Maximum value in 2 Arrays?

# Thread: Maximum value in 2 Arrays?

1. Junior Member
Join Date
Dec 1969
Posts
28

## Maximum value in 2 Arrays?

I need to find the maximum value from 2 arrays, simple hey....<BR><BR>the code I have is below. a page called arr.asp and the output is below that. anyone got any ideas what I am doing wrong??<BR><BR>arr.asp =<BR>======================================<BR>&#0 60;%@LANGUAGE="VBSCRIPT"%&#062; <BR><BR>&#060;html&#062;<BR>&#060;body bgcolor="#FFFFFF" text="#000000"&#062;<BR>&#060;%<BR>myArray2 = Array("3", "4", "5", "6", "7", "8", "10")<BR>myArray3 = Array("1", "10", "1", "10", "20", "0", "0")<BR>dim max_val<BR>max_val = 0<BR><BR>For i = 0 to UBound(myArray2)<BR> If (max_val &#060; myArray2(i)) Then <BR> max_val = myArray2(i)<BR> End If<BR>Response.Write("max_val = " & max_val & " -- arr 2 = " & myArray2(i) & "<BR>")<BR>Next<BR><BR>For i = 0 to UBound(myArray3)<BR> If (max_val &#060; myArray3(i)) Then <BR> max_val = myArray3(i)<BR> End If<BR>Response.Write("max_val = " & max_val & " -- arr 3 = " & myArray3(i) & "<BR>")<BR>Next<BR>%&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;<BR>=================================<BR >output<BR>max_val = 3 -- arr 2 = 3<BR>max_val = 4 -- arr 2 = 4<BR>max_val = 5 -- arr 2 = 5<BR>max_val = 6 -- arr 2 = 6<BR>max_val = 7 -- arr 2 = 7<BR>max_val = 8 -- arr 2 = 8<BR>max_val = 8 -- arr 2 = 10<BR>max_val = 8 -- arr 3 = 1<BR>max_val = 8 -- arr 3 = 10<BR>max_val = 8 -- arr 3 = 1<BR>max_val = 8 -- arr 3 = 10<BR>max_val = 8 -- arr 3 = 20<BR>max_val = 8 -- arr 3 = 0<BR>max_val = 8 -- arr 3 = 0<BR><BR>why is max_val not increasing after it reaches "8" HELP!!!!!!!!

2. Senior Member
Join Date
Dec 1969
Posts
113

## RE: Maximum value in 2 Arrays?

Strings !!<BR><BR>You are creating your arrays using strings ("1", "2")<BR><BR>Hence "10" is less than "2" so when the script reaches "8", it is at its maximum.<BR><BR>Try array(1, 2, 3, 4,.......) &#039;(no quotes!!!)<BR><BR>Let me know how you get on.<BR><BR>Gorvy

3. Senior Member
Join Date
Dec 1969
Posts
1,913

## Correct ...

You could also use Clng() to turn your strings back into numbers.

4. Junior Member
Join Date
Dec 1969
Posts
28

## RE: Correct ...

well now I&#039;m getting somewhere. stupid of me not to spot it.<BR><BR>My real problem was that I am pulling the arrays from an access db where they are stored as <BR><BR>10, 20, 30, etc<BR><BR>and i define the array using Split()<BR>I have now put in an extra variable as in<BR> this_val = Cdbl(myArray(i))<BR>and then just comapre the this_val with max_val and all is OK<BR><BR>Cheers for all your help.

#### Posting Permissions

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