|
-
Oct 11th, 2005, 01:33 PM
#1
Thread Starter
Frenzied Member
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?
-
Oct 11th, 2005, 01:35 PM
#2
Re: multi vars?
What are you trying to do?
I'm afraid your example is unclear.
-
Oct 11th, 2005, 01:36 PM
#3
Re: multi vars?
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?
-
Oct 11th, 2005, 02:16 PM
#4
Thread Starter
Frenzied Member
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?
-
Oct 11th, 2005, 02:25 PM
#5
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:
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
Last edited by RhinoBull; Oct 11th, 2005 at 02:30 PM.
-
Oct 11th, 2005, 05:39 PM
#6
Re: multi vars?
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
-
Oct 11th, 2005, 07:12 PM
#7
Fanatic Member
Re: multi vars?
You could use this :
VB Code:
Set Me.Controls("hInp" & index) = wb(index).Document.blahblah
Me.Controls("hInp" & index).Click
-
Oct 11th, 2005, 07:22 PM
#8
Re: multi vars?
@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.
-
Oct 11th, 2005, 07:25 PM
#9
Fanatic Member
Re: multi vars?
My example would be working for control on the form... but not for a variable!! I misread the thread!!
-
Oct 11th, 2005, 07:30 PM
#10
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...
-
Oct 12th, 2005, 09:43 AM
#11
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.
-
Oct 12th, 2005, 09:56 AM
#12
Re: multi vars?
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.
-
Oct 12th, 2005, 10:00 AM
#13
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.
-
Oct 12th, 2005, 10:08 AM
#14
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:
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
Instead of that nonsense run this sample:
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
BTW, you'll need three command buttons: Command1 (control array - at least 2 members) and Command2.
Last edited by RhinoBull; Oct 12th, 2005 at 10:11 AM.
-
Oct 12th, 2005, 10:16 AM
#15
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:
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
-
Oct 12th, 2005, 11:08 AM
#16
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?
-
Oct 12th, 2005, 11:15 AM
#17
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.
-
Oct 12th, 2005, 11:20 AM
#18
Re: multi vars?
OK, let's stop here because heck knows what you're trying to say. Sorry for being lost in your words.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|