and here's a much later draft:

'  class #9 examples:  (4/17/2011)


' example 1
' demonstrating one use for XML file: storage of string data
' The Strings method places text strings in the XML file into a 
' dictionary object for easy retrieval. External strings allow for 
' easy localization into other languages.

Dim myXMLFile 
 myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"
' the name I've given last week's final example

Dim myStrings 
 Set myStrings = Strings(myXMLFile) ' the strings() is a root level method
which returns a dictionary object

' now initialize the clientInformation object (a root level property of the
application object)
ClientInformation.ScriptName = myStrings("SCRIPT_NAME")
ClientInformation.ScriptVersion = myStrings("SCRIPT_VERSION")
ClientInformation.ScriptDescription = myStrings("SCRIPT_DESCRIPTION")


' end of example 1


' example 2
' shows the easy way to get a shared object (in this case, the one used for
error reporting)

dim oErrorReporting 
Set oErrorReporting =
SharedObjects.Get("com.GWMicro.GWToolkit.ErrorReporting", 5000)
' the first parameter above is a combination of the "name space" used by GW,
and the specific object name;
' the second parameter is the number of milliseconds to wait for the object
before returning

If not oErrorReporting Is Nothing Then
' below lines are taken from  the instructions for how to use the error
reporting object
  sCode = oErrorReporting("1.0", "[email protected]", True)
  ExecuteGlobal sCode
end if

' end of example 2


' example 3
' here's the recommended way to get a shared object, by making use of the
event which tells you when each shared object is available.



' now connect to the onStateChange event of the sharedObjects object (which
is a root level property).
Dim errorReportingEnabled 
errorReportingEnabled = False

ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"

' end of main body

Function HandleStateChange(objName, objState)
' event handler for the onStateChange event of the sharedObjects object.
' the first parameter is the name of the object, and the second is true if
it's available, and false if not.

' this event gets triggered for each shared object  when your app starts, as
well as when new ones come online or go offline.

HandleStateChange = False

Select Case objName
' you only list CASE options for the objects you are interested in using
' even though you will receive a notification for all possible objects.

Case "com.GWMicro.GWToolkit.ErrorReporting"
  If objState Then
' object is available
' (here you put the commands specific to use of this object when it is
loaded)
    If Not errorReportingEnabled Then
      ExecuteGlobal SharedObjects(objName,
0)(ClientInformation.ScriptVersion, "[email protected]", True)
      errorReportingEnabled = True
    End If
  else
' object has become unavailable (maybe it's script has crashed)
' so maybe you do something in your script such as undefine a hotkey which
used this object, gray out some menu choices, whatever.
  end if

end select

HandleStateChange = True ' indicates you have handled this notification

end function

' end of example 3




' example 4
' showing the setup of the standard help object from the GW toolkit

' all of the variables below are automatically generated for you by
WEScriptFramework Wizard
Dim myScriptUpdateURL 
 myScriptUpdateURL =
"http://www.gwmicro.com/scripts/Notepad_Duplicate_Windows/xml";
Dim myINIFile 
 myINIFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.ini"
Dim myXMLFile 
myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"

' The myStrings variable places text strings in the XML file into a 
' dictionary object for easy retrieval. External strings allow for 
' easy localization into other languages.

Dim myStrings 
 Set myStrings = Strings(myXMLFile) ' strings is a root level method of the
application object
' the XML file is also automatically generated for you by WEScriptFramework
Wizard


      Set SO_StandardHelpDialog = Nothing
      ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"

' end of main body



Function HandleStateChange(objName, objState)
' event handler for the onStateChange event of the sharedObjects object.

If objName = "com.GWMicro.GWToolkit.StandardHelpDialog" Then
  If objState Then
' it's available
    Set SO_StandardHelpDialog = SharedObjects(objName, 0).NewDialog
    SO_StandardHelpDialog.INIFileName = myINIFile
    SO_StandardHelpDialog.HelpTitle = ClientInformation.ScriptName & " " &
ClientInformation.ScriptVersion
    SO_StandardHelpDialog.HelpText = myStrings("SCRIPT_HELP")
    SO_StandardHelpDialog.ScriptName = ClientInformation.ScriptName
    SO_StandardHelpDialog.ScriptVersion = ClientInformation.ScriptVersion
    SO_StandardHelpDialog.FocusCloseButton = false ' means set the editbox
with help text as the focused control
' if the above were left set to true, it would cause the close button to be
the control with focus at the start.
    SO_StandardHelpDialog.UpdateUrl = \myScriptUpdateURL
' the above can't really be set at first, you need to enter your app into
app central, in order to get it's associated web address for updates, which
you would then enter above

    SO_StandardHelpDialog.UseAboutBox = True
    SO_StandardHelpDialog.AboutAuthor = "Chip Orange"
    Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
    SO_StandardHelpDialog.AboutReleaseDate =
fsObj.GetFile(ClientInformation.ScriptPath & "\" &
ClientInformation.ScriptFileName).DateLastModified
    Set fsObj = Nothing
    SO_StandardHelpDialog.AboutCopyright = ""
    SO_StandardHelpDialog.AboutWebsite = ""
' Change ClientInformation.ScriptHelp to our real routine
    ClientInformation.ScriptHelp = "ScriptHelp"
  Else
                        ' Change ClientInformation.ScriptHelp to our default
message
    Set SO_StandardHelpDialog = Nothing
    ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
  End If
end if

end function


Sub ScriptHelp()
' after the help object has been initialized by the onStateChange event
handler above, this routine will be executed when the user presses the help
button in the app manager or chooses the help menu choice in the app's menu.
' before the help object is initialized, if the user asks for help, they
would get only the text stored in the .scriptHelp property of the
clientInformation object.

    SO_StandardHelpDialog.Show

End Sub



' end of example 4



' example 5
' showing how to initialize the shared object for checking for updates
' below would be placed in the onStateChange event handler:

        ElseIf objName = "com.GWMicro.GWToolkit.CheckForUpdate" Then
                If objState Then
                        Set SO_CheckForUpdate = SharedObjects(objName,
0).NewCheck
                        
                        If Not checkedForUpdates Then ' this is a global
variable you would initialize to false
                                Queue "CheckForUpdates" ' must use queue
because this is an event handler, and the checking will take a relatively
long time
                                checkedForUpdates = True
                        End If
                Else
                        Set SO_CheckForUpdate = Nothing
                End If
' end of code added to onStateChange event handler


Sub CheckForUpdates()
        ' Before instantiating the object, we need to see if automatic
updates
        ' have been enabled. We do that by checking the Automatic_Updates
        ' section of our INI file for a key called OnScriptStart. If it
exists,
        ' and the value is 1, then we'll attempt to check for a new version.
dim objINIFile
set objINIFile = IniFile(myINIFile) ' iniFile is a root level method of the
application object
        If objINIFile.Number("Automatic_Updates", "OnScriptStart") = 1 Then
                ' OnScriptStart was on, so we need to make sure the
CheckForUpdate 
                ' GW toolkit object is available for use (which it should be
since
                ' this subroutine only gets called when the SharedObject is 
                ' loaded).
                If Not SharedObjects("com.GWMicro.GWToolkit.CheckForUpdate",
10) Is Nothing Then
                        ' The CheckForUpdate object is available, so we'll
create our
                        ' own copy of the object.
                        Dim updateCheck 
 Set updateCheck = SharedObjects("com.GWMicro.GWToolkit.CheckForUpdate",
10).NewCheck

                        ' Now that we have our copy, we'll provide the
required 
                        ' information: our script version (which we stored
in the 
                        ' ClientInformation object in the global variables
section, and
                        ' the web address to our XML file, which we also
stored in
                        ' the global variables section.
                        updateCheck.ScriptVersion =
ClientInformation.ScriptVersion
                        updateCheck.UpdateUrl = myScriptUpdateURL
                        
                        ' Now that we've provided all the required
information, we
                        ' have the GW Toolkit check for an update.
                        updateCheck.Check
                        
                        ' Finally, we'll set the global flag that indicates
whether or
                        ' not we've already checked for updates to True
                        checkedForUpdates = True
                Else
                        ' Since we weren't able to get the toolkit object at
this point,
                        ' we need to make sure our global flag that
indicates whether
                        ' or not we've already checked for updates is set to
False.
                        CheckForUpdates = False
                End If
        End If

End Sub

' the above routine is automatically generated by WEScriptFramework Wizard,
and I've only added some comments etc. for clarity

' end of example 5
 

-----Original Message-----
From: Chip Orange [mailto:[email protected]] 
Sent: Sunday, April 17, 2011 1:23 PM
To: [email protected]
Subject: draft of today's scripting class (#9) examples

we'll be covering some things every app must have: shared objects, and the
way to get some of the needed info into the shared objects: by getting it
out of the xml file.

' Draft of  class #9 examples:  (4/17/2011)


' example 1
' demonstrating one use for XML file: storage of string data ' The Strings
method places text strings in the XML file into a ' dictionary object for
easy retrieval. External strings allow for ' easy localization into other
languages.

Dim myXMLFile
 myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"
' the name I've given last week's final example

Dim myStrings
 Set myStrings = Strings(myXMLFile) ' the strings() is a root level method
which returns a dictionary object

' now initialize the clientInformation object (a root level property of the
application object) ClientInformation.ScriptName = myStrings("SCRIPT_NAME")
ClientInformation.ScriptVersion = myStrings("SCRIPT_VERSION")
ClientInformation.ScriptDescription = myStrings("SCRIPT_DESCRIPTION")


' end of example 1


' example 2
' shows the easy way to get a shared object (in this case, the one used for
error reporting)

dim oErrorReporting
Set oErrorReporting =
SharedObjects.Get("com.GWMicro.GWToolkit.ErrorReporting", 5000) ' the first
parameter above is a combination of the "name space" used by GW, and the
specific object name; ' the second parameter is the number of milliseconds
to wait for the object before returning

If not oErrorReporting Is Nothing Then
' below lines are taken from  the instructions for how to use the error
reporting object
  sCode = oErrorReporting("1.0", "[email protected]", True)
  ExecuteGlobal sCode
end if

' end of example 2


' example 3
' here's the recommended way to get a shared object, by making use of the
event which tells you when each shared object is available.



' now connect to the onStateChange event of the sharedObjects object (which
is a root level property).
Dim errorReportingEnabled
errorReportingEnabled = False

ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"

' end of main body

Function HandleStateChange(objName, objState) ' event handler for the
onStateChange event of the sharedObjects object.
' the first parameter is the name of the object, and the second is true if
it's available, and false if not.

' this event gets triggered for each shared object  when your app starts, as
well as when new ones come online or go offline.

HandleStateChange = False

Select Case objName
' you only list CASE options for the objects you are interested in using '
even though you will receive a notification for all possible objects.

Case "com.GWMicro.GWToolkit.ErrorReporting"
  If objState Then
' object is available
' (here you put the commands specific to use of this object when it is
loaded)
    If Not errorReportingEnabled Then
      ExecuteGlobal SharedObjects(objName,
0)(ClientInformation.ScriptVersion, "[email protected]", True)
      errorReportingEnabled = True
    End If
  else
' object has become unavailable (maybe it's script has crashed) ' so maybe
you do something in your script such as undefine a hotkey which used this
object, gray out some menu choices, whatever.
  end if

end select

HandleStateChange = True ' indicates you have handled this notification

end function

' end of example 3




' example 4
' showing the setup of the standard help object from the GW toolkit Dim
myINIFile : myINIFile = ClientInformation.ScriptPath &
"\Notepad_Duplicate_Windows.ini"
Dim myXMLFile
myXMLFile = ClientInformation.ScriptPath & "\Notepad_Duplicate_Windows.xml"

' The myStrings variable places text strings in the XML file into a '
dictionary object for easy retrieval. External strings allow for ' easy
localization into other languages.

Dim myStrings
 Set myStrings = Strings(myXMLFile) ' strings is a root level method of the
application object


      Set SO_StandardHelpDialog = Nothing
      ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
ConnectEvent SharedObjects, "OnStateChange", "HandleStateChange"

' end of main body



Function HandleStateChange(objName, objState)
' event handler for the onStateChange event of the sharedObjects object.


Select Case objName
  If objName = "com.GWMicro.GWToolkit.StandardHelpDialog" Then
    If objState Then
' it's available
      Set SO_StandardHelpDialog = SharedObjects(objName, 0).NewDialog
      SO_StandardHelpDialog.INIFileName = myINIFile
      SO_StandardHelpDialog.HelpTitle = ClientInformation.ScriptName & " " &
ClientInformation.ScriptVersion
      SO_StandardHelpDialog.HelpText = myStrings("SCRIPT_HELP")
      SO_StandardHelpDialog.ScriptName = ClientInformation.ScriptName
      SO_StandardHelpDialog.ScriptVersion = ClientInformation.ScriptVersion
      SO_StandardHelpDialog.FocusCloseButton = True
      SO_StandardHelpDialog.UpdateUrl = myScriptUpdateURL
      SO_StandardHelpDialog.UseAboutBox = True
      SO_StandardHelpDialog.AboutAuthor = "Chip Orange"
      Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
      SO_StandardHelpDialog.AboutReleaseDate =
fsObj.GetFile(ClientInformation.ScriptPath & "\" &
ClientInformation.ScriptFileName).DateLastModified
      Set fsObj = Nothing
      SO_StandardHelpDialog.AboutCopyright = ""
      SO_StandardHelpDialog.AboutWebsite = ""
' Change ClientInformation.ScriptHelp to our real routine
      ClientInformation.ScriptHelp = "ScriptHelp"
    Else
                        ' Change ClientInformation.ScriptHelp to our default
message
      Set SO_StandardHelpDialog = Nothing
      ClientInformation.ScriptHelp = myStrings("GWToolkit_Required")
    End If
  end if

end function


Sub ScriptHelp()
' after the help object has been initialized by the onStateChange event
handler above, this routine will be executed when the user presses the help
button in the app manager or chooses the help menu choice in the app's menu.
' before the help object is initialized, if the user asks for help, they
would get only the text stored in the .scriptHelp property of the
clientInformation object.

    SO_StandardHelpDialog.Show
End Sub



' end of example 4


Reply via email to