CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2019
    Posts
    2

    Run time error with string, Windows Form App.Net

    Hi! I have created an application where the user inserts their name and an option of a compliment, motivation, greeting, joke, or fun fact. Once clicked, then a new form pops up with the message "Hello[Insert Name], [Insert option here]. I have created this using an if/then branch statement, and I have declared my lblResult, which is where I want the message to appear, as a string. I have been having a runtime error that says I have an unhandled exception and that my string is in the wrong format. I do not know where to go from this point, so any help will be greatly appreciated. Thanks in advance.

    Code:
     
      Dim strName As String
            strName = "Hello" & txtName.Text
            Dim strResult As String
    
            If radCompliment.Checked = True Then
                strResult = strName And "You are FABULOUS"
    
            Else
                MessageBox.Show("Please input information")
    
            End If
            If radMotivation.Checked = True Then
    
                strResult = strName And "Stay focused and never give up!"
            Else
                    MessageBox.Show("Please put in information")
                End If
            If radGreeting.Checked = True Then
                strResult = strName And "How are you today? :)"
            Else
                MessageBox.Show("Please put in information")
            End If
    
            If radJoke.Checked = True Then
                strResult = strName And "What did the computer do at lunch time? Had a byte!"
            Else
                    MessageBox.Show("Please put in information")
                End If
            If radFact.Checked = True Then
                strResult = strName And "Did you know that Banannas are curved because when they grow they gravitate towards the sun."
            Else
                    MessageBox.Show("Please put in information")
                End If
    Last edited by 2kaud; April 24th, 2019 at 03:26 AM. Reason: Added code tags

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Run time error with string, Windows Form App.Net

    From the looks of it you need to replace all of those And with &

    Like so
    Code:
    strResult = strName & "What did the computer do at lunch time? Had a byte!"
    And is a logical operator & is used to combine strings.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Apr 2019
    Posts
    2

    Re: Run time error with string, Windows Form App.Net

    Thankyou, that fixed it!

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

Featured