|
-
Aug 17th, 2000, 05:30 PM
#1
Thread Starter
Registered User
Hello!
I just gota question about declaring a Variable as an object
like for instance....
[code/]
Dim txtTextBox as textbox
[code]
now does that just make txtTextBox a textbox object?
so i could write a statment like this.....
txtTextBox.text = "hello"
But if thats true, whats the point? can someone give me an example of why i would do that?
Because i mean thats just like changing the name property of it...and just rename the textbox "txtTextBox"
i just don't understand why you would do that(if u know why, please post an example that is useful)...THanks for listening!
-
Aug 17th, 2000, 06:00 PM
#2
Frenzied Member
Not a particularly good example but one that works. Suppose you code in a non-English language and you want to localize the names of objects to your language...
[Edited by JHausmann on 08-17-2000 at 07:11 PM]
-
Aug 18th, 2000, 01:30 AM
#3
Addicted Member
I use it for when I am writing a function or a sub in a module, and that function or sub needs a textbox to be executed correctly example:
Code:
Public Function DoStuff(TxtBox as TextBox)
'Do Stuff Here
End Function
'and then in a command button you migh have
Call DoStuff(Text1)
I haven't really used it for a textbox, as you can just use a string, and dump the contents of a textbox into that string, but I have used it for a listbox and numerous other objects, the reason for this is I find it easier to type:
TxtBox.text = "Stuff"
than:
Form1.Text1.Text = "Stuff"
and also because you can use that sub or function again, and again with all different textboxes or whatever the object is, I find it quite handy.
[Edited by Crypt on 08-18-2000 at 03:49 AM]
-
Aug 18th, 2000, 01:40 AM
#4
I also use it A Lot in subs that are in modules.
I use TreeViews, TextBoxes, ListBoxes, etc. but I dont usually do this
Code:
Private Sub Command1_Click()
Dim TheTextBox As TextBox
'etc
'etc
End Sub
I just never found the need to do that.
and the title of this thread brings up another question, lets say I have a class module that is name "clsThing"
how would I call it?
Code:
Dim Thing As New clsThing
'or
Dim Thing As clsThing
Set Thing = New clsThing
???
-
Aug 18th, 2000, 01:53 AM
#5
Guru
Both are correct; however, the second method (first Dim then Set as New) is more efficient.
Remember to stick the Dim in your General Declarations area, and the Set in the Form_Load area.
Also you should do this:
Code:
Private Sub Form_Unload(Cancel As Integer)
Set Thing = Nothing
End Sub
(Thing = Nothing, that didn't sound TOO weird, did it?)
Everything I said here was for efficiency only. Use it so your program will take a lot of RAM (Instead of a WHOLE lot).
-
Aug 18th, 2000, 01:55 AM
#6
why would it take a whole lot/ a lot?
do class modules take logs of memory or something?
or are you just saying for for vb programs in general ?
-
Aug 18th, 2000, 02:07 AM
#7
-
Aug 18th, 2000, 02:15 AM
#8
, I didn't design the Windows memory handling routines (and I'm glad I didn't),
perhaps it would have been better if you had!
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
|