Conversion from string “” to long is not valid

半世苍凉 提交于 2019-12-31 03:50:47

问题


I'm getting an error which i can't solve, even after about an hour of research.

Conversion from String "Waseem-PC\Waseem" to long is not valid

This error really gets annoying, I tried everything!


I would really appreciate help from you. I would love to give your answers a thumbs up but i have to have a bigger rep.
Here is my code


    Private Sub RichTextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox2.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            RichTextBox1.Text = RichTextBox1.Text And vbNewLine And RichTextBox2.Text
        End If
    End Sub

回答1:


You're incorrectly using the And keyword which is used for (from MSDN):

Perform a logical conjunction on two Boolean expressions, or bitwise conjunction on two numeric expressions.

Instead you want to use & to concatenate the strings...

This will work:

 Private Sub RichTextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox2.KeyPress
    If Asc(e.KeyChar) = Keys.Enter Then
        RichTextBox1.Text = RichTextBox1.Text & vbNewLine & RichTextBox2.Text
    End If
End Sub


来源:https://stackoverflow.com/questions/14726120/conversion-from-string-to-long-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!