473,848 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ARRAY issues

Hmmm, my array seems to be emptying itself for no reason. I just want to grab every form element posted to the page into an
appropriately sized array... What is going on here?

dim arrShort()
Elements = 0
dim frm
for each frm in Request.Form
Elements = Elements + 1
next

Redim Preserve arrShort(Elemen ts)
xx = 0
for each frm in Request.Form
arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
Response.Write( "** " & arrShort(xx)) ' Works fine
next

' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
for q = 0 to UBound(arrShort )
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
next

Thanks in advance!
Aug 9 '05 #1
19 2458

"MMMMM" <no*****@replyt ogroup.com> wrote in message
news:Og******** ******@TK2MSFTN GP15.phx.gbl...
Hmmm, my array seems to be emptying itself for no reason. I just want to
grab every form element posted to the page into an appropriately sized
array... What is going on here?

dim arrShort()
Elements = 0
dim frm
for each frm in Request.Form
Elements = Elements + 1
next

Redim Preserve arrShort(Elemen ts)
xx = 0
for each frm in Request.Form
arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
Response.Write( "** " & arrShort(xx)) ' Works fine
next

' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
for q = 0 to UBound(arrShort )
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
next

Thanks in advance!

You forgot to increment xx in the for loop.
Aug 9 '05 #2
"Chris Hohmann" <no****@thankyo u.com> wrote in message
news:u9******** ******@TK2MSFTN GP14.phx.gbl...

"MMMMM" <no*****@replyt ogroup.com> wrote in message
news:Og******** ******@TK2MSFTN GP15.phx.gbl...
Hmmm, my array seems to be emptying itself for no reason. I just want to
grab every form element posted to the page into an appropriately sized
array... What is going on here?

dim arrShort()
Elements = 0
dim frm
for each frm in Request.Form
Elements = Elements + 1
next

Redim Preserve arrShort(Elemen ts)
xx = 0
for each frm in Request.Form
arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
Response.Write( "** " & arrShort(xx)) ' Works fine
next

' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
for q = 0 to UBound(arrShort )
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
next

Thanks in advance!

You forgot to increment xx in the for loop.

Also note that when declaring/redeclaring an array, I believe the parameter
in the declaration statement represents the upper bound for the array, not
its size. As such, your array is one element too large. I know, it's not
intuitively obvious, but such is life in a world of zero-based arrays. :)
Aug 9 '05 #3
>> arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
xx will always be 0. You need to increment xx - xx = xx+1
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
What does "Does not work" mean?

Bob Lehmann

"MMMMM" <no*****@replyt ogroup.com> wrote in message
news:Og******** ******@TK2MSFTN GP15.phx.gbl... Hmmm, my array seems to be emptying itself for no reason. I just want to grab every form element posted to the page into an appropriately sized array... What is going on here?

dim arrShort()
Elements = 0
dim frm
for each frm in Request.Form
Elements = Elements + 1
next

Redim Preserve arrShort(Elemen ts)
xx = 0
for each frm in Request.Form
arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
Response.Write( "** " & arrShort(xx)) ' Works fine
next

' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
for q = 0 to UBound(arrShort )
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
next

Thanks in advance!

Aug 9 '05 #4
I am an idiot - An idiot operating on 3 hours of sleep ;-)

Thanks...

"Chris Hohmann" <no****@thankyo u.com> wrote in message news:u9******** ******@TK2MSFTN GP14.phx.gbl...

"MMMMM" <no*****@replyt ogroup.com> wrote in message news:Og******** ******@TK2MSFTN GP15.phx.gbl...
Hmmm, my array seems to be emptying itself for no reason. I just want to grab every form element posted to the page into an
appropriately sized array... What is going on here?

dim arrShort()
Elements = 0
dim frm
for each frm in Request.Form
Elements = Elements + 1
next

Redim Preserve arrShort(Elemen ts)
xx = 0
for each frm in Request.Form
arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
Response.Write( "** " & arrShort(xx)) ' Works fine
next

' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
for q = 0 to UBound(arrShort )
Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
next

Thanks in advance!

You forgot to increment xx in the for loop.

Aug 9 '05 #5
"MMMMM" wrote in message news:Og******** ******@TK2MSFTN GP15.phx.gbl...
: Hmmm, my array seems to be emptying itself for no reason. I just want to
grab every form element posted to the page into an
: appropriately sized array... What is going on here?
:
: dim arrShort()
: Elements = 0
: dim frm
: for each frm in Request.Form
: Elements = Elements + 1
: next
:
: Redim Preserve arrShort(Elemen ts)
: xx = 0
: for each frm in Request.Form
: arrShort(xx) = frm & ": " & request.form(fr m) & "<br>"
: Response.Write( "** " & arrShort(xx)) ' Works fine
: next
:
: ' *** THIS PART BELOW ONLY HAS ONE ELEMENT POPULATED???
: for q = 0 to UBound(arrShort )
: Response.Write( "VERIFY: " & arrShort(q)) ' Does not work for some reason
: next

A little less work:

<%@ Language=VBScri pt %>
<%
Option Explicit
Response.Buffer = True

sub lprt(str)
Response.Write str & "<br />" & vbCrLf
end sub

dim count, method, i, arrShort()
method = Request.ServerV ariables("REQUE ST_METHOD")
if method = "POST" then
count = Request.Form.Co unt
redim preserve arrShort(count - 1)
for i = 1 to count
arrShort(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
lprt "** " & arrShort(i - 1)
next
for i = 0 to ubound(arrShort )
lprt "VERIFY: " & arrShort(i)
next
end if
%>
<html>
<body>
<form action="" method="post">
<input type="text" name="t1" value="" /><br />
<input type="text" name="t2" value="" /><br />
<input type="submit" />
</form>
</body>
</html>

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Aug 10 '05 #6
Roland Hall wrote:
A little less work:

<%@ Language=VBScri pt %>
<%
Option Explicit
Response.Buffer = True

sub lprt(str)
Response.Write str & "<br />" & vbCrLf
end sub

dim count, method, i, arrShort()
method = Request.ServerV ariables("REQUE ST_METHOD")
if method = "POST" then
count = Request.Form.Co unt
redim preserve arrShort(count - 1)
for i = 1 to count
arrShort(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
lprt "** " & arrShort(i - 1)
next
for i = 0 to ubound(arrShort )
lprt "VERIFY: " & arrShort(i)
next
end if


Even less work:

<%@Language=JSc ript%><%

var Elements = []
for (var i=1; i<=Request.Form .Count; i++)
Elements.push(R equest.Form(i). Key + ": " + Request.Form(i) .Item)

%>
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Aug 10 '05 #7
"Dave Anderson" wrote in message
news:eL******** ******@TK2MSFTN GP15.phx.gbl...
: Roland Hall wrote:
: > A little less work:
: >
: > <%@ Language=VBScri pt %>
: > <%
: > Option Explicit
: > Response.Buffer = True
: >
: > sub lprt(str)
: > Response.Write str & "<br />" & vbCrLf
: > end sub
: >
: > dim count, method, i, arrShort()
: > method = Request.ServerV ariables("REQUE ST_METHOD")
: > if method = "POST" then
: > count = Request.Form.Co unt
: > redim preserve arrShort(count - 1)
: > for i = 1 to count
: > arrShort(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
: > lprt "** " & arrShort(i - 1)
: > next
: > for i = 0 to ubound(arrShort )
: > lprt "VERIFY: " & arrShort(i)
: > next
: > end if
:
: Even less work:
:
: <%@Language=JSc ript%><%
:
: var Elements = []
: for (var i=1; i<=Request.Form .Count; i++)
: Elements.push(R equest.Form(i). Key + ": " + Request.Form(i) .Item)
:
: %>

Not much.

You're comparing that to:

dim i : redim preserve Elements(Reques t.Form.Count - 1)
for i = 1 to Request.Form.Co unt
Elements(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
next

....and in another language.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Aug 10 '05 #8
Roland Hall wrote:
Even less work:
...


Not much.

You're comparing that to:

dim i : redim preserve Elements(Reques t.Form.Count - 1)
for i = 1 to Request.Form.Co unt
Elements(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
next

...and in another language.


I am, indeed. And it is certainly less work to push an element onto an array
than to calculate the desired array size, resize that array, and keep track
of the array index (adjusting for the index offset, no less). The JScript
Array happily accepts whatever you give it. Size and index come for free.

[... And now for the BIG ASIDE ...]

In reality, I would not have used the construction in my example, as JScript
is far too interesting to stop there. A "step-through-the-collection"
approach might be:

for (var a=[],E=new Enumerator(Requ est.Form); !E.atEnd(); E.moveNext())
a.push({Name:E. item(),Value:Re quest.Form(E.it em()).Item})

This gives us an array of objects, each with [Name] and [Value] properties.
Now I can do interesting things, such as sort on [Name]:

a.sort(function (x,y){return x.Name<y.Name?-1:x.Name>y.Name ?1:0})

Admittedly, this is of little advantage with a simple, always-available
object like the Request.Form collection. It is considerably more powerful
when used with recordsets, though:

for (var Employees=[]; !RS.EOF; RS.MoveNext()) a.push(
{
ID: RS.Fields("Reco rdID").Value,
Last: RS.Fields("Last Name").Value,
First: RS.Fields("Firs tName").Value,
SSN: RS.Fields("SSN" ).Value,
Phone: RS.Fields("Phon eNumber").Value ,
Address: RS.Fields("Post alAddress").Val ue,
DOB: RS.Fields("Date OfBirth").Value ,
Age: function(){retu rn Math.floor((new Date() - new
Date(this.DOB))/31536000000)}
}
)
RS.Close()

In this case, the array takes the place of a disconnected recordset -- it is
a group of objects with enumerated properties (and methods, if desired!). I
can step forward and backward through it, sort it, insert elements, delete
others -- all without worrying about indices or whether I have the right
kind of cursor.

Best of all, it leads to *sensible* tokens for the HMTL templates:

<td><%=Employee s[i].ID%></td>
<td><%=Employee s[i].Last%></td>
<td><%=Employee s[i].Age()%></td>

Stuff like that.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Aug 10 '05 #9

"Dave Anderson" <GT**********@s pammotel.com> wrote in message
news:u0******** ******@TK2MSFTN GP12.phx.gbl...
: Roland Hall wrote:
: >> Even less work:
: >> ...
: >
: > Not much.
: >
: > You're comparing that to:
: >
: > dim i : redim preserve Elements(Reques t.Form.Count - 1)
: > for i = 1 to Request.Form.Co unt
: > Elements(i - 1) = Request.Form.Ke y(i) & ": " & Request.Form.It em(i)
: > next
: >
: > ...and in another language.
:
: I am, indeed. And it is certainly less work to push an element onto an
array
: than to calculate the desired array size, resize that array, and keep
track
: of the array index (adjusting for the index offset, no less). The JScript
: Array happily accepts whatever you give it. Size and index come for free.

Terrific but the OP is using vbscript. I also could have responded in
Italian but he's using English.

: [... And now for the BIG ASIDE ...]
:
: In reality, I would not have used the construction in my example, as
JScript
: is far too interesting to stop there. A "step-through-the-collection"
: approach might be:
:
: for (var a=[],E=new Enumerator(Requ est.Form); !E.atEnd(); E.moveNext())
: a.push({Name:E. item(),Value:Re quest.Form(E.it em()).Item})
:
: This gives us an array of objects, each with [Name] and [Value]
properties.
: Now I can do interesting things, such as sort on [Name]:

Isn't that called an associative array? In VBScript we use a dictionary.

: a.sort(function (x,y){return x.Name<y.Name?-1:x.Name>y.Name ?1:0})
:
: Admittedly, this is of little advantage with a simple, always-available
: object like the Request.Form collection. It is considerably more powerful
: when used with recordsets, though:
:
: for (var Employees=[]; !RS.EOF; RS.MoveNext()) a.push(
: {
: ID: RS.Fields("Reco rdID").Value,
: Last: RS.Fields("Last Name").Value,
: First: RS.Fields("Firs tName").Value,
: SSN: RS.Fields("SSN" ).Value,
: Phone: RS.Fields("Phon eNumber").Value ,
: Address: RS.Fields("Post alAddress").Val ue,
: DOB: RS.Fields("Date OfBirth").Value ,
: Age: function(){retu rn Math.floor((new Date() - new
: Date(this.DOB))/31536000000)}
: }
: )
: RS.Close()

Why use recordset looping when you can use a 2-dimensional array?

: In this case, the array takes the place of a disconnected recordset -- it
is
: a group of objects with enumerated properties (and methods, if desired!).
I
: can step forward and backward through it, sort it, insert elements, delete
: others -- all without worrying about indices or whether I have the right
: kind of cursor.

I dump my recordset with GetRows into a 2-dimensional array and then close
and destroy the recordset and the connection. I find it to be pretty
powerful.

: Best of all, it leads to *sensible* tokens for the HMTL templates:
:
: <td><%=Employee s[i].ID%></td>
: <td><%=Employee s[i].Last%></td>
: <td><%=Employee s[i].Age()%></td>

I normally don't mix my HTML and server-side script. I usually have just
one opening <% and one closing %> and if I was writing out a table, I would
use GetString.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Aug 11 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2355
by: Hamish Dean | last post by:
Hi. I want to pass an array through a function. how do i do this? eg. void SomeFunction(){ int Array; Array = 1; Array = 2; Array = 3;
19
4169
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
19
3162
by: Tom Jastrzebski | last post by:
Hello, I was just testing VB.Net on Framework.Net 2.0 performance when I run into the this problem. This trivial code attached below executed hundreds, if not thousand times faster in VB 6.0 than in .Net environment, under VS 2005 Beta 2. Does anyone have any idea whether this will be addressed in the final release? Thanks, Tomasz
5
28406
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through each element but I am having issues using redim to adjust the new array. Any help or example code would be greatly appreciated. thanks!
5
10366
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do it somewhere. thanks
8
71620
by: Pim75 | last post by:
Hello, I'm defining a string array like: Dim strArray() As String = {"1", "2"} Can I add some values to this string array later in the code? It's not clear to me how to do this. I hope someone can help me. Thanks in advance!
3
3761
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
One more for today.... As I add more and more lines to my RichTextBox the array that holds its strings gets bigger and bigger and the vertical scroll bar gets smaller and smaller until the string array finally runs out of memory. I'd like to set some line limit and once that limit is reached, start removing the first line each time a new line is appended onto the end. I think this is probably more of an array manipulation question than...
1
3128
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge a,b,c into another array f.. I can do two arrays, but I have issues when trying to do all three and when I do the even/odd compare I only get 2 numbers processed. here is some of the code... //*******************Function...
3
3616
by: =?Utf-8?B?SXpvcmljaA==?= | last post by:
I observed that WCF client running inside Full Trust mode XBAP application can't read byte array over 16384. If return result is bigger than that size, then client simply get null or Nothing in VB and there are no exceptions. I have tried increasing limits on both client and server. Here is a typical entry: <binding name="myBasicHttpBinding" maxBufferSize="2097152" maxBufferPoolSize="8388608" maxReceivedMessageSize="2097152"...
0
9893
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11001
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10664
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.