Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Arrays and TextBoxes

Reply
 
Old 06-12-2009   #1 (permalink)
MattW


 
 

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>&nbsp;</th>
<th><b>Template User ID.</b></th>
</tr>
<tr>
<td><input type="text" name="User1" size=20><p align=left></td>
<td>&nbsp;</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!


My System SpecsSystem Spec
Old 06-12-2009   #2 (permalink)
MattW


 
 

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>&nbsp;</th>
> *<th><b>Template User ID.</b></th>
> *</tr>
> *<tr>
> * <td><input type="text" name="User1" size=20><p align=left></td>
> *<td>&nbsp;</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!
Nevermind, I had dimmed my variables in the wrong place. It's been a
long day.
My System SpecsSystem Spec
Old 06-12-2009   #3 (permalink)
T Lavedas


 
 

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>&nbsp;</th>
> *<th><b>Template User ID.</b></th>
> *</tr>
> *<tr>
> * <td><input type="text" name="User1" size=20><p align=left></td>
> *<td>&nbsp;</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!
The problem lies in the fact that the array assignments are occurring
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>&nbsp;</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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46