Re: Arrays and TextBoxes



On Jun 12, 12:20 pm, MattW <winber...@xxxxxxxxx> wrote:
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>
[/code]

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
************
.



Relevant Pages

  • Re: Arrays and TextBoxes
    ... values of the textboxes into an array. ... Dim arrUsers ...
    (microsoft.public.scripting.vbscript)
  • Re: "Sorting" assignment
    ... If the array is already sorted, this means that you end up ... less time than a bubble sort, ...     int intLeft, ... I don't declare anything inside of a loop is why. ...
    (comp.programming)
  • Re: #defining an array within another in C language
    ... you do not know the number of elements of the array. ...     int var; ... C99 flexible array members or the plain old "struct hack". ...
    (comp.lang.c)
  • Re: Generic programming in C
    ... struct tag$ArrayInterface; ...     unsigned int Flags; ... specific type as the contents of the array. ...
    (comp.lang.c)
  • Re: Allocattable and namelist object
    ...   NAMELIST/TOTO/TAB ... array can be in a namelist object. ... The shape of an allocatable array can ... A deferred-shape array is an allocatable array or an ...
    (comp.lang.fortran)