I’m trying to create a textbox, where the user enters a number, and the output shows a word representing each digit, each word is in an individual label created by the code, regardless of how many digits are entered.
So if the user enters 153, the output will be:
I’m not sure how to break the input apart to separate each digit and create a label accordingly to the number of digits entered (e.g. if 3 digit number, create 3 labels). I know that after breaking the input apart, run those separated digits through case select, and then assign the output to a new label. I was able to find how to create a label, but I'm not sure how to add more than one label and move the label down, if more than one digit is entered, because "MyLinkLabel.Location = (10, -10)" will not work to move the label vertically down by 10 pixels.
The code below adds a single label to the form.

Dim MyLinkLabel As New Label()
   With MyLinkLabel
      .Location = New Point(10, 10)
      .Visible = True
      .AutoSize = True
   End With
MyLinkLabel.Text = "one"

Recommended Answers

All 14 Replies

i think you must create a label array..

Use one Label and concatenate your digit strings like so:
MyLabel.Text = "one" + vbCr + "five" +vbCr +"two"

Create an array like so:

dim NumberToText as String = new String() {"zero", "one", "two", & _
"three", "four", "five", "six","seven", "eight", "nine"}

Then parse through your input one character at a time. Each character will be a number whose value corresponds to the index in the array where the conversion to string is stored:

Sub ShowAsString (byref InputText as String)
dim i as integer
dim sChar as string

for i = 0 to len(InputText)
    sChar = mid(InputText,i,1)
    If Not IsNumeric(sChar) then
        Messagebox.Show("Non Numeric Text entered")
        Exit Sub
        'we know that we have a number and the string of that 
        ' number is in the array I assume you wish a line per number...
        MyOutPutLabel.Text  + =  NumbersToText(cint(sChar)) &vbcrlf
    end if
end sub
commented: Nice code. +15

My 2 last posts didn't display so I try again. Just insrt my code into a new project and play around with the labels.

Imports System.Drawing.Color
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim testStr As String = TextBox1.Text
        Dim st As String
        Dim po As Integer = 10
        For i = 0 To testStr.Length - 1
            st = CStr(GetRootNumberWord((CInt(Val(testStr(i))))))
            Dim lbl As New Label
            lbl.Text = st
            lbl.BackColor = Aqua
            lbl.Location = CType(New System.Drawing.Size(po + i, 30 * i), Point) 'position of label
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    End Sub
    Public Enum RootNumbers
    End Enum
    Public Shared Function GetRootNumberWord(ByVal number As Integer) As String
        Return [Enum].GetName(GetType(RootNumbers), number)
    End Function
End Class

Thanks Minimalist. So if I decides to change the input, how would I delete the previous labels and create new ones for the new input?

For i As Integer = Me.Controls.Count - 1 To 0 Step -1
    If TypeOf Me.Controls(i) Is Label Then
    End If

I can't figure out how to move the labels.
So now the labels are printed out vertically, how would I change the line

lbl.Location = CType(New System.Drawing.Size(po + i, 30 * i), Point) 'position of label

to move the label horizontally. (e.g. input 152, output one five two).
And also, in the RootNumbers, is it possible to have more than one word on one line. For example, instead of "zero", have "zero 0"? Because I tried to do that, and it expects an "end of statement expected".

OK, so I figured out that

lbl.Location = CType(New System.Drawing.Size((po * i), 0 * i), Point) 'position of label

will add the next label horizantally, but the first label is being added in the location (0,0). I want the first label to start at the location (12, 36), but I don't know where to set the initial location of the first label.

I also tried adding a panel, and make the labels add to the panel, that way I could place the panel anywhere I want, and the labels will add in the location fo the panel, but I also was wondering if there is a code approach.

Just put an
if i= 0 then
put label location for the first label
end if

Minimalist, what about

in the RootNumbers, is it possible to have more than one word on one line. For example, instead of "zero", have "zero 0"? Because I tried to do that, and it expects an "end of statement expected".

look at line 14, put an if statement in and lbl.Text = st & " 0".
Don't forget to mark the thread as solved. Thanks

I can't figure out how to set if statement. I tried:

If TextBox1.Text.Contains(0) Then
   lbl.Text = st & " 0"
End If

If TextBox1.Text.Contains(1) Then
   lbl.Text = st & " 1"
End If

But this didn't work. What am I doing worng? I need the output for the input of "01" to be zero 0 one 1

I removed the line

lbl.Text = st

so this got to work, but not properly.
If I enter 111, the output is one 1 one 1 one 1
If I enter 000, the output is zero 0 zero 0 zero 0
But If I enter 011, the output is zero 1 one 1 one 1
And If I enter 100, the output is one 1 zero 1 zero 1
What is not right here?

Replace line 14 with all of the following code:

 If st = "zero" Then
                lbl.Text = st & "  0"
                If st = "one" Then
                    lbl.Text = st & " 1"
                    lbl.Text = st
                End If
            End If

Thank you very much for your help. This is my final result of the program: (See attachment)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.