-
April 23rd, 2019, 04:00 PM
#1
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
-
April 23rd, 2019, 05:10 PM
#2
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.
-
April 23rd, 2019, 05:19 PM
#3
Re: Run time error with string, Windows Form App.Net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|