Forum Moderators: open

Message Too Old, No Replies

Matching of Strings (no go)

VB Script strings not matching in [Select Case]

         

WeenerDawg

6:22 am on Jun 19, 2007 (gmt 0)

10+ Year Member



I'm going nuts. I have a char(1) value in my database table. The char in itself is meanless to my client, I need to reflect the corresponding realworld 'value' -

To do this I opted to use the VB [Case Select] statement - but for some reason I am unable to match the strings not matter what I do. If I force a varialble (see the commented variable) then the [Case] works. As soon as I replace it with the value extracted from the Database it defaults to the [CASE ELSE] even though there are matching values.

My Code:

___________________________________________________

'*********** FUNCTION:
function getSect( myVAL )

'>>>> IF I UNCOMMENT THIS, IT WORKS
' myVAL = "c"

select case myVAL

case "c"
sectionX = "match c"

case "p"
sectionX = "match p"

.
.
.
.

case else
sectionX = "No Match"

end select

getSect = sectionX

end function

'*********** BODY:

response.write( getSect(rs("charValue")) )

___________________________________________________

.... I'm a PHP coder so I might be missing something - I'm thinking that it might be because the two items being 'matched' aren't of the same type?

makeupalley

7:07 am on Jun 19, 2007 (gmt 0)

10+ Year Member



I think you're probably right,

I'd try this:

Select Case Trim(Cstr(LCase(myVAL)))

This will ensure that there are no trailing/leading spaces attached to your db returned value, that you are comparing apples to apples (or strings to strings) and that the cAsE matches.

Good Luck

WeenerDawg

7:53 am on Jun 19, 2007 (gmt 0)

10+ Year Member



phew... I was about to pull the trigger when I checked my post for one last time :)

Brilliant! My problem has been solved. Thanks for taking the time to help out... You made my day!