473,665 Members | 2,827 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 2450

"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
2346
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
4125
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
19
3143
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
28356
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
10339
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
71581
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
3737
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
3105
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
3604
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
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8779
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...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
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.