|
-
Jan 6th, 2004, 05:14 AM
#1
Thread Starter
Hyperactive Member
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
-
Jan 6th, 2004, 07:42 AM
#2
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:
Dim f1 As String = ""
Dim f2 As String = ""
MsgBox(f2.GetType.ToString)
This world is not my home. I'm just passing through.
-
Jan 8th, 2004, 12:28 AM
#3
Thread Starter
Hyperactive Member
ok
thanks...
I will check this, I hope if this work I can solve my problem.
big TX.
PPCC
-
Jan 9th, 2004, 05:08 AM
#4
Thread Starter
Hyperactive Member
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
-
Jan 9th, 2004, 05:11 AM
#5
Thread Starter
Hyperactive Member
tx trisuglow
I got it , u r gr8 trisuglow
PPCC
-
Jan 9th, 2004, 05:29 AM
#6
Sleep mode
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:
Dim i As Integer
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|