Reputation: 21
I'm trying to code a very simple program in vb.net to display the ASCII code for a specific character. I have a form with a textbox, button and a label, to use the input from the textbox to get the ascii for, and then display it in the label.
Here is the code:
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mydata As Char
TextBox1.Text = mydata
Dim toto As Short
toto = Asc(mydata)
Label1.Text = toto
End Sub
End Class
When I click the button I get 0
in the label instead of the correct ASCII, but when I filled the asc()
method with a fixed character it worked fine.
Can you help?
Upvotes: 1
Views: 168
Reputation: 6206
I think this is the wrong way round:
TextBox1.Text = mydata
Should be
mydata = TextBox1.Text
However as Crowcoder has said, remove the use of the variable altogether
You can chop it right down to:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Asc(TextBox1.Text)
End Sub
Upvotes: 0
Reputation: 11514
What is mydata
? I think you want to remove:
TextBox1.Text = mydata
and change toto assignment to:
toto = Asc(TextBox1.Text)
Upvotes: 1