compare string

koure

Active member
Joined
Sep 23, 2008
Messages
27
Programming Experience
Beginner
Hi

I'm newbie to vb.net. Im using vb.net 2005

I want to evaluate if a string is equal to another one but it does not seem to work:

Dim sName as string = "Jack"

if sName = "Jack" then
Msgbox("Jack")
else
Msgbox("Not Jack")
end if

In the above code the if condition is not working and instead of getting a mesage box with Jack I get the second msgbox Not Jack

I have tried sName.equals as well but the same problem

Does anyone can help me

Thanks in advance
 
At the very top of the code window put this line in "Option Compare Text" then try running the code.
 
Hi

thanks. It worked perfectly

can you please tell me what was the problem and what "Option Compare Text" does

Thanks again
 
It tells the compiler (for that class/module) to compile it using Text comparison instead of Binary. I'm willing to bet that in the project properties the 'Option Compare' field is set to Binary which will compile everything to do binary comparison other than the one class that you tell it otherwise.
 
Yes it was set to binary. I changed it and remove the code but again it doesnt work without the code snippet u sent me
 
Yes it was set to binary. I changed it and remove the code but again it doesnt work without the code snippet u sent me
If you change it in the project properties, try saving it then rebuild it and it should work from there, if that still doesn't work then I'm wiling to bet that you've got some compile errors and you're actually running the last successful compile file.
 
Back
Top