Converting GN3 code to GN4 code

Build 1501 on 14/Nov/2017  This topic last edited on: 5/Aug/2014, at 14:41

The syntax is different between VBScript (used in GN3) and VB code (used in GN4). Here are some basic guidelines, and this example of a GN3 Tera library function and a GN3 user script, commented line-by-line.

See also Differences between GN4 and GN3 scripting.

Basic guidelines

All variables have to be declared before using them, e.g. dim x.

It is recommended to add the type to the dim statement, e.g. dim x as Integer.

It is recommended to initialize variables when declaring them (where possible), e.g. dim x as Integer = 0.

Avoid to declare variables inside branching, as Visual Studio Express syntax checker will complain, e.g.

if blah-blah then

  dim x as Integer = 1

end if

msgbox (x)

In the red line, Visual Studio Express syntax checker complains that x is undeclared.

Correct code would be:

dim x as Integer = 0

if blah-blah then

  x = 1

end if

msgbox (x)

Use dim instead of set when declaring objects, e.g. dim obj = Text.GetParaStyle.

All parameters are to be enclosed in parenthesis.

hmtoggle_plus1GN3 code
hmtoggle_plus1GN4 code
hmtoggle_plus1Differences line-by-line