Convert text to variable

Convert text to variable

Anonymous
Not applicable
1,287 Views
3 Replies
Message 1 of 4

Convert text to variable

Anonymous
Not applicable

Hi All,

 

This week i've been exploring the possibilities of ilogic this week and now i'm stuck.

I think I would like to convert a text string into a variable; so in my example below I get variable 1 to 3 returned and not x to 3 (in the debugview program).

 

(actually i'm working on a routine to make the scale from multiple views automatic (and selected from common list of options from excel ). so each view is dependent on a variable in a part and automatically scaled)

 

x1 = variable1
x2 = variable2
x3 = variable3

i = 3

For i = 1 To i

z = xi         'doesn't work
z = x & i      'doesn't work
z = ????? Trace.Writeline("ilogic = " & z) Next i

 

Best regards,

Igor

0 Likes
Accepted solutions (1)
1,288 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

If you want to iterate over a set of variables you want to use an array.  Visual Basic is a bit strange in how you declare an array.  The number 2 indicates the upper index of the array and since the low index is always zero the entire size of the array in this case is 3.

 

Dim x(2) As Double
x(0) = variable1
x(1) = variable2
x(2) = variable3

i = 3

For i = 0 To i-1
    z = x(i)

    Trace.Writeline("ilogic = " & z)
Next i

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks! this is a good workaround.

I assume creating a varable name from (multiple) text strings isn't possible then?

 

Best regards,

Igor

0 Likes
Message 4 of 4

Anonymous
Not applicable

This is what I made with it, in below example the diffrent views are still depending of the same parameter but you get the picture.

 

GoExcel.DisplayAlerts = False
Dim excel as String = "D055547.xlsx" 'model should be in the same folder as excel file

'the result of the variables below should be the desired scale
model1 = (1/Parameter("Part1.ipt.BOX"))*50
model2 = (1/Parameter("Part1.ipt.BOX"))*25
model3 = (1/Parameter("Part1.ipt.BOX"))*30

Trace.Writeline("ilogic A= " & model1) 'use the program called DebugView to see the variable model1
Trace.Writeline("ilogic B= " & model2)
Trace.Writeline("ilogic C= " & model3)

Dim x(2) As Double
x(0) = model1
x(1) = model2
x(2) = model3

j = 3 'amount of views to be adjusted automatically (the views have to be named VIEW and starting at 1)

For i = 0 To j-1

      z = x(i)
    Trace.Writeline("ilogic Dx = "& z)

    'find the rownumber under verhouding of commonly used scales corresponding to the found proportion, in the sheet Tables
    scale_row = GoExcel.FindRow(excel, "Tables", "verhouding", ">=", z) 
    Trace.Writeline("ilogic Ex = " & scale_row)

    'store the scale in the right format to variable scale
    Dim scale As String = GoExcel.CellValue(excel, "Tables","V"&scale_row) 'after the last comma the column is specified
    Trace.Writeline("ilogic Fx "& scale)
    
    Dim vw As String = "VIEW"&I+1
    Trace.Writeline("ilogic Gx "& vw)
    ActiveSheet.View(vw).ScaleString = scale

Next i , i

 

0 Likes