0

How can I get an object type in a variable?

For example in VB I can declare this way:

Dim tvNode As TreeNode
tvNode = TreeView1.Nodes(1)
tvNode.Remove()

That way I can access to the functions to that object.

But in VBScript i do this:

Dim tvNode
tvNode = TreeView.Nodes(1)
tvNode.Remove() // Error. Incompatible type - tvNode is type: (name of the node) ???

How can I get a node in a variable in VBScript then?

ProtectedVoid
  • 1,161
  • 3
  • 13
  • 36

2 Answers2

0

Use TypeName to get the string representation of the type. There is also VarType which returns the VT_ENUM value of the variant type.

See also Get the type of a variable in VBScript.

Community
  • 1
  • 1
patthoyts
  • 29,437
  • 2
  • 54
  • 84
  • It returns type `String`. How can I get a TreeView Node type? So I can access to its functions such as remove, add, etc... Thanks. – ProtectedVoid Jul 17 '15 at 10:19
0

The answer was using Set. That way I can assign objects to a variable. If I don't use Set keyword, it just assigns the string value.

ProtectedVoid
  • 1,161
  • 3
  • 13
  • 36
  • You should have clarified that your working example was _VB.NET_. In all other VB languages (VB6, VBA, VBScript) `Set` is always required for object assignment. – Bond Jul 20 '15 at 12:59
  • I used two examples: One in VB.NET which works as I specified "That way I can access to the functions to that object". And the other example (the language I'm working with) VBScript, which I had the trouble with. Sorry If it wasn't clear. – ProtectedVoid Jul 21 '15 at 12:54