Results 1 to 3 of 3

Thread: [02/03] Comparing strings (NEWB ALERT)

  1. #1

    Thread Starter
    Banned
    Join Date
    Sep 2007
    Posts
    11

    Unhappy [02/03] Comparing strings (NEWB ALERT)

    Hey guys, really newbish question here, but this book isnt helping me much in my plight. So, I'm trying to make a program that will help my classmates study their vocab for school (I'm getting extra credit for it! ) and my code does not do what I want it to. I've set it up so that it compares the two strings (The answer, and the input) like so:
    answer = "*Whatever the answer is here, it's randomly generated based on a number, I have like, 125 if/then statements based on random numbers >_>*"
    Code:
    input = Convert.ToString(Me.txtAnswer.Text)
            If answer.ToUpper = input.ToUpper Then
                Points = Points + 1
                Me.picPass.Visible = True
                Me.picFail.Visible = False
            Else
                Points = Points
                Me.picFail.Visible = True
                Me.picPass.Visible = False
            End If
    And this if/then always defaults to the false, because I always see the red checkmark, which indicates a fail. Thanks for your help!
    Last edited by bugmenot; Feb 4th, 2008 at 12:21 AM. Reason: Forgot to format the code as code >_>

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Comparing strings (NEWB ALERT)

    First of all, why do you need to convert a String to a String?
    Code:
    input = Convert.ToString(Me.txtAnswer.Text)
    It doesn't automatically default to False. It compares the two strings and if they are not the same it will show the red check mark. If you see the red check mark then obviously your two strings are not the same. Do you actually know what your two strings contain or are you just assuming? Presumably you are just assuming. You need to actually look at answer.ToUpper and input.ToUpper and see what values they contain. At least one of them will not be what you think itis, otherwise your If block condition would evaluate to True.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Banned
    Join Date
    Sep 2007
    Posts
    11

    Re: [02/03] Comparing strings (NEWB ALERT)

    hehe, yeah, I got kinda frusterated and started just doing unessicary things that I thought could help, I'll get right on to your suggestions though, thanks.

    Yay, it works, I figured out that, once I clicked "Start" the answer and the root variables got out of sync, so every answer I tried was wrong, thanks so much for the debugging trick
    Last edited by bugmenot; Feb 4th, 2008 at 01:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width