Global Variables

R

Roger Johnson

Is there a way within VBScript to declare a variable as global during OnLoad?

I seem to lose the value each time I go to a different SUB, which indicates
to me that they are all local.
 
S

Scott L. Heim [MSFT]

Hi Roger,

When you first create an InfoPath solution, if you immediately open the
script editor (ALT+SHIFT+F11), you will see the following:

' This file contains functions for data validation and form-level events.
' Because the functions are referenced in the form definition (.xsf) file,
' it is recommended that you do not modify the name of the function,
' or the name and number of arguments.

' The following line is created by Microsoft Office InfoPath to define the
prefixes
' for all the known namespaces in the main XML data file.
' Any modification to the form files made outside of InfoPath
' will not be automatically updated.
'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-
29T12:56:06"""
'</namespacesDefinition>

If you simply add the following below what already exists, the variable
will be "global:"

Dim strName

You could then set that variable on the Load event of the form:

Sub XDocument_OnLoad(eventObj)
strName = "Scott"
End Sub

And you can still access that information from the click event of a button:

Sub CTRL1_5_OnClick(eventObj)
XDocument.UI.Alert strName
End Sub

I hope this helps! :)

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top