Results 1 to 6 of 6

Thread: Object/TypeName/TypeOf weirdness! (bug?)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    London
    Posts
    290

    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.

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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().

  3. #3
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    London
    Posts
    290
    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.

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Doesn't typename work either?

    It is documented that typeof is, will not work in as many circumstances as typename.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    London
    Posts
    290
    "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
  •  



Click Here to Expand Forum to Full Width