Performing Calculations from Arrays

# Thread: Performing Calculations from Arrays

1. Junior Member
Join Date
Dec 1969
Posts
4

## Performing Calculations from Arrays

Below is part of the code I am using to assign and display values in an array:<BR>-------------------------<BR>placedjobs = objRS1.GetRows(1)<BR><BR>RCR = placedjobs(0,0)<BR>For iRowLoop = 0 to UBound(placedjobs, 2)<BR>for iColLoop = 1 to UBound(placedjobs, 1)<BR>Sumplacedjobs = sumplacedjobs + placedjobs(iColLoop, iRowLoop)<BR>next<BR>next<BR><BR><BR>&#039;get placedjobs info %&#062;<BR> &#060;tr bgcolor = "#99CCFF"&#062;<BR> &#060;td width="2.5%" align="left"&#062;<BR> &#060;font face="times" color="#000000" size=3&#062;&#060;b&#062;&#060;%=RCR%&#062;&#060;/b&#062;&#060;/font&#062;<BR> &#060;/td&#062;<BR> &#060;td width="2%" align="right"&#062;<BR> &#060;font face="times" color="#000000" size=3&#062;&#060;b&#062;&#060;%=Sumplacedjobs%&#0 62;&#060;/b&#062;&#060;/font&#062;<BR> &#060;/td&#062;<BR>&#060;% <BR>For iRowLoop = 0 to UBound(placedjobs, 2)<BR> For iColLoop = 1 to UBound(placedjobs, 1)%&#062;<BR> &#060;td width="2%" align="right"&#062;<BR> &#060;font face="times" color="#000000" size=3&#062;&#060;b&#062;&#060;%=placedjobs(iColLo op, iRowLoop)%&#062;&#060;/b&#062;&#060;/font&#062;<BR> &#060;/td&#062;<BR> &#060;% Next &#039;iColLoop%&#062;<BR>&#060;% Next &#039;iRowLoop%&#062;<BR> &#060;/tr&#062;<BR><BR>---------------<BR><BR>But now, I want to perform calculations on this (and other similarly assigned) array(s) as well as write them to a new array. I cannot seem to find any resources that can help me write the correct coding for this.<BR><BR>Does anyone have any suggestions! I am a beginner at ASP and an hitting a wall right now!

2. Senior Member
Join Date
Dec 1969
Posts
723

## RE: Performing Calculations from Arrays

Could you elaborate as to the types of calculations you want to perform. There are many possibilities, so you need to be specific.<BR><BR>The values in your arrays are all strings, even the numbers. So it might be wise to use the type conversion functions when you perform the calculations (CINT, CDbl, CBool,...).<BR><BR>Also, for clarity sake, you should define constant to represent the column header indexes in you array. <BR><BR>For example,<BR><BR>Const cFirtName = 1<BR>Const cLastName = 2<BR><BR>response.write arNames(cFirtName,intRow)<BR>response.write arNames(cLastName,intRow)<BR><BR>where intRow represent the row number in your array, 0-ubound(arNames,2)

3. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Performing Calculations from Arrays

Thanks for responding so quickly...<BR><BR>To answer your first question:<BR>I am doing a few different types of calculations. One of them, I am adding two different arrays together and finding an average (rounding it too)...another one, I&#039;m calculating a ratio between two different arrays. There are others similar to that. In addition, I&#039;d like to write them to a new array so I can display them and perhaps even run calculations off of those later in the code.<BR><BR>As for the values in the arrays, if they are all considered strings, why am I not having a problem adding them together when displaying them. The code below seemed to give me correct data. The only reason it doesn&#039;t work well for me is because I can&#039;t seem to write the result to a new array:<BR><BR>---------------<BR> &#060;% &#039;get total placements info %&#062;<BR> &#060;tr bgcolor = "#99CCCC"&#062;<BR> &#060;td width="2.5%" align="left"&#062;<BR> &#060;font face="times" color="#000000" size=3&#062;&#060;b&#062;Counted Placements&#060;/b&#062;&#060;/font&#062;<BR> &#060;/td&#062;<BR> &#060;td width="2%" align="right"&#062;<BR> &#060;font face="times" color="#000000" size=3&#062;&#060;b&#062;&#060;%=Sumplacedapps + Sumplacedjobs%&#062;&#060;/b&#062;&#060;/font&#062;<BR> &#060;/td&#062;

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## A big fib in there...

It may not matter, but there&#039;s a huge misconception in that post:<BR><BR>&#062; The values in your arrays are all strings, even the numbers.<BR><BR>Not true AT ALL.<BR><BR>I think Moshe may be thinking of Request.Form and its ilk.<BR><BR>When a RecordSet is converted to an array using GetRows, the individual elements of the array have VBS types that follow, in columnar fashion, the best possible conversion from the DB type of that column to a VBS type.<BR><BR>So, if you did<BR><BR>&#060;%<BR>Set RS = conn.Execute("SELECT numField, dateField, textField FROM ...")<BR>rows = RS.GetRows<BR>%&#062;<BR><BR>Then the datatype of *every* <BR>-- rows(0,row) would be vbLong or vbDouble or whatever matched the specific DB number type closest.<BR>-- rows(1,row) would be vbDate<BR>-- rows(2,row) would, indeed, be vbString<BR><BR>

5. Junior Member
Join Date
Dec 1969
Posts
4

## RE: A big fib in there...

Thanks Bill, now do you have any suggestions for the response I had for Moshe? I&#039;m still having a hard time with the calculations.

#### Posting Permissions

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