Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have tried to ask this before -but it was late an I really didn't do a good job in setting the question...
Let's try this again
Here is my Question:
Is there a way to determin the type of a variable held in a structure before a value has been assigned ?
- I know that once a value has been assigned to it I can use [TypeName] to get the type of the variable.
- I also knwo that if I would declare the variable in the structure as shared I could assigne a value to it during declaration ( This is what I might end up doing)
- If there is nothing assigned to the variable yet (see example below)
[Typename] will just return "nothing"

Is ther afunction that will actually tell me what type the variable was declared with (String , boolean , Integer .. )


Public Test As Test_T        
Public Structure test
        Public S_String as string
End Structure

MsgBox(TypeName(Test.S_String)) = will return "Nothing" at that point 

Test.S_string = "Help"
MsgBox(TypeName(Test.S_String)) = will now return "String"
Posted

1 solution

No. There is no way, because until you assign a value there is no type to detect.

When you declare a variable, it's value is null (C#) or nothing (VB) - that does not have a type, it is a value which specifically indicates there is no content. Technically, it could contain a string, or any type derived from string, so there is no "type" which can be specifically identified as being "the type" it will be holding.

Think about it: if you make a box, and put no item in it, can you say "this is a box of cheese", or "this is a box of IPad2's"? No. It is an empty box.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900