Results 1 to 8 of 8

Thread: [RESOLVED] How do I get VB to read the...

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    Resolved [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:
    1. Dim strString as String
    2.  
    3. strString = "SubName"
    4.  
    5. Call strString 'so you see I want VB to call SubName instead of strString
    VB6 all the way!

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: How do I get VB to read the...

    Have two command buttons....

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Subname As String
    3.  
    4. Subname = "SubA"
    5.  
    6. CallSubroutine Subname
    7. End Sub
    8.  
    9. Private Sub Command2_Click()
    10. Dim Subname As String
    11.  
    12. Subname = "SubB"
    13.  
    14. CallSubroutine Subname
    15.  
    16. End Sub
    17.  
    18. Private Sub CallSubroutine(ByVal sub_name As String)
    19.     CallByName Me, sub_name, VbMethod
    20. End Sub
    21.  
    22. Public Sub SubA()
    23.     MsgBox "This is SubA"
    24. End Sub
    25.  
    26. Public Sub SubB()
    27.     MsgBox "This is SubB"
    28. End Sub
    Chris

  3. #3
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    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
    VB Code:
    1. Call SubName

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    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?
    VB6 all the way!

  5. #5
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: How do I get VB to read the...

    Can you explain further what you want to do with 'images'
    Chris

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    10

    Re: How do I get VB to read the...

    i mean
    dim strName as string

    strName = "Car"

    imgImage = strName
    VB6 all the way!

  7. #7
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    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
    Chris

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How do I get VB to read the...

    I think this should work, though I did not test it:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Pictures As New Collection
    4.  
    5. Private Sub Form_Load()
    6.     Dim strName As String
    7.    
    8.     Pictures.Add LoadPicture("C:\Car.jpg"), "Car"
    9.     Pictures.Add LoadPicture("C:\House.jpg"), "House"
    10.     Pictures.Add LoadPicture("C:\Toy.jpg"), "Toy"
    11.     Pictures.Add LoadPicture("C:\UFO.jpg"), "UFO"
    12.     ' ..... etc...    
    13.  
    14.     strName = "UFO"
    15.     imgImage.Picture = Pictures(strName)
    16. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width