...

View Full Version : arrays



Baleric
03-01-2006, 01:36 AM
jsut curious...
I would like to know what arrays are and what they are able to be used for.
ive been seeing them a fair bit in here and would like to understand a little better.

thanks
-baleric

ihitman
03-01-2006, 11:13 AM
See :: http://www.w3schools.com/vbscript/vbscript_variables.asp :: here for a wee example and example.

GoComplain
03-01-2006, 12:34 PM
Arrays are used to store a series of related data items.

Pretty simple:

<%
Dim things(1000)
For i = 1 to 100
things(i) = i
Next

Do While i < 1000
Response.Write things(i) & ", "
Loop
%>

This will show the number 1 - 1000 you can also do that with text, just like on w3's site:

<script type="text/vbscript">
dim famname(5)
famname(0)="Jan Egil"
famname(1)="Tove"
famname(2)="Hege"
famname(3)="Stale"
famname(4)="Kai Jim"
famname(5)="Borge"
for i=0 to 5
document.write(famname(i) & "<br />")
next
</script>

Variables are a object that can change depending on what information you would like it to have:

i.e.

strBGColor = "#FFFFFF"

Response.Write "<body bgcolor=""" & strBGColor """>"

degsy
03-01-2006, 02:06 PM
It's also useful to know that Request collections are submitted in arrays and some form variables are submitted in arrays.

e.g.


<%
For Each Item In Request.ServerVariables
Response.Write Item & ": " & Request.ServerVariables(Item) & "<br>"
Next
%>




<%
If Len(Request.Form) > 0 Then
For Each Item In Request.Form
Response.Write Item & ": " & Request.Form(Item) & "<br>"
Next
End If
%>
<form name="form1" method="post" action="">
<table width="200" border="1" cellspacing="0" cellpadding="2">
<tr>
<td>Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comments"></textarea></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>




<%
If Len(Request.Form) > 0 Then
For Each Item In Request.Form
Response.Write Item & ": " & Request.Form(Item) & "<br>"
Next

myChk = Split(Request.Form("myChk"),",")
For x=0 To Ubound(myChk)
Response.Write myChk(x) & "<br>"
Next
End If
%>
<form name="form1" method="post" action="">
<input type="checkbox" name="myChk" value="1">
<input type="checkbox" name="myChk" value="2">
<input type="checkbox" name="myChk" value="3">
<input type="checkbox" name="myChk" value="4">
<input type="checkbox" name="myChk" value="5">
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

GoComplain
03-01-2006, 03:12 PM
Great examples, I was competely overlooking those array/variables

SpirtOfGrandeur
03-01-2006, 03:30 PM
Or the one Array most people use, and never really notice its an array.

ASP
if Not RST.EOF then
Response.Write("<table><thead><tr>")
For each q in RST.Fields
Response.Write("<td>" & q.name & "</td>")
next
Response.Write("</tr></thead><tbody>")
do while not RST.EOF
Response.Write("<tr>")
For each q in RST.Fields
Response.Write("<td>" & q & "</td>")
next
Response.Write("</tr>")
RST.MoveNext()
loop
Response.Write("</thead></table>")
end if

Baleric
03-01-2006, 08:59 PM
wow thanks for some great examples.
i know alot more know about arrays,
spank you all very much :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum