dafuq is wrong with this??

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Reaction score
13
Doing my first Classic ASP page in a while

I have an array that stores a value, like "FEL", I have a record from a db that contains the same value, I then do this

Code:
if Trim(rs("Description")) = Trim(myArray(0,i)) Then

The output shows FEL on both the array AND the recordset, I even compared the length (both = 3)

But for some reason the above is NEVER equal to each other according to that if statement

WTF. Did I lose my ability to code in something AS SIMPLE AS classic ASP!?
 
Use StrComp(string1, string2, comparetype ) instead?
 
Okay, I know this might seem stupid but bear with me: have you tried hard-coding the expected value at either side? At least that way you can figure out which end is to blame for the statement failing.
 
Okay, I know this might seem stupid but bear with me: have you tried hard-coding the expected value at either side? At least that way you can figure out which end is to blame for the statement failing.

Not a stupid idea, let me try that quick
 
Didn't want to post the code, cause I want to figure this out, but here's the code:

Code:
Do While NOT rs.EOF

For  i = 0 to UBound(myArray,2) 'loop through all our items in the array to see if it exists yet
	if Trim(rs("Description")) = Trim(myArray(0,i)), 0) Then 'Found the description in the array already, lets update it instead
		if CInt(rs("CompletedOnTime")) = 1 Then
			myArray(1,i) = (myArray(1,i) + 1) 'Completed, so let's add it
		end if
		myArray(2,i) = (myArray(2,i) + 1) 'Overall Count
	Else 'Doesnt exists, insert into array		

ReDim Preserve myArray(2,intSizeOfArray) 'lets change the size of our array to accommodate more

myArray(0,intSizeOfArray) = Trim(rs("description"))
myArray(1,intSizeOfArray) = 1
myArray(2,intSizeOfArray) = 1

intSizeOfArray = intSizeOfArray + 1

		Exit For 'We exit the loop immediately when we find this, we entered the record successfully to the array and need to move to the next db record
	End If
Next


rs.MoveNext
Loop
 
This gives me the same result as a direct compare (string1 = string2), ie, it doesn't match up even if FEL = FEL



Looks like it's on the array's side

I assume you're comparing appropriate datatypes and whatnot? Can we see your array declaration?
 
Last edited:
ReDim myArray(2,0)

Basically it keeps 3 types of values, description/amount completed on time and number of tickets

And yes, I've CStr() both of them still didn't work and I can confirm both of them are the same datatypes (varchar in the db/string when read out)
 
Ummm I think you swapped your array indexes maybe?

ReDim myArray(2,0):
[0 0 0]

vs

myArray(0,i):
[0
0
0]


Haven't looked at VB in literally years so I may be wrong with that logic, just had a quick Google.
 
Didn't want to post the code, cause I want to figure this out, but here's the code:

Code:
Do While NOT rs.EOF

For  i = 0 to UBound(myArray,2) 'loop through all our items in the array to see if it exists yet
	if Trim(rs("Description")) = Trim(myArray(0,i)), 0) Then 'Found the description in the array already, lets update it instead
		if CInt(rs("CompletedOnTime")) = 1 Then
			myArray(1,i) = (myArray(1,i) + 1) 'Completed, so let's add it
		end if
		myArray(2,i) = (myArray(2,i) + 1) 'Overall Count
	Else 'Doesnt exists, insert into array		

ReDim Preserve myArray(2,intSizeOfArray) 'lets change the size of our array to accommodate more

myArray(0,intSizeOfArray) = Trim(rs("description"))
myArray(1,intSizeOfArray) = 1
myArray(2,intSizeOfArray) = 1

intSizeOfArray = intSizeOfArray + 1

		Exit For 'We exit the loop immediately when we find this, we entered the record successfully to the array and need to move to the next db record
	End If
Next


rs.MoveNext
Loop

this line :

if Trim(rs("Description")) = Trim(myArray(0,i)), 0)

does not compile. Think that is the problem. The code work and return the correct result if you take away the ,0) at the end.

How did you compile it?
 
this line :

if Trim(rs("Description")) = Trim(myArray(0,i)), 0)

does not compile. Think that is the problem. The code work and return the correct result if you take away the ,0) at the end.

How did you compile it?

That's a typo sorry, I was removing some of my earlier attempts (StrComp() suggestion above)

If you remove ,0) then it should work


Ummm I think you swapped your array indexes maybe?

ReDim myArray(2,0):
[0 0 0]

vs

myArray(0,i):
[0
0
0]


Haven't looked at VB in literally years so I may be wrong with that logic, just had a quick Google.

Nope, I've tested it and it works perfectly. Sure I can do it the other way around, but I just use UBound(myArray,2) to make it swap rows/columns.

Basically looks like this:

array["column1"][0]
array["column2"][0]
array["column3"][0]
array["column1"][1]
array["column2"][1]
array["column3"][1]
array["column1"][2]
array["column2"][2]
array["column3"][2]
etc

Wish this was PHP, wouldn't have had an issue...
 
Top
Sign up to the MyBroadband newsletter
X