Assigning a variable value to a variable name?

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Passerby
Assigning a variable value to a variable name?

Post by Passerby » Mon Jul 31, 2006 9:29 am

Is is possible to assign the value of a variable, say Var1=1 in the middle of a name of another variable, which could be Var(Var1's value here)2?

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

What?

Post by Valerie » Sat Aug 05, 2006 11:38 am

I don't quite understand what you are asking. Please re-phrase your query and explain the purpose.

Thanks...

Guest

Post by Guest » Sun Aug 06, 2006 4:20 am

Sure, if the second variable is in the form of an array. for instance, you , ould have a variable, V(V1), where, if V1 = 1, is the variable V(1), and, if V1=10, then the other variable is V(10), and so on.

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Sorry - I'm still a bit confused...

Post by Valerie » Sun Aug 06, 2006 6:17 am

Do you mean that if the variable V=1 then the array V(1) will be returned or do you want to change the value at V(1) to the value of V:?:

If you want to change the value in an array you must code it. Every time the variable V changes you must code the change to be entered into the array.

Please explain what you are trying to achieve...

Thanks

V...

Bulldog

Post by Bulldog » Thu Aug 10, 2006 8:51 am

You can't rename a varible on the fly if that's what your trying to do.

Jak
Newbie
Posts:2
Joined:Mon Sep 04, 2006 11:35 am

Post by Jak » Mon Sep 04, 2006 11:55 am

If I understand you right, what you're thinking of is a situation like this.


you have a variable Var1

you want to create a new variable and assign a value (let's say 291) to it so that:

If Var1=3
Var31=291

If var1=18
Var181=291

and so on.


Assuming Var1 is numeric, the obvious solution would be to use an array for the second variable and use the value of Var1 as the index.

Eg: Var1=19: Var(Var1)=291

Two problems with this are that your new variable name won't be strictly in the format you were aiming for, so may need slight re-coding elsewhere. Also, if the value of Var1 can vary widely then you may have to define a large array.

Eg: If Var1 can have the values 0, 25 or 3096 you would have to DIM Var(3096). That's kind of wasteful.

There are ways to code round it, but the solutions really depend on your exact requirements. If you haven't solved your problem yet, any chance of posting a few more details, especially permitted values / range of values and types (INT, STRING etc) for your Var1?

Bulldog
Newbie
Posts:4
Joined:Fri Nov 03, 2006 6:34 am

Post by Bulldog » Fri Nov 03, 2006 6:48 am

I think what he want's to do is this

Var1 = 2

then create another varible named Var21 using var1's value as part of the new varible name. I have wanted to do that before also but of course you can't.

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Sun Dec 31, 2006 6:12 pm

Why do you people keep on trying to outguess the OP, when that person has not even shown any interest in your questions or posts?
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Post Reply