# Creating a variable

I would like to create a variable and name it after the contents of MEM2.

Lets say MEM2 has the string 506,1EA,UNY,UNW,009,656,UNV

Then I extract each option using

@Option = FLD(MEM2, 1, ",")

After this I want to create a global variable named with the contents of @Option.

I want to do this until I reach the end of MEM2.

Can this be done?

Date Kevin Griffis

Is the value of MEM2 always going to have the same number of elements? Justin Barrett

So if @Option = "506,1EA,UNY,UNW,009,656,UNV" you want to create new global named variables with the names @506, @1EA and so on using the @Option string automatically?

Short answer is no you cant.

Long answer is yes but it would be too much code and not really worth it. Easier to store the options in the string, then check to see if that option exists when needed. ie.

IF (FINDI(@Option,"506",1)) > 0

'enter code related to that option'

ENDIF

IF (FINDI(@Option,"1EA",1)) > 0

'enter code related to that option'

ENDIF

and so on... You can try this code, S is your actual option for each iteration of the loop:

1.002  IEEE         *IDN?[I\$]
1.003  RSLT         =
1.004  RSLT         = [MEM2]
1.005  MATH         @IDN = MEM2
1.006  IEEE         *OPT?[I\$]
1.007  RSLT         = [MEM2]
1.008  MATH         @Option = MEM2

1.009  MATH         M=1

1.010  DO
1.011  DISP         @Option_[M1]
1.012  MATH         S = FMT(M, "%.0f")
1.013  MATH         S = "Option_"
1.014  MATH         S = S & S
1.015  MATH         S = FLD(@Option, M, ",")
1.016  IF           NULL(S)
1.017  JMPL         End_Option
1.018  ELSE
1.020  DISP         [S4]
1.019  RSLT         =         [S3] = [S4]
1.021  ENDIF
1.022  MATH         M = M+1
1.023  LABEL        End_Option
1.024  UNTIL        NULL(S)
1.025  MATH         M = M-1
1.026  DISP         There are "[M1]" options in this UUT James Smith

From what I am reading, I am gathering you are trying to create a varable name after the contents of MEM2. I have not found a way to actually do that yet. Your options from what I know are either hard code the variable by typing it out yourself or utilize the Sreg with SSET. Hope this could be of some use.

You can copy and paste this in editor. There are two sections here. The first being what you asked for except using Sreg over variables, the second being what I believe you may be going towards. It is a clip that will cover instruments with a wide range of options installed and may require some tests and not some tests. The second section comes into play later on with the named variables. It all depends on your application and how much code you want to put in.

# here is an example of what I think you are asking for
1.001  VISA         *OPT?[I\$]
# example return 506,1EA,UNY,UNW,009,656,UNV

# make Variable = return
# Not sure why you need it, but it is here if you do
1.002  MATH         @Option = MEM2

1.003  MATH         CTR = 0
# coutner for do - unitl
1.004  MATH         OPT = findi(MEM2,",",0)+1
# coutner for # of options installed
1.005  DO
1.006  MATH         CTR = CTR + 1
# tick counter per cycle
1.007  MATH         SSET(CTR,(FLD(MEM2,CTR,",")))
# set S[x] to the field extracted from opt string
1.008  UNTIL        CTR == OPT
# this bit will set your Sregisters to the options installed and stop
# when it reaches the end of the opt return string.

# I think this may be what your going towards

1.026  LABEL        Options
1.027  VISA         *OPT?[I\$]
1.028  MATH         S = MEM2
1.029  MATH         L = FINDI(MEM2,",",0)+1
1.030  MATH         CTR = 0
1.031  DO
1.032  MATH         CTR = CTR + 1
1.033  MATH         S = FLD(MEM2,CTR,",")
1.034  MATH         @506 = ZCMPI(S, "506")
1.035  MATH         @1EA = ZCMPI(S, "1EA")
1.036  MATH         @UNY = ZCMPI(S, "UNY")
1.037  MATH         @UNW = ZCMPI(S, "UNW")
1.038  MATH         @009 = ZCMPI(S, "009")
1.039  MATH         @656 = ZCMPI(S, "656")
1.040  MATH         @UNV = ZCMPI(S, "UNV")
1.053  UNTIL        CTR == L

1.061  RSLT         =

1.062  IF           @506 >0
1.063  RSLT         =Option 506: Option desciption
1.064  ENDIF
1.065  IF           @1EA >0
1.066  RSLT         =Option 1EA: Option desciption
1.067  ENDIF
1.068  IF           @UNY >0
1.069  RSLT         =Option UNY: Option desciption
1.070  ENDIF
1.071  IF           @UNW >0
1.072  RSLT         =Option UNW: Option desciption
1.073  ENDIF
1.074  IF           @009>0
1.075  RSLT         =Option 009: Option desciption
1.076  ENDIF
1.077  IF           @656 >0
1.078  RSLT         =Option 656: Option desciption
1.079  ENDIF
1.080  IF           @UNV >0
1.081  RSLT         =Option UNV: Option descrption
1.082  ENDIF