Hi. I'm making a program somewhat like Siri except through text boxes not voice command. On my form FormMain I have two text boxes named TextBoxInput and TextBoxConversation. I also have two buttons named ButtonStart and ButtonEnd. Here is my entire code for FormMain so far:
Public Class FormMain
Dim yourname As String
Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
TextBoxInput.Enabled = True
Call Conversation()
End Sub
Private Sub ButtonEnd_Click(sender As Object, e As EventArgs) Handles ButtonEnd.Click
TextBoxInput.Enabled = False
End Sub
Sub Conversation()
TextBoxConversation.Text = "Hi! My name is Alex." + vbCrLf + "To end our conversation you may click the ""End Conversation"" button at the bottom of the app at anytime." + vbCrLf + "What is your name?"
yourname = TextBoxInput.Text
TextBoxConversation.Text = TextBoxConversation.Text + vbCrLf + yourname + vbCrLf + "Nice to meet you " + yourname + ". How are you?"
End Sub
End Class
What I need to do is when TextBoxConversation asks for a name, I need it to wait for the enter key to be pressed, and then set yourname equal to TextBoxInput.Text. I tried doing this but it gave me errors in the sub Conversation when I tried to Call the sub FormMain_EnterKeyUp:
Public Class FormMain
Dim yourname As String
Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
TextBoxInput.Enabled = True
Call Conversation()
End Sub
Private Sub ButtonEnd_Click(sender As Object, e As EventArgs) Handles ButtonEnd.Click
TextBoxInput.Enabled = False
End Sub
Sub Conversation()
TextBoxConversation.Text = "Hi! My name is Alex." + vbCrLf + "To end our conversation you may click the ""End Conversation"" button at the bottom of the app at anytime." + vbCrLf + "What is your name?"
Call FormMain_EnterKeyUp() *<--Error was here*
yourname = TextBoxInput.Text
TextBoxConversation.Text = TextBoxConversation.Text + vbCrLf + yourname + vbCrLf + "Nice to meet you " + yourname + ". How are you?"
End Sub
Sub FormMain_EnterKeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
Do Until e.KeyCode = Keys.Enter
Loop
End Sub
I just need to call the sub and make it do nothing until the enter key is pressed, and when it is pressed, I need it to go back to sub Conversation and continue where it left off. And then repeat the call function each time a new question is asked like this:
TextBoxConversation.Text = TextBoxConversation.Text + vbCrLf + "How are you?"
Call Conversation()
yourstatus = TextBoxInput.Text
'React to the user's answer here
Is this possible? Thanks in advance.
-David