View Full Version : string == string?


javajom
03-08-2008, 07:33 AM
--------------------------------------------------------------------------------

Hi,
Just a quicky, How do I compare 2 strings? I've just started in VBA and not quite use to the syntax. Here's the code I've done so far and works up to the point where it compares strings.



Public Function fShowMsg()
Dim Pass_Word As String
Dim sh As String
Pass_Word = "jon"
fShowMsg = MsgBox("Do you know the code?", vbYesNo)
If fShowMsg = vbYes Then
sh = InputBox("Enter the Password")
If Pass_Word = st Then
MsgBox ("Hello.")
End If
MsgBox ("Sorry that was incorrect, please contact creator.")
End If
End Function


It's only a rough function at the moment, so probably lots of errors.

RuralGuy
03-08-2008, 08:00 AM
Try:
If Pass_Word = 'st' Then

Brianwarnock
03-08-2008, 08:01 AM
should this
If Pass_Word = st Then
be
If Pass_Word = sh Then

If not where does st come from?

Brian

RuralGuy
03-08-2008, 08:06 AM
Doh! Brian has it! Brain dead me. :(

javajom
03-08-2008, 08:08 AM
Thanks, made that mistake learning java spent hours finding a method name error.
Thanks

Brianwarnock
03-08-2008, 08:09 AM
Brain dead me. :(

That'll be the day, just been reading through another thread you are involved in, you do the hard ones I'll stick to the simple ones. :D

Brian

RuralGuy
03-08-2008, 09:47 AM
Thanks, made that mistake learning java spent hours finding a method name error.
ThanksIf you put Option Explicit at the top of your class module, it will catch these types of errors. It will then insist you define a variable before you use it so it catches typo's.