Results 1 to 6 of 6

Thread: get the type of variable

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Question get the type of variable

    Hello All
    Happy New year 2004


    I want to know the type of the variable for that I am writing following code

    Dim fld1, fld2 as string
    msgbox (fld1.GetType())

    but it is giveng me the error.Any body knows how to find out the type of variable
    help appreciated please.

    PPCC

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    I can't give you the in-depth reasons off-hand, but it's something to do with the variables not being instantiated - they exist but do not point to any objects. Strings are a bit of a special case. Remember that there is a big difference between Nothing and an empty string.

    Try this code:

    VB Code:
    1. Dim f1 As String = ""
    2.         Dim f2 As String = ""
    3.  
    4.         MsgBox(f2.GetType.ToString)
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    ok

    thanks...
    I will check this, I hope if this work I can solve my problem.

    big TX.


    PPCC

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    NOt working

    hi trisuglow

    I have tried the code u suggested but the error is same as previous i.e

    An unhandled exception of type 'System.NullReferenceException' occurred in temp.exe

    Additional information: Object reference not set to an instance of an object.

    I have to get the type of variable which i have declared regardless of null or empty.

    Please guide me if u have ant different solution


    Thanks & regards



    PPCC

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    tx trisuglow

    I got it , u r gr8 trisuglow


    PPCC

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Just to comment something about string . String objects are reference type and should be initialized (at least in C#) . This example will work even if the variable isn't initialized because it's value type and its value set to 0 at creation time .

    VB Code:
    1. Dim i As Integer
    2. MsgBox(i.GetType.ToString)

    Reference types are assigned null values after instantiation (spell?? ) .

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