How to Convert Numbers into Letters in VB 6 Programming?

Wednesday, July 15, 2009 ·

In this posting I will tell you a simple VB programming tips how to convert numbers from 0 until 20 into letters. To the application you can use either If..Then..Else...End If or Select Case..End Select control structure. In this application just demonstrate how to use both control structures. What is the simple program like? Please look at below simple VB programming tips.

1. Using If..Then..Else..End If control structure

  • Create a VB project for example Project1
  • Create a VB standard form for example Form1
  • Create a command button for example Command1
  • Create another command button for example Command2
  • Create a text box for example Text1
  • Create another text box for example Text2
  • Create a label for example Label1
  • Create another label for example Label2
  • Doubleclick Command1 commandbutton to create a Sub Command1_Click()
  • Write down below simple VB program coding in the Sub Command1_Click() area

    If Val(Text1.Text) = 0 Then
    Label1.Caption = "zero"
    Else
    If Val(Text1.Text) = 1 Then
    Label1.Caption = "one"
    Else
    If Val(Text1.Text) = 2 Then
    Label1.Caption = "two"
    Else
    If Val(Text1.Text) = 3 Then
    Label1.Caption = "three"
    Else
    If Val(Text1.Text) = 4 Then
    Label1.Caption = "four"
    Else
    If Val(Text1.Text) = 5 Then
    Label1.Caption = "five"
    Else
    If Val(Text1.Text) = 6 Then
    Label1.Caption = "six"
    Else
    If Val(Text1.Text) = 7 Then
    Label1.Caption = "seven"
    Else
    If Val(Text1.Text) = 8 Then
    Label1.Caption = "eight"
    Else
    If Val(Text1.Text) = 9 Then
    Label1.Caption = "nine"
    Else
    If Val(Text1.Text) = 10 Then
    Label1.Caption = "ten"
    Else
    If Val(Text1.Text) = 11 Then
    Label1.Caption = "eleven"
    Else
    If Val(Text1.Text) = 12 Then
    Label1.Caption = "twelve"
    Else
    If Val(Text1.Text) = 13 Then
    Label1.Caption = "thirteen"
    Else
    If Val(Text1.Text) = 14 Then
    Label1.Caption = "forteen"
    Else
    If Val(Text1.Text) = 15 Then
    Label1.Caption = "fifteen"
    Else
    If Val(Text1.Text) = 16 Then
    Label1.Caption = "sixteen"
    Else
    If Val(Text1.Text) = 17 Then
    Label1.Caption = "seventeen"
    Else
    If Val(Text1.Text) = 18 Then
    Label1.Caption = "eighteen"
    Else
    If Val(Text1.Text) = 19 Then
    Label1.Caption = "nineteen"
    Else
    If Val(Text1.Text) = 20 Then
    Label1.Caption = "twenty"
    Else
    Label1.Caption = "unrecognize number"
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If


    2. Using select case...end select control structure
  • Doubleclick Command2 command button to create a Sub Command2_Click()
  • Write down below program coding in the Sub Command2_Click() area

    Select Case Val(Text2.Text)
    Case 0
    Label2.Caption = "zero"
    Case 1
    Label2.Caption = "one"
    Case 2
    Label2.Caption = "two"
    Case 3
    Label2.Caption = "three"
    Case 4
    Label2.Caption = "four"
    Case 5
    Label2.Caption = "five"
    Case 6
    Label2.Caption = "six"
    Case 7
    Label2.Caption = "seven"
    Case 8
    Label2.Caption = "eight"
    Case 9
    Label2.Caption = "nine"
    Case 10
    Label2.Caption = "ten"
    Case 11
    Label2.Caption = "eleven"
    Case 12
    Label2.Caption = "twelve"
    Case 13
    Label2.Caption = "thirteen"
    Case 14
    Label2.Caption = "forteen"
    Case 15
    Label2.Caption = "fifteen"
    Case 16
    Label2.Caption = "sixteen"
    Case 17
    Label2.Caption = "seventeen"
    Case 18
    Label2.Caption = "eighteen"
    Case 19
    Label2.Caption = "nineteen"
    Case 20
    Label2.Caption = "twenty"
    Case Else
    Label2.Caption = "unrecognize number"
    End Select


    You can run your program by clicking Start button on your VB toolbar to check whether your program is correct or not.
  • Type a number in Text1 box for example 15
  • Click Command1 commandbutton
  • Type a number in Text2 box for example 15
  • Click Command2 commandbutton
    If letter "fifteen" appears in both Label1 and Label2, it means that your program is correct, and running properly.

    Look at below screen shot for your illustration.
    Sample a Simple VB6 Program Conversion Number to Letter

    What do you think about it? It is an easy simple VB programming tips isn't it? Would you like to try?



  • 4 comments:

    hendra said...
    July 25, 2009 at 7:23 PM  

    tarif iklan barisnya berapa

    Tips Clip said...
    July 26, 2009 at 9:28 AM  

    Untuk saat ini saya kasih harga Rp. 20.000,- per bulan untuk 1 iklan.

    Singnals3 said...
    August 4, 2009 at 7:27 PM  

    Thanks a lot for this posting......

    Get More Details

    Free Clip of Tips said...
    August 4, 2009 at 10:05 PM  

    Hi,
    Thank's a lot for your visiting to my blog.

    Post a Comment