leeder
asked on
Indirect Addressing
Visual Basic 3.0
When the following program is run...
A=1234
B$="A"
C=UnknownFunction(B$)
...what is the "UnknownFunction" that assigns the value of variable A (1234) to variable C by referencing variable B$ ?
When the following program is run...
A=1234
B$="A"
C=UnknownFunction(B$)
...what is the "UnknownFunction" that assigns the value of variable A (1234) to variable C by referencing variable B$ ?
Dim A As Long
Private Sub Form_Load()
Dim B As String
Dim C As Long
A = 1234
B = "A"
C = UnknownFunction(B)
Debug.Print C
End Sub
Private Function UnknownFunction(sVar As String) As Long
Select Case sVar
Case "A"
UnknownFunction = A
'... more cases
Case Else
UnknownFunction = 0
End Select
End Function
Private Sub Form_Load()
Dim B As String
Dim C As Long
A = 1234
B = "A"
C = UnknownFunction(B)
Debug.Print C
End Sub
Private Function UnknownFunction(sVar As String) As Long
Select Case sVar
Case "A"
UnknownFunction = A
'... more cases
Case Else
UnknownFunction = 0
End Select
End Function
ASKER
Thanks for your rapid response. However, you must realize that it is too early for me to accept such an answer. The old old dBase II programming language had such a function and I still have hopes of a solution. I must wait for other responses although you may be absolutely correct.
Erick37's comment shows a way for you to "do-it-yourself".
In his example, you would have to program a case statement for each indirect reference.
Cheers!
In his example, you would have to program a case statement for each indirect reference.
Cheers!
This functionality seems to be common in XBase languages, such as FoxPro and dBase, but you will not find a single internal VB3 function that will solve your problem. You would have to write a function, like Erick37 suggested that simulates this.
VB6 Professional/Enterprise has a Micro$oft Script Control that does expression evaluation that would do the trick, but this doesn't help with VB3.
VB6 Professional/Enterprise has a Micro$oft Script Control that does expression evaluation that would do the trick, but this doesn't help with VB3.
ASKER
To Erick37 (and mcrider)
Your response certainly works for fixed known variables (it is how I currently am doing it) however, it requires a programming modification every time a different variable is used.
Although my example may be simplistic, I need something that will encompass any variable name.
Your response certainly works for fixed known variables (it is how I currently am doing it) however, it requires a programming modification every time a different variable is used.
Although my example may be simplistic, I need something that will encompass any variable name.
If VB3 has SaveSetting and GetSetting:
Dim A, C As Long
Dim B As String
A = 1234
SaveSetting "AppName", "Indirect", "A", A
B = "A"
C = GetSetting("AppName", "Indirect", B, 0)
Debug.Print C
Dim A, C As Long
Dim B As String
A = 1234
SaveSetting "AppName", "Indirect", "A", A
B = "A"
C = GetSetting("AppName", "Indirect", B, 0)
Debug.Print C
I stand by my original answer (as confirmed by TheLearnedOne) VB3 does not contain any NATIVE way of performing this function.
Cheers!
Cheers!
TheLearnedOne... By the way, the microsoft Script control MSSCRIPT.OCX is available for VB4-32-bit and VB5 from a microsoft download page, and is shipped with VB6...
Cheers!
Cheers!
Erick37, Using the Registry like this will DEFINATELY increase the size of the registry (and boot time?)...
Cheers!
Cheers!
Yes, Mcrider, I would not use this approach for many operations. But if I HAD to do it for a couple of variables on occation, it would work. Just a comment.
ASKER
mcrider--I am still not quite convinced. Also, I don't have to have a "Native" solution - 3rd party would be fine.
Erick37--VB3 doesn't seem to have "SaveSetting" or "GetSetting"
Erick37--VB3 doesn't seem to have "SaveSetting" or "GetSetting"
You are definitely stretching the rubberband pretty thin. I haven't thought about VB3 for about 4 or 5 years, and I hope that you find an answer to your question that you are going to accept.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mcrider--you win--cheers
;-)
Gimme those points mcrider! :-/
sorry... )
Cheers!