|
-
Oct 27th, 2000, 11:44 AM
#1
Thread Starter
Frenzied Member
Hi,
I'm not sure how to do this but here's what I'm trying to accomplish..
In a module, I need to reference a control on a form many times. Rather than keep typing Form1.Control.Whatever, I would like to create a name such as Control1 so that in my module, I can write:
With Control1
.Whatever
.Whatever1
End With
Any help on how to do this would be appreciated.
Dan
-
Oct 27th, 2000, 11:57 AM
#2
Fanatic Member
You can use a shortcut very close to what you have already said. Just dim a variable of type Object somewhere, and then set it to the control you want to keep referencing.
Say you had a particular textbox from somewhere you wanted to keep using:
Code:
Dim X As Object
'in the main loading form
Private Sub Form_Load()
Set X = Form1.Text1
End Sub
Then you can just use X like it was a real textbox.
Code:
X.Text = "some text"
Or if you had a lot of things:
Code:
With X
.Left = 0
.Top = 0
'etc
End With
When you're done using the variable:
[Edited by Kaverin on 10-27-2000 at 01:02 PM]
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Oct 27th, 2000, 12:43 PM
#3
Thread Starter
Frenzied Member
Thanks! I think that's what I was looking for but there is a small problem using that method..
None of the events, methods or properties are available for me to see when using the object.
For example, when I type:
frmMain.Winsock1.
the events, methods and properties of the Winsock control automatically pop up after the last "."
But, when doing the following:
Dim x as Object
Set x = frmMain.Winsock
x.
nothing pops up after the "."
Any idea on how to accomplish this? It's hard to remember all the methods, events and properties for each object..
Thanks,
Dan
-
Oct 27th, 2000, 03:20 PM
#4
Fanatic Member
I would assume that's because in the manner I described, X isn't anything yet (because it isn't valid until the program runs). You'll just have to learn all the things, or if you know what X is supposed to be (meaning at design time), just type out the class itself, and it should pop up. Something like Form. I can't check on this, so I could be going far off in left field This comp I'm on at the moment has no VB at all.
Just so you know, I think using a variable in this manner is called "late binding of an object". I'm sure someone will correct me if I'm wrong heh heh.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Oct 27th, 2000, 03:30 PM
#5
No, it's because you used late binding.
Instead of dimensioning the object variable as object, dimension it as textbox and the intellisense feature is back again.
So not:
Dim x as Object
but:
Dim x As TextBox
-
Oct 30th, 2000, 01:42 PM
#6
Fanatic Member
Been away studying for some exams... but anyway, I wanted to say something else. By all means, I think it would be better to actually dim the variable as the type it will reference in the future. Using plain old object is just a general way in the event you 1) don't know what it might be referencing 2) it will reference several different objects (at different times of course).
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
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
|