[RESOLVED] How do I get VB to read the...
What I'm trying to do is to get VB to read the actual value stored inside the variable instead of just reading its', name here's what I mean.
VB Code:
Dim strString as String
strString = "SubName"
Call strString 'so you see I want VB to call SubName instead of strString
Re: How do I get VB to read the...
Have two command buttons....
VB Code:
Private Sub Command1_Click()
Dim Subname As String
Subname = "SubA"
CallSubroutine Subname
End Sub
Private Sub Command2_Click()
Dim Subname As String
Subname = "SubB"
CallSubroutine Subname
End Sub
Private Sub CallSubroutine(ByVal sub_name As String)
CallByName Me, sub_name, VbMethod
End Sub
Public Sub SubA()
MsgBox "This is SubA"
End Sub
Public Sub SubB()
MsgBox "This is SubB"
End Sub
Re: How do I get VB to read the...
The value stored in strString is "SubName" as you set it...
If you want to execute a function then just do
Re: How do I get VB to read the...
oh thanks a lot that help so much but how would I do the same thing with images?
Re: How do I get VB to read the...
Can you explain further what you want to do with 'images'
Re: How do I get VB to read the...
i mean
dim strName as string
strName = "Car"
imgImage = strName
Re: How do I get VB to read the...
No I don't think thats possible, unless you insert thousands of images into your project and give each a reference name
Re: How do I get VB to read the...
I think this should work, though I did not test it:
VB Code:
Option Explicit
Private Pictures As New Collection
Private Sub Form_Load()
Dim strName As String
Pictures.Add LoadPicture("C:\Car.jpg"), "Car"
Pictures.Add LoadPicture("C:\House.jpg"), "House"
Pictures.Add LoadPicture("C:\Toy.jpg"), "Toy"
Pictures.Add LoadPicture("C:\UFO.jpg"), "UFO"
' ..... etc...
strName = "UFO"
imgImage.Picture = Pictures(strName)
End Sub