|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
String Compare
Below I have some code to compare an input time (starttime="13:35") to the records in the SQL database. When I run the code on my site I get this response:
13:05 13:35 1 13:15 13:35 1 13:25 13:35 1 13:35 13:35 -1 13:45 13:35 -1 13:55 13:35 -1 14:05 13:35 -1 14:10 13:35 -1 14:20 13:35 -1 14:30 13:35 -1 14:50 13:35 -1 Why isn't the comparison of 13:35 with 13:35 = 0? While Not objRecSQLDBInfo.EOF test=objRecSQLDBInfo("CCBtime") Response.Write test strtest=strComp(starttime, test, vbTextCompare) Response.Write starttime & " " Response.Write strtest & "<br>" objRecSQLDBInfo.MoveNext Wend |
|
#2
|
|||
|
|||
|
typecast them both to string first, cstr(variable)
|
|
#3
|
|||
|
|||
|
While Not objRecSQLDBInfo.EOF
test=objRecSQLDBInfo("CCBtime") test=cstr(test) starttime=cstr(starttime) Response.Write test strtest=strComp(starttime, test, vbTextCompare) Response.Write starttime & " " Response.Write strtest & "<br>" objRecSQLDBInfo.MoveNext Wend Like this? There's no change in result. |
|
#4
|
|||
|
|||
|
you may have trim the time you are getting from the db to hours and minutes only.
i mean reformat it like timeformat(rs(time),'hh:mm') something like that -------------------------------------------------------------- |
|
#5
|
|||
|
|||
|
well, he isn't trimming the output
13:25 13:35 1 13:35 13:35 -1 so if he's printing out the two and they look like this that shouldn't be the issue.... |
|
#6
|
|||
|
|||
|
Comparing 13:35 to 13:35 should give 0 not -1 right?
|
|
#7
|
|||
|
|||
|
Here's the definition:
StrComp Returns a value indicating the result of a string comparison. Syntax StrComp(string1, string2[, compare]) The StrCompsyntax has these arguments: Part Description string1 Required. Any valid string expression. string2 Required. Any valid string expression. compare Optional. Numeric value indicating the kind of comparison to use when evaluating strings. If omitted, a binary comparison is performed. See Settings section for values. Settings The compare argument can have the following values: Constant Value Description vbBinaryCompare 0 Perform a binary comparison. vbTextCompare 1 Perform a textual comparison. vbDatabaseCompare 2 Not supported. Return Values The StrComphas the following return values: If StrComp returns string1 is less than string2 -1 string1 is equal to string2 0 string1 is greater than string2 1 string1 or string2 is Null Null |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > String Compare |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|