I am building a HTA that will accept a list of users to be pasted into a
textarea. It appears when using a text area textarea.value stores all input
as one variable. For instance, if I put it
user1
user2
user3

the variable stores it as
user1
user2
user3

Does anybody know of a way that I can break the variable apart other than
using a split function?

Thanks

Re: Variable Issue by Anthony

Anthony
Fri Jan 27 03:16:00 CST 2006

What's wrong with the Split function?
If you could imagine a new piece of functionality that would ideally suit
your needs what would it be?

Anthony.



Re: Variable Issue by deckhopper

deckhopper
Sat Jan 28 16:44:31 CST 2006

Try the following:

<html>
<head>
<title>Add Users</title>

<HTA:APPLICATION
ID="objBuildUserArray"
APPLICATIONNAME="BuildUserArray"
SCROLL="yes"
SINGLEINSTANCE="no"
WINDOWSTATE="normal">
</head>

<script language="VBScript">
Option Explicit
Dim objShell
Dim arrUsers()
Dim x : x = 0

Set objShell = CreateObject("WScript.Shell")

'Sizes Window on startup
'-------------------------------------------------------
Function Window_OnLoad()
Const iWIDTH = 525
Const iHEIGHT = 450
Window.ResizeTo iWIDTH, iHEIGHT
Window.MoveTo (Screen.availWidth-iWIDTH)/2,_
(Screen.availHeight-iHEIGHT)/2
DataArea1.innerHTML = x
usersTextBox.focus()
End Function
'--------------------------------------------|

'Adds users to an array : checks for empty entry
'-------------------------------------------------------
Sub addUser(user)

If user.Value <> "" And user.Value <> " " _
And user.Value <> " " Then
ReDim Preserve arrUsers(x)
arrUsers(x) = user.Value
x=x+1
DataArea1.innerHTML = x
user.Value = ""
user.focus()
Else
MsgBox "Field Cannot Be Empty!",0,_
"Please Enter User Name"
user.focus()
End If

End Sub
'--------------------------------------------|

'Shows list of users
'-------------------------------------------------------
Sub showUsers()

Dim y,msg
If x <> 0 Then
For y=0 To UBound(arrUsers)
msg = msg & y+1 & ". " & arrUsers(y) & vbCr
Next
MsgBox msg,0,"Total Users: " & x
usersTextBox.focus()
Else
MsgBox "No Users Entered",0,"Total Users: " & x
usersTextBox.focus()
End If

End Sub
'--------------------------------------------|

'Starts HTA over
'-------------------------------------------------------
Sub RunScriptHTARefresh
Location.Reload(True)
End Sub
'--------------------------------------------|
</script>

<body>

<input id=usersTextBox type="text" maxlength="29"
size="30">
<a
style="position:absolute;right:70;font:bold 1em arial;">
Users Added:&nbsp&nbsp&nbsp<span id="DataArea1"></span>
</a><br><hr>

<input id=addUsers type="button" value="Add User"
onClick="addUser(usersTextBox)"><br><hr>

<input id=showAllUsers type="button"
value="Show All Users"
onClick="showUsers()"><br><hr>

<input id=refresh type="button" value="Refresh"
onClick="RunScriptHTARefresh"><p>
<a
style="font-family:arial;font-weight:bold;color=red;">
Warning: Hitting Refresh button<br>
clears everything and starts over.
</body>
</html>


Re: Variable Issue by deckhopper

deckhopper
Sat Jan 28 17:21:42 CST 2006

My mistake... I misunderstood your need. Looks like split is the only
way to go here. Part of your problem might be the delimiter you are
using for your SPLIT function. I used the linefeed character chr(10)
and it appears to work fine.

<html>
<head>
<title></title>
<script language="vbs">
Sub Window_OnLoad()
add01.focus()
add01.Value=""
End Sub

Function doTheSplitWithJamesBrown(text)
stuff = text.Value
splitArray = Split(stuff, chr(10), -1, 0)
For x=0 To UBound(splitArray)
msgbox splitArray(x),0,"Array Element: " & x
Next
End Function
</script>
</head>

<body >
<p>Users</p>
<div>
<textarea id="add01" name="users" cols="30" rows="4">
</textarea>
</div>
<div>
<input id="clicker" type="button" value="Click Me"
onClick="doTheSplitWithJamesBrown(add01)">
</div>
</body>
</html>