Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch -case

Hello,
How can i make this shorter?
 
 
int address ;
 
switch (address)
{
case 0:
       RunIOTask ("0:0") ;
break;
case 1:
       RunIOTask ("0:1") ;
break;
case 2:
       RunIOTask ("0:2") ;
break;
case 3:
       RunIOTask ("0:3") ;
break;
case 4:
       RunIOTask ("0:4") ;
break;
.
.
case 30:
       RunIOTask("0:30) ;
break;
}
 
0 Kudos
Message 1 of 4
(3,635 Views)

Hello Juha

just for my information, what language are you using?
anyway you can generate the string via table lookup and then call RunIOtask with this string as parameter.
If you want flexibility read the strings/address combinations from file.

greetings from a dry country (almost as hot as Austin today)

greetings from the Netherlands
0 Kudos
Message 2 of 4
(3,623 Views)


@-Juha- wrote:
Hello,
How can i make this shorter?
 
 
int address ;
 
switch (address)
{
case 0:
       RunIOTask ("0:0") ;
break;
case 1:
       RunIOTask ("0:1") ;
break;
case 2:
       RunIOTask ("0:2") ;
break;
case 3:
       RunIOTask ("0:3") ;
break;
case 4:
       RunIOTask ("0:4") ;
break;
.
.
case 30:
       RunIOTask("0:30) ;
break;
}
 


Try something like

int address ;

char addr[5];

if ( address >= 0 && address <= 30) {

Fmt (addr,"%s<0:%i",address);

RunIOTask(addr);

}


 

Message 3 of 4
(3,622 Views)
Thanks, it works
0 Kudos
Message 4 of 4
(3,615 Views)