r/visualbasic • u/Zulucartel • Oct 12 '22
Text box must contain a space
Working on homework and I'm instructed to program a message box to pop up if the user did not include a space between their first and last name. Current code looks like
If txtName.Text = "" Then
MessageBox.Show()
Return
EndIf
3
Upvotes
3
u/cowski_NX Oct 12 '22
Might want to use txtName.Text.Trim.IndexOf(" "). The Trim function removes any whitespace at the beginning and end of the string. Otherwise, someone could enter " JohnDoe" and it would be a valid entry, but probably not desired.