Alphanumeric number.

skawt

Member
Joined
Nov 25, 2010
Messages
8
Programming Experience
Beginner
Hi guys, I'm a beginner in vb.net.

I just want to ask the ways on how to convert alphanumeric data from textbox?

TIA
 
What exactly would you convert it to? If it's aplhanumeric then your only real option is a String and the Text of a TextBox is already a String, so there's no conversion necessary. I don't think you've actually provided us all the information, so there's not much more we can tell you. If you don't give us the full story, we can't give you a full answer.
 
Hmmm... I must have missed the bit where you mentioned phone numbers in your first post. Oh, hang on, you didn't mention phone numbers. We can't read minds so you have to provide us with ALL the relevant information when asking a question.

I would suggest that you first convert the String into a Char array, using String.ToCharArray. You can then use a For loop to access each Char. You can use Char.IsLetter to determine if the character is a letter and, if it is, convert it to the corresponding digit and put that into the array instead. At the end, you can create a new String by passing the Char array to the String constructor. As for the conversion itself, I'd suggest just using a Select Case statement.

See what you can do with those instructions and post back if you get stuck on something specific.
 
Sorry for that sir.

On what I did on the code, I add 0 - 9 buttons and put string value each one of them to appear on the textbox.

Ex. TextBox2.Text = TextBox2.Text & "0"

And if i press the "Execute" button, it should convert the 7 numbers to letters.

and vice versa. ( If the user wants to display 7 characters to numeric)

And then it would be validated from the database if that number is already taken by other person.


TIA
 
Last edited:
pahabol:

Sir i tried this code in my button to see if it will display "a" if i press the button once, "b" if i press it twice and "c" if thrice" but it display the whole string not as char.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim zero As String = " a b c "
Dim chararr1() As Char = zero.ToCharArray()
For i As Integer = 0 To zero.Length - 1
TextBox1.Text = TextBox1.Text & chararr1(i)
Next
End Sub
 
A simple form with two text boxes and one button.
I didn't rename any of the controls

hasjdhakshkjsahkdhaksha.png


This code is added to button1 :) and then it will work
Explanations inside the code.
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'clears textbox2, just in case you want to do this multiple times.
        TextBox2.Text = ""

        'an array that will split into 8 different strings (first string = abcABC, second = DEFdef, and so on..)
        Dim string1() As String = "abcABC DEFdef GHIghi JKLjkl MNOmno PQRSpqrs TUVtuv WXYZwxyz".Split(" ")

        'a simple string that is used to see whether the character in the number needs to be converted, all characters in this string are left untouched
        Dim string2 As String = "0123456789-"

        ' an array that will be used to replace the characters from string1()
        Dim string3() As String = "2 3 4 5 6 7 8 9".Split(" ")

        'this is the process that will convert the number. It will loop trough every character in textbox1 and replace some if necessary.
        For i = 0 To TextBox1.Text.Length - 1
            'this check whether the current character in the textbox that the loop is checking, is in string2. If it is in string2, then it will be added to textbox2 without changes
            If InStr(string2, TextBox1.Text.Substring(i, 1)) > 0 Then
                TextBox2.Text = TextBox2.Text + TextBox1.Text.Substring(i, 1)
            Else
                'this loop checks trough string1(), in case a character wasn't found in string2.
                ' the loop will then find the corresponding string of the character found from string1(), from string3(), and put that character (a number) to textbox2.
                Dim j As Integer = 0
                Do Until InStr(string1(j), TextBox1.Text.Substring(i, 1)) > 0
'same thing as if you would write j = j+1, it basically adds 1 to j for every loop
                    j += 1
                Loop
                TextBox2.Text = TextBox2.Text + string3(j)
            End If
        Next

    End Sub

Note, this program will return error if you insert unidentified characters such as : or ? for example.

Hope that made things a little bit clearer
I'm a new member here myself, and my knowledge of Vb.net is very limited. I hope to learn a lot from the pro:s around here :)
 
Sir Calley, a BIG thank you for you.

But is it okay if you explain the code on abc = 2, efg = 3... like if i enter abc in TextBox1.Text it would appear 222 on TextBox2.Text.

Sorry, I'm really a beginner.

TIA
 
up.

I'm done with alpha phrase to numeric.

Now i'm working with numeric to alpha phrase.

Now, this one is the harder. I'm stuck on how to come up with a specific alpha value if the the user inputs a numeric value.

Ex. if the user input is 2 in TextBox1.Text then it should give me "a", not "abc".
 
Back
Top