开发者

VB.NET - Weird String Error?

开发者 https://www.devze.com 2022-12-19 00:10 出处:网络
I\'m making a SIMPLE, and when I mean simple, I mean simple. But any way, I have this thing where, the person enters in a word, and it will preview a text file. I have everything setup even the text r

I'm making a SIMPLE, and when I mean simple, I mean simple. But any way, I have this thing where, the person enters in a word, and it will preview a text file. I have everything setup even the text reader, but something unusual I get in my code is the 开发者_StackOverflow社区"if statement". Whenever I type in the word into the textbox, it won't run the thing I want it to, instead it will go directly to the else and display the error message. This is the code I have:

If mainText.Text = "book" Then
        startProcess()

    ElseIf mainText.Text = "greet" Then  //Just there for testing..
        mainText.Text = "Hello there..."
    Else
        mainText.Text = "Please either enter a valid command."
    End If

Now i looked into mainText.text and saw the value when entering the greet command..

{System.Windows.Forms.TextBox, Text: greet" & vbCrLf & "}

.. I don't really understand why this is happening.. All my other program work fine.

Can anyone help me solve this!??!

Thanks,

Kevin


Is the textbox multi-line? A single-line textbox shouldn't allow these characters. Either way, you can probably just trim the string.

Dim command As String = mainText.Text.Trim()
If command = "book" Then
    startProcess()
ElseIf command = "greet" Then  // Just there for testing..
    mainText.Text = "Hello there..."
Else
    mainText.Text = "Please either enter a valid command."
End If


The fact that it works when you break it sounds like a synchronization problem (multithreading) .. could be something connected to the timer you use. Can you provide more information regarding your code/logic?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号