![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Arrays and TextBoxes Hi all. I've got 2 textboxes in an HTA, and I'm trying to pull the values of the textboxes into an array. Here's what I've got code wise. Code: <HTML> <HEAD> <TITLE>Users Group Migration HTA</TITLE> <HTA:APPLICATION ID="MyApp" APPLICATIONNAME="Template" BORDER="thick" BORDERSTYLE="complex" CAPTION="yes" CONTEXTMENU="no" ICON="http://Your URL/your icon.ico" INNERBORDER="yes" MAXIMIZEBUTTON="yes" MINIMIZEBUTTON="yes" NAVIGABLE="no" SCROLL="no" SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="yes" VERSION="1.0" WINDOWSTATE="maximized"/> </HEAD> <SCRIPT Language="VBScript"> Sub Window_onLoad window.resizeTo 640, 480 End Sub ' Cancel button Sub ExitProgram window.close() End Sub Dim arrUsers(1) arrUsers(0) = User1.value arrUsers(1) = User2.value Function myBox(x) myBox = arrusers(i) End Function 'Let's use our function! Sub btnComp_Click Dim result For i = 0 To 1 If i = 0 Then result = myBox(i) MsgBox (result) ElseIf i = 1 Then MsgBox "This is what comes next." End If Next End Sub </Script> <body STYLE="font:10pt arial; color:white; (background-color:Menu; color:MenuText; cursor:default;)"> <p align=left><b>Group Migration Tool</b></font></p> <table> <tr> <col align="left"></col> <col width="160"></col> <col align="left"></col> <th><b>New User ID.</b></th> <th> </th> <th><b>Template User ID.</b></th> </tr> <tr> <td><input type="text" name="User1" size=20><p align=left></td> <td> </td> <td><input type="text" name="User2" size=20><p align=left></td> </tr> </table> <tr> <td><input type="button" value="Compare" name="btnComp" onClick="btnComp_Click" STyle='background-color: ButtonFace;' STyle='color:ButtonText;'></td> <td><input id=runbutton type="button" value="Cancel" onClick="ExitProgram" STyle='background-color: ButtonFace;' STyle='color:ButtonText;'></td> </tr> <p> <Span ID = "UserGroup1"</Span> <Span ID = "UserGroup2"</Span> </body> </html> User1 in line 34. I don't understand why. I've been googling, and I've seen solutions that involve assigning variables to each textbox, but I had thought that defining them in the array would take care of that. Can someone show me where I'm going wrong? Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Arrays and TextBoxes On Jun 12, 11:20*am, MattW <winber...@xxxxxx> wrote: Quote: > Hi all. *I've got 2 textboxes in an HTA, and I'm trying to pull the > values of the textboxes into an array. *Here's what I've got code > wise. > > Code: > <HTML> > * * * * <HEAD> > * * * * * * * * <TITLE>Users Group Migration HTA</TITLE> > * * * * * * * * <HTA:APPLICATION > * * * * * * * * * * * * ID="MyApp" > * * * * * * * * * * * * APPLICATIONNAME="Template" > * * * * * * * * * * * * BORDER="thick" > * * * * * * * * * * * * BORDERSTYLE="complex" > * * * * * * * * * * * * CAPTION="yes" > * * * * * * * * * * * * CONTEXTMENU="no" > * * * * * * * * * * * * ICON="http://YourURL/your icon.ico" > * * * * * * * * * * * * INNERBORDER="yes" > * * * * * * * * * * * * MAXIMIZEBUTTON="yes" > * * * * * * * * * * * * MINIMIZEBUTTON="yes" > * * * * * * * * * * * * NAVIGABLE="no" > * * * * * * * * * * * * SCROLL="no" > * * * * * * * * * * * * SHOWINTASKBAR="yes" > * * * * * * * * * * * * SINGLEINSTANCE="yes" > * * * * * * * * * * * * SYSMENU="yes" > * * * * * * * * * * * * VERSION="1.0" > * * * * * * * * * * * * WINDOWSTATE="maximized"/> > * * * * </HEAD> > * * * * <SCRIPT Language="VBScript"> > * * * * Sub Window_onLoad > window.resizeTo 640, 480 > End Sub > > ' Cancel button > Sub ExitProgram > window.close() > End Sub > > Dim arrUsers(1) > arrUsers(0) = User1.value > arrUsers(1) = User2.value > Function myBox(x) > * * myBox = arrusers(i) > * * End Function > > 'Let's use our function! > Sub btnComp_Click > Dim result > For i = 0 To 1 > If i = 0 Then > result = myBox(i) > MsgBox (result) > ElseIf i = 1 Then > MsgBox "This is what comes next." > End If > Next > End Sub > </Script> > * * * * <body STYLE="font:10pt arial; color:white; > (background-color:Menu; > color:MenuText; > cursor:default;)"> > * * * * <p align=left><b>Group Migration Tool</b></font></p> > *<table> > *<tr> > *<col align="left"></col> > *<col width="160"></col> > *<col align="left"></col> > *<th><b>New User ID.</b></th> > *<th> </th> > *<th><b>Template User ID.</b></th> > *</tr> > *<tr> > * <td><input type="text" name="User1" size=20><p align=left></td> > *<td> </td> > *<td><input type="text" name="User2" size=20><p align=left></td> > * *</tr> > * *</table> > * *<tr> > * * * * <td><input type="button" value="Compare" name="btnComp" > onClick="btnComp_Click" STyle='background-color: ButtonFace;' > STyle='color:ButtonText;'></td> > * * * * *<td><input id=runbutton type="button" value="Cancel" > onClick="ExitProgram" STyle='background-color: ButtonFace;' > STyle='color:ButtonText;'></td> > * * * * * * </tr> > * * * * <p> > <Span ID = "UserGroup1"</Span> > <Span ID = "UserGroup2"</Span> > </body> > </html> > > When I try to run it, I immediately get an Object Required error on > User1 in line 34. *I don't understand why. *I've been googling, and > I've seen solutions that involve assigning variables to each textbox, > but I had thought that defining them in the array would take care of > that. *Can someone show me where I'm going wrong? *Thanks! long day. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Arrays and TextBoxes On Jun 12, 12:20*pm, MattW <winber...@xxxxxx> wrote: Quote: > Hi all. *I've got 2 textboxes in an HTA, and I'm trying to pull the > values of the textboxes into an array. *Here's what I've got code > wise. > > Code: > <HTML> > * * * * <HEAD> > * * * * * * * * <TITLE>Users Group Migration HTA</TITLE> > * * * * * * * * <HTA:APPLICATION > * * * * * * * * * * * * ID="MyApp" > * * * * * * * * * * * * APPLICATIONNAME="Template" > * * * * * * * * * * * * BORDER="thick" > * * * * * * * * * * * * BORDERSTYLE="complex" > * * * * * * * * * * * * CAPTION="yes" > * * * * * * * * * * * * CONTEXTMENU="no" > * * * * * * * * * * * * ICON="http://YourURL/your icon.ico" > * * * * * * * * * * * * INNERBORDER="yes" > * * * * * * * * * * * * MAXIMIZEBUTTON="yes" > * * * * * * * * * * * * MINIMIZEBUTTON="yes" > * * * * * * * * * * * * NAVIGABLE="no" > * * * * * * * * * * * * SCROLL="no" > * * * * * * * * * * * * SHOWINTASKBAR="yes" > * * * * * * * * * * * * SINGLEINSTANCE="yes" > * * * * * * * * * * * * SYSMENU="yes" > * * * * * * * * * * * * VERSION="1.0" > * * * * * * * * * * * * WINDOWSTATE="maximized"/> > * * * * </HEAD> > * * * * <SCRIPT Language="VBScript"> > * * * * Sub Window_onLoad > window.resizeTo 640, 480 > End Sub > > ' Cancel button > Sub ExitProgram > window.close() > End Sub > > Dim arrUsers(1) > arrUsers(0) = User1.value > arrUsers(1) = User2.value > Function myBox(x) > * * myBox = arrusers(i) > * * End Function > > 'Let's use our function! > Sub btnComp_Click > Dim result > For i = 0 To 1 > If i = 0 Then > result = myBox(i) > MsgBox (result) > ElseIf i = 1 Then > MsgBox "This is what comes next." > End If > Next > End Sub > </Script> > * * * * <body STYLE="font:10pt arial; color:white; > (background-color:Menu; > color:MenuText; > cursor:default;)"> > * * * * <p align=left><b>Group Migration Tool</b></font></p> > *<table> > *<tr> > *<col align="left"></col> > *<col width="160"></col> > *<col align="left"></col> > *<th><b>New User ID.</b></th> > *<th> </th> > *<th><b>Template User ID.</b></th> > *</tr> > *<tr> > * <td><input type="text" name="User1" size=20><p align=left></td> > *<td> </td> > *<td><input type="text" name="User2" size=20><p align=left></td> > * *</tr> > * *</table> > * *<tr> > * * * * <td><input type="button" value="Compare" name="btnComp" > onClick="btnComp_Click" STyle='background-color: ButtonFace;' > STyle='color:ButtonText;'></td> > * * * * *<td><input id=runbutton type="button" value="Cancel" > onClick="ExitProgram" STyle='background-color: ButtonFace;' > STyle='color:ButtonText;'></td> > * * * * * * </tr> > * * * * <p> > <Span ID = "UserGroup1"</Span> > <Span ID = "UserGroup2"</Span> > </body> > </html> > > When I try to run it, I immediately get an Object Required error on > User1 in line 34. *I don't understand why. *I've been googling, and > I've seen solutions that involve assigning variables to each textbox, > but I had thought that defining them in the array would take care of > that. *Can someone show me where I'm going wrong? *Thanks! before the page has had time to load. This is because your code places the assignments outside of the initialization routine. Code in this 'global' space is executed as the page loads, which means it is executed before the USERx elements are instantiated. This also has the major problem of making them statically defined, so that the contents of the array cannot change in response to the user's input. This can be fixed in one of two ways: 1. Move the assignment statements into the Mybox routine (but leave the DIM statement outside to create the needed global variable). That is ... Function myBox(x) arrUsers(0) = User1.value arrUsers(1) = User2.value myBox = arrUsers(x).value End Function or, a better way 2. Change the two textboxes to have the exact same name, say arrUsers, and access them directly as an array of textboxes, as in ... <tr> <td><input type="text" name="arrUsers" size=20><p align=left></td> <td> </td> <td><input type="text" name="arrUsers" size=20><p align=left></td> </tr> and Function myBox(x) myBox = arrUsers(x).value End Function Then you don't need the array or its value assignments. In fact the need for the function goes away as well, as the arrUsers element array can be directly accessed where needed. Tom Lavedas ************ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Comparing arrays | PowerShell | |||
| Re: Multidimensional Arrays | PowerShell | |||
| Question About arrays | VB Script | |||
| Arrays | PowerShell | |||
| cannot type in textboxes | Vista performance & maintenance | |||