VB Script Variable Declaration

Post Reply
SDNPDG_Quality
User
User
Posts: 12
Joined: Mon May 08, 2017 1:58 pm

VB Script Variable Declaration

Post by SDNPDG_Quality » Tue Jul 23, 2019 1:27 pm

I ran a program originally written in version 3.7SP2 with VB script that declared variables, e.g.

Dim top As String

When I try the same code in version 3.9 I get an "Expected end of statement" syntax error. If I comment out (or remove) the "As String" the syntax error goes away. What am I missing?

User avatar
CrashN8
Site Admin
Site Admin
Posts: 367
Joined: Thu Feb 09, 2017 4:07 pm

Re: VB Script Variable Declaration

Post by CrashN8 » Tue Jul 23, 2019 5:25 pm

New VB Engine starting in 3.8 does not require dimensioning Variables or Objects. Everything is treated as variant allowing you to bypass this extra bit of code. Keep in mind if you need to concatenate two variables, you may need to convert one or more variable to String - For example:

Code: Select all

MyVar1 = 123
MyVar2 = ABC

MyVar3 = CStr(MyVar1) + CStr(MyVar2)

Post Reply