|
-
Jun 15th, 2001, 07:56 AM
#1
Thread Starter
Hyperactive Member
Object/TypeName/TypeOf weirdness! (bug?)
Hi!
ok, i have a situation where, in my immediate window i can go:
?typename(fred)
and i get
"TextBox".
I go:
If TypeOf fred is TextBox then ?"textbox" else ? "not textbox"
and i get
"not textbox".
I`ve tried different types for fred. Ideally it would be object, as i want to iterate through each of the controls on a form, so i`d get errors/have to write error handling code if i used type `textbox`.
Any ideas whats going on? Bug in VB (6, no service pack)? Misunderstanding of TypeOf/TypeName?
This code is in a DLL, if thats relevant.
-
Jun 15th, 2001, 08:29 AM
#2
Registered User
The typeof is statement only works if the object library is currently selected in the references dialog box.
On the other hand typename doesn't require the object class to be present in the current application or in the references dialog box. So use typename() not typeof().
-
Jun 15th, 2001, 08:33 AM
#3
Fanatic Member
could you use something like this?
Code:
Private Sub Command1_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
MsgBox ctrl.Name
End If
Next ctrl
End Sub
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Jun 15th, 2001, 09:25 AM
#4
Thread Starter
Hyperactive Member
The called dll does this:
if typeof fred is textbox then
ok,do more processing on textbox
else
not a textbox, so fail
endif
My code passes it a textbox, and it fails.
Its as if the `typeof` command takes the two objects (fred, and a textbox), and checks them, but not using their name (which presumably is `textbox` somewhere inside the object) but checks some other property (like an internal version number or something).
Bizarre.
-
Jun 15th, 2001, 09:28 AM
#5
Registered User
Doesn't typename work either?
It is documented that typeof is, will not work in as many circumstances as typename.
-
Jun 15th, 2001, 12:03 PM
#6
Thread Starter
Hyperactive Member
"Doesn't typename work either?
It is documented that typeof is, will not work in as many circumstances as typename."
well, typename returns `textbox`, which is fine.
and yes, typeof only works as part of an if..else statement.
The prob is that i dont have the sourcecode to the part of the code which uses typeof.
I have an earlier version of the DLL`s sourcecode, for documentation purposes, but i cant change the corresponding code in the current version of the DLL, as i dont have the current version (and won`t ever have).
If that makes sense!
so i can see why its failing, i was just interested to know why!
(The dll provides some support for keyboard input into a textbox and displaying the output (formatted). seeing as i cant convince it that my textbox is actually a textbox, i`ll have to do the handling myself. Tedious.)
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
|