Reputation: 33
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
Dim s As String
Dim b As String
Dim length As Integer
length = Len(TextBox1.Text)
For x = 1 To length
s = TextBox1.Text
b = s.Remove(0, 1)
a = Asc(b)
TextBox2.Text = a
Next
End Sub
End Class
This is my code. I tried to do a loop so the whole word is translated to ASCII but it still did not work, I am trying to get it so a user enters a word into a text box (textbox1) then if they press button 2, the whole of textbox1 will be converted to ASCII, and displayed in textbox2.
I have looked online but I can not find anything, the current issue I have is that when I press 'convert' only the first letter of the word is converted which is not what I want. This is done in vb 2008, forms. But I have also tried in console with similar code.
All help would be Great.
Upvotes: 1
Views: 432
Reputation: 3424
Try using a loop:
Imports System
Imports Microsoft.VisualBasic
Imports System.Text
Dim input As String = TextBox1.Text
Dim output as new StringBuilder
for each item as string in input.ToCharArray()
output.Append(Asc(item).ToString() + " ")
next
Console.WriteLine(output)
In this case:
Input : Sunil
Output : 83 117 110 105 108
I added that space for clarity, you can change it to anything or remove it.
Upvotes: 3