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?
Printable View
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?
What are you trying to do?
I'm afraid your example is unclear.
You can use arrays, however I am a bit confused with this line:
hInp & index.Click
What do you have in mind? Creating buttons (or something) or variables as your thread subject suggests?
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?
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:
Private Sub Command1_Click() WebBrowser1_DownloadBegin 0 End Sub Private Sub WebBrowser1_DownloadBegin(Index As Integer) Select Case Index Case 0, 1 MsgBox "Start downloading... Please wait." End Select End Sub
You could use a For loop to loop thru each control, eg:
VB Code:
Dim iCount as Integer Dim hInp as ??? For iCount = 1 To (wb.Count - 1) Set hInp = wb(1).Document.blahblah hInp.Click Next iCount Set hInp= Nothing
You could use this :
VB Code:
Set Me.Controls("hInp" & index) = wb(index).Document.blahblah Me.Controls("hInp" & index).Click
@si_the_geek and Gensor:
sorry guys but your samples don't make much sense (to me at least) unless you explain what you had in mind. :wave:
My example would be working for control on the form... but not for a variable!! I misread the thread!! :p
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...
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. :)
Yea, I saw that, but hypothetically if the following line is OK
Set hInp1 = wb(1).Document.blahblah
then this will fail anyway
hInp1.Click
because for control array index is expected as an argument in every event handler.
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.
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"
Instead of that nonsense run this sample:VB Code:
Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 MsgBox "Button 0 was clicked." End Select End Sub Private Sub Command2_Click() Dim ctl As Control Set ctl = Command1(0) MsgBox ctl.Caption 'this is still fine ctl.Click 'ERROR WILL OCCUR HERE End Sub
BTW, you'll need three command buttons: Command1 (control array - at least 2 members) and Command2.VB Code:
Option Explicit Private Sub Command1_Click(Index As Integer) Select Case Index Case 0 MsgBox "Button 0 was clicked." End Select End Sub Private Sub Command2_Click() Command1_Click 0 End Sub
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:
Dim iCount as Integer For iCount = 1 To (wb.Count - 1) wb(1).Click Next iCount
Of course we can't tell until Pouncer comments ;)
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?
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.
OK, let's stop here because heck knows what you're trying to say. Sorry for being lost in your words. :wave: