I tried to write a simple hta application. I just wanted to load .ini files in order to build four <select> based on the .ini files.
As the code is the same for each file load, i wanted to write a function in order to reuse it to build each <select>, just passing the form name or id (?)
Part of this code was found on scripting guys blog (or site don't remember), just wanted to improve it ...
I clearly don't arrive to send the <select> into the function.
Code: Select all
<html>
<head>
<title>Computer Naming</title>
<HTA:APPLICATION
CAPTION="yes"
ID="MMD"
APPLICATIONNAME="Airbus Naming Computer"
BORDER="thin"
INNERBORDER="no"
SCROLL="no"
SINGLEINSTANCE="yes"
SHOWINTASKBAR="no"
SYSMENU="yes"
WINDOWSTATE="normal"
SELECTION="no"
CONTEXTMENU="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGABLE="yes"
ICON="mobsync.exe"
VERSION="1.0"
>
</head>
<SCRIPT Language="VBScript">
'#Load each component
'Dim oFile as String
'Dim oForm as Document.element
Sub Window_Onload
LoadForms "sites.ini" ,aSites
LoadForms "types.ini" ,aType
LoadForms "asset.ini" ,aAsset
LoadForms "natco.ini" ,aNatco
End Sub
'#sites.ini file
Sub LoadForms(oFile, oForm)
ClearForm(oForm)
oSelect = Document.getElementbyID(oForm)
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile(oFile)
strOptions = objFile.ReadAll
objFile.Close
arrOptions = Split(strOptions, vbNewLine)
For Each strOption in arrOptions
Set objOption = Document.createElement("OPTION")
If Instr(strOption,"=") = 3 Then
objOption.Text = Mid(strOption,4)
objOption.Value = Mid(strOption,1,2)
Else
objOption.Text = Mid(strOption,3)
objOption.Value = Mid(strOption,1,1)
End If
oSelect.Options.Add(objOption)
arrOptions = Null
strOption = Null
Next
End Sub
'#Refresh on click
Sub ClearForm(oForm)
oSelect = Document.GetElementbyID(oForm)
For Each objOption in oSelect.Options
objOption.RemoveNode
Next
End Sub
</SCRIPT>
<body>
<select onActivate="LoadForms 'sites.ini' ,aSites" id=aSites>
</select>
<select onActivate="LoadForms 'types.ini' ,aTypes" id=aTypes>
</select>
<select onActivate="LoadForms 'asset.ini' ,aAsset" id=aAsset>
</select>
<select onActivate="LoadForms 'natco.ini' ,aNatco" id=aNatco>
</select>
<p>
<input type="text" name="computername">
</input>
</p>
<div id="display"> </div>
</body>
</html>
Each .ini file attached to this application is write as following :
Parameter=Text to display
Exemple for country:
FR=France
DE=Germany
UK=England
...
Have you any simple idea to do this working ?
Thanks in advance.