Need help setting up an array within an HTA

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 13 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
thenoob74
Posts: 17
Last visit: Thu Sep 09, 2010 1:38 am

Need help setting up an array within an HTA

Post by thenoob74 »

Hello,I'm looking for some guidance on using an array in my VB project. I have 5 radio buttons on my HTA form. I'm looking for a way to have a program run with different switches depending on what is selected. We are setting up Tivoli Storage Manger and I am currently able to register the node and schedule it, but I need to be able to tell it which schedule to use. I've been looking at array functions and am not sure that is the best approach or not. If it is I'm looking for a little help to get me going. Thank you!I apologize I am not able to upload, looks like we have blocked that ability so I have to paste my code. Again I'm sorry! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ... dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>My HTML Application</title><script language="vbscript">Sub send1_onclick()strNodeIn = node.valuestrPswd = passw.valuestrID = usern.valuebaclient = "c:program filestivolitsmbaclient"dsmopt = "c:program filestivolitsmbaclientdsm.opt"If list2.Value = "" Then MsgBox "Please select a schedule" Exit Sub End ifstrCMD = "dsmadmc.exe -tcps=server.mikl.com -id=" & strID & " -password=" & strPswd & " register node " & strNodeIn & " pioneer userid=NONE contact=" & strID & " domain=standard compression=client backdelete=yes url=http://" & strNodeIn & ":1581 passexp=9999" Set objShell = CreateObject("Wscript.Shell") objShell.Run ("%comspec% /c" & strCMD),1,True strCMD1 = "dsmcutil remove /name:""TSM Client Scheduler"""strCMD = "dsmcutil.exe install Scheduler /name:""TSM Client Scheduler"" /node:" & strNodeIn & " /password:password /commmethod:tcpip /commserver:server.mikl.com /autostart:yes"'what to doif radio1.value="1" thenschedA = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD DESKTOP_A-E" & strNodeIn & ""if radio1.value="2" thenschedF = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD DESKTOP_F-K" & strNodeIn & ""if radio1.value="3" thenschedL = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD DESKTOP_L-N" & strNodeIn & ""if radio1.value="4" thenschedO = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD DESKTOP_O-S" & strNodeIn & ""if radio1.value="5" thenschedT = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD DESKTOP_T-Z" & strNodeIn & "" Set objShell = CreateObject("Wscript.Shell") objShell.Run ("%comspec% /c" & strCMD1),1,True objShell.Run ("%comspec% /c" & strCMD) End if End sub</script><hta:application applicationname="MyHTA" border="dialog" borderstyle="normal" caption="My HTML Application" contextmenu="no" icon="myicon.ico" maximizebutton="no" minimizebutton="yes" navigable="no" scroll="no" selection="no" showintaskbar="yes" singleinstance="yes" sysmenu="yes" version="1.0" windowstate="normal"></head><body style="background-color: #EF0000"><span>Node Name <input id="node" style="width: 209px"/></span><br /> <span>Admin TSM Username <input id="usern"/></span><br /> <span>Admin TSM Password <input id="passw"/><br /> </span><br /> Select Schedule: <form method="post"> Desktop_A-E<input name="Radio1" type="radio" value="1"/><br /> Desktop_F-K<input name="Radio1" type="radio" value="2"/><br /> Desktop_L-N<input name="Radio1" type="radio" value="3"/><br /> Desktop_O-S<input name="Radio1" type="radio" value="4"/><br /> Desktop_T-Z <input name="Radio1" type="radio" value="5"/></form> <br /> <br /> <input id="send1" type="button" value="Register Node"/> <br /> <br /></body></html>
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Need help setting up an array within an HTA

Post by rasimmer »

Select Case radio1.value Case "1" : strDesktop = "DESKTOP_A-E" Case "2" : strDesktop = "DESKTOP_F-K" Case "3" : strDesktop = "DESKTOP_L-N" Case "4" : strDesktop = "DESKTOP_O-S" Case "5" : strDesktop = "DESKTOP_T-Z"End SelectstrCMD = "dsmadmc -id=" & strNodeIn & " -password:password Define assoc STANDARD " & strDesktop & " " & strNodeIn
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Need help setting up an array within an HTA

Post by jvierra »

Here is an update RunCode Sub:

Code: Select all

Sub RunCode( iSelection, strNodeIn, strID, strPswd )
    
        baclient = "c:program filestivolitsmbaclient"
        dsmopt = "c:program filestivolitsmbaclientdsm.opt"
        strCMD = "dsmadmc.exe -tcps=server.mikl.com -id=" & strID & " -password=" & strPswd & " register node " & strNodeIn & " pioneer userid=NONE contact=" & strID & " domain=standard compression=client backdelete=yes url=http://" & strNodeIn & ":1581 passexp=9999"
        Set objShell = CreateObject("Wscript.Shell")
        objShell.Run ("%comspec% /c" & strCMD),1,True  
        strCMD1 = "dsmcutil remove /name:""TSM Client Scheduler"""
        strCMD = "dsmcutil.exe install Scheduler /name:""TSM Client Scheduler"" /node:" & strNodeIn & " /password:password /commmethod:tcpip /commserver:server.mikl.com /autostart:yes"
        'what to do
        Select Case iSelection
            Case 1: schedA = "dsmadmc -id=" & strNodeIn & " -password:password  Define assoc STANDARD DESKTOP_A-E" & strNodeIn & ""
            Case 2: schedF = "dsmadmc -id=" & strNodeIn & " -password:password  Define assoc STANDARD DESKTOP_F-K" & strNodeIn & ""
            Case 3: schedL = "dsmadmc -id=" & strNodeIn & " -password:password  Define assoc STANDARD DESKTOP_L-N" & strNodeIn & ""
            Case 4: schedO = "dsmadmc -id=" & strNodeIn & " -password:password  Define assoc STANDARD DESKTOP_O-S" & strNodeIn & ""
            Case 5: schedT = "dsmadmc -id=" & strNodeIn & " -password:password  Define assoc STANDARD DESKTOP_T-Z" & strNodeIn & ""
         End Select
         
         Set objShell = CreateObject("Wscript.Shell")
         objShell.Run ("%comspec% /c" & strCMD1),1,True 
         objShell.Run ("%comspec% /c" & strCMD) 
                 
    End Sub

Note that it now contains no validation. That is teh job of the UI and not the work code. By separating the job out this way you can independently test and debug the work code which cannot be done in an HTA. The WIndows Debugger, MSAccess, Excel, MSWord or PromalScript can all debug VBScript files but NONE can debug an HTA. Always build and test you work code as a VBScript subroutine usign arguments or an argument array to pass in all fields collected from the HTA/Screen.

Call the sub statically from the VBS and test it until it works as needed. Just remember that you cannot use WScript object or its methodsa without special consideration.

Call the above this way

Code: Select all

in the VBS file
	RunCode  1, "nodename", "userid", "password"</strong></DIV>

In the HTA:
	RunCode  btn.value, node.value, usern.value, passw.value

Once you understand and maser this technique you will find it much easier to create HTAs and all code.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Need help setting up an array within an HTA

Post by jvierra »

Here are some demos of better ways to control teh layout without inserting hundreds of nbsp and BR sets. Use CSS and positioning. It easier.

uploads/2491/demohta3.hta.txt

If we want teh radio buttons to line up nicely here we would just select a fixed width font and that would allow allignment. We can also do other things like force the labels to behave differently. ';abel' controls have been deprecated although they still work. th 'SPAN' tag will probably actually work better for allignment purposes.

Note: To upload a file you need to click the control in the toolbar above the 'reply' editor to open the enhanced editor. If this is not available then go to the Member Control Panel and select 'Forum Preferences' and select to use WYSIWYG editor which will allow you to upload and format edits.



jvierra2010-08-24 11:19:58
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Need help setting up an array within an HTA

Post by jvierra »

YOu have too many errors in your code. You will find it very hard trying to debug an HTA. Start, as suggested with a vbscript file to save yourself a lot of headaches.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Need help setting up an array within an HTA

Post by jvierra »

Here is an even simpler version of the same thing merging some of rassimer's reduction of the case statement. I have used the radio button value to supply the required string.

Code: Select all

<html>
<head>
<title>My HTML Application</title>
<script language="vbscript">
    Sub send1_onclick()
        for each btn In Radio
            If btn.checked Then 
                MsgBox btn.value
                If usern.value <> "" Then
                    RunCode btn.value,node.value, usern.value, passw.value
                End If
            End If
        Next
    End Sub
        
    Sub RunCode( assoc, strNodeIn , strID, strPswd )
        baclient = "c:program filestivolitsmbaclient"
        dsmopt = "c:program filestivolitsmbaclientdsm.opt"
        strCMD = "dsmadmc.exe -tcps=server.mikl.com -id=" & strID & " -password=" & strPswd & " register node " & strNodeIn & " pioneer userid=NONE contact=" & strID & " domain=standard compression=client backdelete=yes url=http://" & strNodeIn & ":1581 passexp=9999"
        Set objShell = CreateObject("Wscript.Shell")
        objShell.Run ("%comspec% /c" & strCMD),1,True  
        strCMD1 = "dsmcutil remove /name:""TSM Client Scheduler"""
        strCMD = "dsmcutil.exe install Scheduler /name:""TSM Client Scheduler"" /node:" & strNodeIn & " /password:password /commmethod:tcpip /commserver:server.mikl.com /autostart:yes"
                 
' somewher eher i suspect you need to build a string with the 'assoc' value in it
         objShell.Run "%comspec% /c" & strCMD1,1,True 
         objShell.Run "%comspec% /c" & strCMD 
                 
    End Sub
</script>
<hta:application
    applicationname="MyHTA"    
    border="dialog"
    borderstyle="normal"
    caption="My HTML Application"
    contextmenu="no"
    icon="myicon.ico"
    maximizebutton="no"
    minimizebutton="yes"
    navigable="no"
    scroll="no"
    selection="no"
    showintaskbar="yes"
    singleinstance="yes"
    sysmenu="yes"
    version="1.0"
    windowstate="normal"
>
</head>
<body style="background-color: #EF0000">
    <span>Node Name&nbsp; <input id="node" style="width: 209px"/></span><br />
    <span>Admin TSM Username <input id="usern"/></span><br />
    <span>Admin TSM Password <input id="passw"/></span><br />
    <div>
        Select Schedule:<br />
        Desktop_A-E<input name="Radio" type="radio" <FONT color=#cc0000>value="STANDARD DESKTOP_A-E"/</FONT>><br />
        Desktop_F-K<input name="Radio" type="radio" <FONT color=#cc0033>value="STANDARD DESKTOP_F-K"</FONT>/><br />
        Desktop_L-N<input name="Radio" type="radio" <FONT color=#cc0000>value="STANDARD DESKTOP_L-N"/</FONT>><br />
        Desktop_O-S<input name="Radio" type="radio" <FONT color=#cc0000>value="STANDARD DESKTOP_O-S"/</FONT>><br />
        Desktop_T-Z<input name="Radio" type="radio" <FONT color=#cc0000>value="STANDARD DESKTOP_T-Z</FONT>"/><br />
    </div>
    <br />
    <input id="send1" type="button" value="Register Node"/>
    <br />
    <br />
    
</body>
</html>

Nowhere in any of your example code do you ever use this value.

YOu have used parens in teh comand strings which may cause an issue. I removed them as they are not required.

Using a radio button to set a specific value to use later is common use for radio buttons. A radio button set IS a case statement or filter while a checkbox is a visible ANDing operation. Coding a case or if statement to reprocess this produces no added value but only adds more error prone lines of code.

Take the lesson from someone who has been writing HTAs.HTML for more than 20 years. This suggestionalong with debugging the main task in a vbscript file will save you a load of wasted time.

jvierra2010-08-25 07:21:54
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Need help setting up an array within an HTA

Post by jvierra »

Here is a more complete demo of how a radio button array works. Note that there are two modes of access to the array.

uploads/2491/radio_buttons.htm.txt

CLicking on link should display file in most browsers. If not theen download and change extension to HTM and it will run in browser.

Right-click to see source.
This topic is 13 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked