Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: arrays

  1. #1
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts

    arrays

    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

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See :: http://www.w3schools.com/vbscript/vb..._variables.asp :: here for a wee example and example.

  • #3
    New Coder
    Join Date
    Apr 2004
    Location
    Columbus, Ohio
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 """>"
    Hate something?
    Tell us about it
    Go Complain

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's also useful to know that Request collections are submitted in arrays and some form variables are submitted in arrays.

    e.g.
    Code:
    <%
    For Each Item In Request.ServerVariables
    	Response.Write Item & ": " & Request.ServerVariables(Item) & "<br>"
    Next
    %>
    Code:
    <%
    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>
    Code:
    <%
    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>

  • #5
    New Coder
    Join Date
    Apr 2004
    Location
    Columbus, Ohio
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great examples, I was competely overlooking those array/variables
    Hate something?
    Tell us about it
    Go Complain

  • #6
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or the one Array most people use, and never really notice its an array.

    ASP
    Code:
    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
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #7
    Regular Coder Baleric's Avatar
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    332
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow thanks for some great examples.
    i know alot more know about arrays,
    spank you all very much


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •