Check for string value of global variable

Hello,
I have a global variable that I assigned it a string value by using the command
@set $glob:MyGlob="TheValue"
What is the right command to check if MyGlob="WheteverValue" in a VBS script?

Thank you

if DOpus.vars.Get("MyGlob") = "TheValue" Then ...

Thank you Jon but I receive an error:
Error at line 3, position 2
Invalid procedure call or argument: 'DOpus.vars.Get' (0x800a0005)

This the code that I am using in a button

Option Explicit
Function OnClick(ByRef clickData)
	if DOpus.vars.Get("MyGlob") = "TheValue" Then 
	  dopus.output "HaveIt"
	End If
End Function

Is the variable actually set? You'll get an error if you try to use Get on a variable that doesn't exist.

You can test if it exists first to avoid the error:

Option Explicit

Function OnClick(ByRef clickData)

	If DOpus.vars.Exists("MyGlob") Then
		If DOpus.vars.Get("MyGlob") = "TheValue" Then
			DOpus.Output "MyGlob = ""TheValue"""
		Else
			DOpus.Output "MyGlob <> ""TheValue"". MyGlob = """ & DOpus.vars.Get("MyGlob") & """"
		End If
	Else
		DOpus.Output "MyGlob is not set to any value"
	End If
End Function

Also note that the way you are setting the value will set it to "TheValue" including quotes, not to TheValue.

If you don't want the quotes, just use:

@set $glob:MyGlob=TheValue

PS: Remember not to combine the Exists and Get calls into a single line in VBScript. This won't work, which is one thing I hate about VBScript. :slight_smile:

' WON'T WORK:
If DOpus.vars.Exists("MyGlob") And DOpus.vars.Get("MyGlob") = "TheValue" Then 

(Similar is fine in JScript, on the other hand.)

Thank you Leo you are a life saver it is working properly now.

Leo, I would need another help from you regarding a global variable with a string value.
I would like to make the string variable persistent that it would exist even after restart of the program. The following is the declaration of the variable that I made in a button: @set $glob:MyVar=TheStringValue persist
But after a restart of the program the variables does not exist. I have been looking in the help file but I couldn't find how to do it.

Thanks in advance for your help

I was looking at this chapter but I missed the last sentence.

Thank you