Reputation:
I'm writing a program that kids can use to code from within my application instead of a console-based approach
So I have a lesson that teaches them about message boxes, they are given a sample line of code and what it creates and are told to create their own by entering code into a textbox to create their own that says "Hey Dude!", the problem is, I'm having trouble getting the system to check if what they entered was correct or not... eg:
Private Sub btnShowMsgBox_Click(sender As Object, e As EventArgs) Handles btnShowMsgBox.Click
If txtUserInput.Text = MessageBox.Show("I can code!") Then
MessageBox.Show("I can code!")
Else
MessageBox.Show("That's not quite right, try again!")
End If
I've tried adding " " around the relevent code on the first line of the if statement but no joy, as well as trying a variable approach
So basically the problem is the program is getting confused and doesn't understand why I'm checking to see if code for a message box is present, the syntax of the messagebox code doesn't fit well either
Does anyone have any suggestions as to how I would get this working? The logic is so straightforward but it's driving me nuts!
Thanks a million in advance
Upvotes: 0
Views: 76
Reputation: 580
I believe you want the code to look more like...
Private Sub btnShowMsgBox_Click(sender As Object, e As EventArgs) Handles btnShowMsgBox.Click
If txtUserInput.Text = "MessageBox.Show(""I can code!"")" Then
MessageBox.Show("I can code!")
Else
MessageBox.Show("That's not quite right, try again!")
End If
The double quotes will return as single quotes within the string between the single quotes.
Upvotes: 1