It's often the case that you want to read content from a file (e.g. an INI or, to bring us right up-to-date, an XML file) and use that content in a script. If you have more than a few items, it quickly becomes tedious to code the passing of the content to script variables. This is where the little-known Execute command (and its neighbour ExecuteGlobal) becomes so useful. In essence, this allows you dynamically populate variables (amongst other things) in script.

Here's an example which is in daily use at the client I'm working for. Forgive me for including what might be extraneous code - I couldn't be bothered to edit it:'// The INI being read looks like this:
'// [London]
'// SiteIdentifiers=OXF,TCR,CHX
'// AppPath=http://main.btcc.somewhere.com/webcommnet
'// WebServer=mainwc.btcc.somewhere.com
'// IPAddress=mainais.btcc.somewhere.com
'// The script defines the variables we will populate. Note that the variable names match the INI file's value names:
'// Dim strSiteIdentifiers
'// Dim strAppPath
'// Dim strWebServer
'// Dim strIPAddress
'// The script then reads the INI (I use a heavily-edited version of the rather nice INI class from JSWare (http://www.jsware.net)
blnReturn_Customise = objINIFile.GetSectionValues(strSiteName, arrSiteValues)

For intSiteIndex = 1 To UBound(arrSiteValues)
strData = Trim(arrSiteValues(intSiteIndex))
If Len(strData) > 0 Then
strValueName = Trim(Split(strData, "=")(0))

If strValueName <> "SiteIdentifiers" Then
'// If the data itself contains 'equals' signs, we need to split it
blnResult = GetSubstringCount("=", strData, True, intIndex)
If intIndex > 1 Then
'// Reset intIndex by finding the first 'equals' sign
intIndex = InStr(strData, "=")
'// I could use Split again, of course, but...
strValueData = Right(strData, (Len(strData) - intIndex))
strValueData = Trim(Split(strData, "=")(1))
End If

'// Populate the remaining strings to be used for settings
'// (Use ExecuteGlobal if the variables are to be global in scope.)
strMsg = "str" & strValueName & "=" & Chr(34) & strValueData & Chr(34)
'// THIS is where the action is. It takes strMsg and shoe-horns it into memory,
'// almost as if you were in there, typing "str" & strValueName & "=" & Chr(34) & strValueData & Chr(34) !!
Execute strMsg
End If
End If

'// Some of you might also have worked out by this stage that there's no need to even decalre the variables first!
'// There's no reason why (other than client paranoia in my case) why the last 2 lines couldn't be like this:
'// strMsg = "Dim str" & strValueName & ":" & "str" & strValueName & "=" & Chr(34) & strValueData & Chr(34)
'// Execute strMsg
0 Comments   [ - ] Hide Comments


Please log in to comment

There are no answers at this time
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity