Ask Your Question

Variable name Vs Value variable

asked 2018-07-11 17:50:52 +0200

Fede gravatar image

updated 2018-07-12 14:48:07 +0200

Jim K gravatar image

Hello, I have 3 variables: var1 = 10; var2 = 20; var3 = 30

I would like to print on screen the variable with for cycle

sub prova
dim var1#
dim var2#
dim var3#

var1 = 10
var2 = 20
var3 = 30   
for i = 1 to 3
    print "var" & i
end sub

But in this way obtain the of variable, not the value

Can you help me?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-07-11 19:15:19 +0200

Lupp gravatar image

updated 2018-07-11 19:19:06 +0200

You explicitly order to output a string constant with the string value var every time. The current value of i is then automatically also converted to string and appended.

You cannot access the value of a variable by a string in place of the variable itself.

To achieve what you wanted you need to make the three values accessible by index. One way to do so would be:

Sub someOutput()
Dim myArray
myArray = Array(10, 20, 30)
For i = 0 to 2     'Arrays created by the standard function Array() start with index 0.
    Print myArray(i)
Next i
End Sub

To make values accessible via string values used as names you need to create a structured variable of a different type. The names then are still strings viewed from Basic, not variables.

Pöease don't miss to add the tag "basic" to your question. Even better you replace "calc" with "basic" because the question isn't related to Calc.

edit flag offensive delete link more


Thank you Lupp, P.S. After clicking "Retag" and modifing it, how to conferm?

Fede gravatar imageFede ( 2018-07-12 09:15:59 +0200 )edit

Sorry. Retagging doesn't seem to work. I also tried some ways but failed.
I found the respective question here but no answer.

Lupp gravatar imageLupp ( 2018-07-12 09:52:43 +0200 )edit

I retagged it by clicking retag, entering common basic variable name and then clicking outside the entry box. @Lupp, perhaps you tried to enter basic variable name, but this will not be accepted because either calc or commonis required, as explained at

Jim K gravatar imageJim K ( 2018-07-12 14:49:47 +0200 )edit

Thanks @Jim K .
I also had added common. I obviously missed the expcted sequel.
And: I missed to hint @Fede to the fact that there are a few predefined tags one of which to use is mandatory.

Lupp gravatar imageLupp ( 2018-07-12 15:10:22 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-07-11 17:50:52 +0200

Seen: 41 times

Last updated: Jul 12