Waseem Shahwan
Waseem Shahwan

Reputation: 178

Conversion from string "" to long is not valid

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

Upvotes: 1

Views: 6045

Answers (1)

Blachshma
Blachshma

Reputation: 17395

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

Upvotes: 1

Related Questions