starcraft Posted August 1, 2003 Posted August 1, 2003 i'm thining of making a command promt type program and i was wondering how do i compair a line the user just entered with a list of commands set into the program? i'd asume is something likeif richtextbox1.line = bob then DO THIS![code=visualbasic] also if i did do that how could i set like a list of commands so i didn't have to set up an if equal for each command, just have like a list and it searchs the list. Quote
Hughng Posted August 1, 2003 Posted August 1, 2003 You can use the equals method in string class to do this. If equals is used, it must be exact case (case sensitive). If you want to create a list of lines that you can compare quick. Use Arraylist class to store your set of lines. Then when user type in something use method contains(String) to search for it. Dim tArray as new ArrayList() ' Add your items here tArray.Add("Your line") tArray.Add("Another line") ' To find that the input line exist in your ArrayList if tArray.contains("User Input") Msgbox("Input exist") else Msgbox("Input not exist") Hope that help. Quote
Leaders dynamic_sysop Posted August 1, 2003 Leaders Posted August 1, 2003 you could always do the following , to find your text in a string / textbox : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strString As String = "some StuFf In DifFeRenT CaSeS !" If Not strString.ToLower.IndexOf("stuff") = -1 Then MessageBox.Show("the word stuff was found in the string at position: " & strString.ToLower.IndexOf("stuff")) End If End Sub you can do the same with TextBox or RichTextBox , eg: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "some StuFf In DifFeRenT CaSeS !" If Not TextBox1.Text.ToLower.IndexOf("stuff") = -1 Then '/// make sure it's there or not. MessageBox.Show("the word stuff was found in the string at position: " & TextBox1.Text.ToLower.IndexOf("stuff")) End If End Sub Quote
BAZRAMIT Posted August 1, 2003 Posted August 1, 2003 Use the Select Case statement Select Case Command.ToUpper 'Or ToLower Case "GET" ' Get something! Case "SET" ' Set something! End Select Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.