Results 1 to 18 of 18

Thread: multi vars?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    multi vars?

    Set hInp & index = 'whatever'
    hInp & index.Click
    is that possible so whatever the index is it wil creeate multi ones like

    hInp1
    hInp2
    hInp3

    this is what i need etc, any suggesstions?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: multi vars?

    What are you trying to do?

    I'm afraid your example is unclear.

  3. #3

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: multi vars?

    well im dealing with multiple webbrowsers so for 1 broswer i do something like..

    Set hInp = wb.Document.blahblah
    hInp.Click

    but im dealing with multi webrowsers with indexes e.g. wb(1) wb(2)

    so i need different variable names

    Set hInp1 = wb(1).Document.blahblah
    hInp1.Click

    Set hInp2 = wb(2).Document.blahblah
    hInp2.Click

    thats why i was asking i need something like

    Set hInp & index = wb(index).Document.blahblah
    hInp & index.Click

    any ideas why it wont work?

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: multi vars?

    Why don't you simply call that click event and pass Index (if you do have control array) ?
    Here is a quick sample:
    VB Code:
    1. Private Sub Command1_Click()
    2.     WebBrowser1_DownloadBegin 0
    3. End Sub
    4.  
    5. Private Sub WebBrowser1_DownloadBegin(Index As Integer)
    6.     Select Case Index
    7.         Case 0, 1
    8.             MsgBox "Start downloading... Please wait."
    9.     End Select
    10. End Sub

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: multi vars?

    You could use a For loop to loop thru each control, eg:
    VB Code:
    1. Dim iCount as Integer
    2. Dim hInp as ???
    3.  
    4. For iCount = 1 To (wb.Count - 1)
    5.   Set hInp = wb(1).Document.blahblah
    6.   hInp.Click
    7. Next iCount
    8. Set hInp= Nothing

  7. #7
    Fanatic Member
    Join Date
    May 2004
    Location
    Granby, Qc, Canada
    Posts
    602

    Re: multi vars?

    You could use this :

    VB Code:
    1. Set Me.Controls("hInp" & index) = wb(index).Document.blahblah
    2. Me.Controls("hInp" & index).Click

  8. #8

  9. #9
    Fanatic Member
    Join Date
    May 2004
    Location
    Granby, Qc, Canada
    Posts
    602

    Re: multi vars?

    My example would be working for control on the form... but not for a variable!! I misread the thread!!

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: multi vars?

    No, your sample will fail in the following line:

    Set Me.Controls("hInp" & index) ...

    for two reasons:

    1. "hInp" & index must represent control's name but since it doesn't exist it cannot be found in the controls collection.
    2. presuming that it does exist - you cannot set existing control to be another control...

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: multi vars?

    Well RhinoBull, in post 4 Pouncer said that he wants to repeat this code for each webbrowser control:

    Set hInp1 = wb(1).Document.blahblah
    hInp1.Click

    ..so I just put it into a loop for the control array wb.

  12. #12

  13. #13
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: multi vars?

    I see your point but disagree, as the index refers to the parent object (wb) rather than the sub-object (blahblah) that hInp1 is set to.

  14. #14
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: multi vars?

    I'm afraid you're missing one important point, SI - you cannot do that.
    If you run this sample you will get error: "Object doesn't support this property or method"
    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2.     Select Case Index
    3.         Case 0
    4.             MsgBox "Button 0 was clicked."
    5.     End Select
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9. Dim ctl As Control
    10.  
    11.     Set ctl = Command1(0)
    12.     MsgBox ctl.Caption 'this is still fine
    13.     ctl.Click 'ERROR WILL OCCUR HERE
    14.  
    15. End Sub
    Instead of that nonsense run this sample:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click(Index As Integer)
    4.     Select Case Index
    5.         Case 0
    6.             MsgBox "Button 0 was clicked."
    7.     End Select
    8. End Sub
    9.  
    10. Private Sub Command2_Click()
    11.     Command1_Click 0
    12. End Sub
    BTW, you'll need three command buttons: Command1 (control array - at least 2 members) and Command2.

  15. #15
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: multi vars?

    Yes, your example code fails. However, I consider it to be irrelevant to the issue - as Pouncer is assigning a child object to the variable, rather than the parent object. Using a child object from a control array in this way is valid.

    Of course I could be wrong about the requirements (I am basing my opinion on post 4), if Pouncer is actually trying to do this for each wb:
    Set hInp = wb(1)
    hInp.Click

    ..then the code should be like this:
    VB Code:
    1. Dim iCount as Integer
    2.  
    3. For iCount = 1 To (wb.Count - 1)
    4.   wb(1).Click
    5. Next iCount

    Of course we can't tell until Pouncer comments

  16. #16
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: multi vars?

    How is it irrelevant if the following syntax

    wb(1).Click

    is not valid ???

    Can you explain that to me? I don't get it?
    If you try to execute that line of your - you will get error "Method or data member not found" because of the syntax problem. Correct syntax is as follows:

    Command1_Click 0 'Index As Integer is a mandatory argument

    How can you NOT get that error or did you run it at all?

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: multi vars?

    Can you please read my post again, a bit more carefully

    As I said I did get the error, and I also said that assigning wb(1) to a variable was incorrect.

    However the code as posted by Pouncer is not of the style "wb(1).Click", it is "wb(1).childobject.Click". You can assign wb(1).childobject to a variable and use "variable.click".


    We can't tell exatcly what Pouncer was trying to achieve without more details, but whatever it is, there is enough information here now so that he can find an appropriate answer.

  18. #18

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