Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Im trying to convert numbers to english , Why wont this work ,,,

JabaKaba1988JabaKaba1988 Posts: 7Member
' When I run the program it returns a 0 in the label ???? Any suggestions


Private Sub btnConverttoEnglish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConverttoEnglish.Click

Dim oneword As Integer
Dim tensword As Integer
Dim hundredsword As Integer
Dim thousandsword As Integer
Dim EnglishResult As String


Select Case thousandsword
Case 1000
EnglishResult = "one Thousand"
Case 2000
EnglishResult = "two Thousand"
Case 3000
EnglishResult = "three Thousand"
End Select

Select Case hundredsword
Case 100
EnglishResult = "one hundred"
Case 200
EnglishResult = "two hundred"
Case 300
EnglishResult = "three hundred"
Case 400
EnglishResult = "four hundred"
Case 500
EnglishResult = "five hundred"
Case 600
EnglishResult = "six hundred"
Case 700
EnglishResult = "seven hundred"
Case 800
EnglishResult = "eight hundred"
Case 900
EnglishResult = "nine hundred"

End Select


Select Case oneword

Case 1
EnglishResult = "One "
Case 2
EnglishResult = "Two "
Case 3
EnglishResult = "Three "
Case 4
EnglishResult = "Four "
Case 5
EnglishResult = "Five "
Case 6
EnglishResult = "Six "
Case 7
EnglishResult = "Seven "
Case 8
EnglishResult = "Eight "
Case 9
EnglishResult = "Nine "
Case 10
EnglishResult = "Ten "
Case 11
EnglishResult = "Eleven "
Case 12
EnglishResult = "Twelve "
Case 13
EnglishResult = "Thirteen "
Case 14
EnglishResult = "Fourteen "
Case 15
EnglishResult = "Fifteen "
Case 16
EnglishResult = "Sixteen "
Case 17
EnglishResult = "Seventeen "
Case 18
EnglishResult = "Eighteen "
Case 19
EnglishResult = "Nineteen "
End Select

Select Case tensword

Case 90 To 99
EnglishResult = "Ninety "
Case 80 To 89
EnglishResult = "Eighty "
Case 70 To 79
EnglishResult = "Seventy "
Case 60 To 69
EnglishResult = "Sixty "
Case 50 To 59
EnglishResult = "Fifty "
Case 40 To 49
EnglishResult = "Forty "
Case 30 To 39
EnglishResult = "Thirty "
Case 20 To 29
EnglishResult = "Twenty "


End Select


EnglishResult = CStr(thousandsword + hundredsword + tensword + oneword)
txtEnterNumber.Text = CStr(EnglishResult)
LblResult.Text = txtEnterNumber.Text


End Sub

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Hi there!!

    I so remember being assigned this in C++ class in highschool... lots of fun. Well it looks like you might be doing something bad in your code.

    Firstly, when you click that button, it dimensions new variables with 0 in them.

    So onesword tensword thousandsword etc are all sitting at 0 when the select cases start to get called. If you have some textboxes with those values in it, make sure you suck the textboxes values back in.

    next, if you do Select thousandsword and thousandsword = 1001, it wont do anything to EnglishResult. Next, if two select statements work, the second one will overwrite the contents of EnglishResult.

    I editted your code to assume only 1 number is entered with a maximum value of 3999 (i base this off of how you wrote your select statements).

    Put this in your button click code
    [code]
    Dim Number As Integer

    'This checks if the number entered is indeed a number
    If IsNumeric(txtEnterNumber.Text) Then
    Number = CInt(txtEnterNumber.Text)
    Else
    MsgBox("Please enter a numeric value into the text entry field") 'inform user bad entry
    txtEnterNumber.Focus() ' set the entry pointer to the txtEnterNumber object
    Exit Sub 'Exit this subroutine so nothing breaks
    End If

    'Math.Floor is a function that rounds a number down
    Dim Thousands As Integer = Math.Floor(Number / 1000) * 1000
    Dim Hundreds As Integer = Math.Floor((Number - Thousands) / 100) * 100
    Dim Tens As Integer = Math.Floor((Number - Hundreds - Thousands) / 10) * 10
    'Mod is an operator that returns the "Remainder" of a given division problem
    'So mod 10 returns the 1's place.
    Dim Ones As Integer = Number Mod 10

    Dim EnglishResult As String = ""

    'Remember the &= operator is the same as saying
    'EnglishResult = EnglishResult & "String"
    'Or
    'EnglishResult = EnglishResult + "String"

    Select Case Thousands
    Case 1000
    EnglishResult &= "One Thousand "
    Case 2000
    EnglishResult &= "Two Thousand "
    Case 3000
    EnglishResult &= "Three Thousand "
    End Select

    Select Case Hundreds
    Case 100
    EnglishResult &= "One Hundred "
    Case 200
    EnglishResult &= "Two Hundred "
    Case 300
    EnglishResult &= "Three Hundred "
    Case 400
    EnglishResult &= "Four Hundred "
    Case 500
    EnglishResult &= "Five Hundred "
    Case 600
    EnglishResult &= "Six Hundred "
    Case 700
    EnglishResult &= "Seven Hundred "
    Case 800
    EnglishResult &= "Eight Hundred "
    Case 900
    EnglishResult &= "Nine Hundred "
    End Select

    Select Case Tens
    Case 90
    EnglishResult &= "Ninety-"
    Case 80
    EnglishResult &= "Eighty-"
    Case 70
    EnglishResult &= "Seventy-"
    Case 60
    EnglishResult &= "Sixty-"
    Case 50
    EnglishResult &= "Fifty-"
    Case 40
    EnglishResult &= "Forty-"
    Case 30
    EnglishResult &= "Thirty-"
    Case 20
    EnglishResult &= "Twenty-"
    End Select

    Select Case Ones
    Case 1
    EnglishResult &= "One "
    Case 2
    EnglishResult &= "Two "
    Case 3
    EnglishResult &= "Three "
    Case 4
    EnglishResult &= "Four "
    Case 5
    EnglishResult &= "Five "
    Case 6
    EnglishResult &= "Six "
    Case 7
    EnglishResult &= "Seven "
    Case 8
    EnglishResult &= "Eight "
    Case 9
    EnglishResult &= "Nine "
    Case 10
    EnglishResult &= "Ten "
    Case 11
    EnglishResult &= "Eleven "
    Case 12
    EnglishResult &= "Twelve "
    Case 13
    EnglishResult &= "Thirteen "
    Case 14
    EnglishResult &= "Fourteen "
    Case 15
    EnglishResult &= "Fifteen "
    Case 16
    EnglishResult &= "Sixteen "
    Case 17
    EnglishResult &= "Seventeen "
    Case 18
    EnglishResult &= "Eighteen "
    Case 19
    EnglishResult &= "Nineteen "
    End Select

    txtEnterNumber.Text = EnglishResult
    lblResult.Text = EnglishResult
    [/code]

    Hope this helps!!!!
    FireSickle.Com
  • JabaKaba1988JabaKaba1988 Posts: 7Member
    Nice work Props
    Yea I'm a newb workin my way up so this helped me alot thankz bro


    Hi there!!
    :
    : I so remember being assigned this in C++ class in highschool... lots
    : of fun. Well it looks like you might be doing something bad in your
    : code.
    :
    : Firstly, when you click that button, it dimensions new variables
    : with 0 in them.
    :
    : So onesword tensword thousandsword etc are all sitting at 0 when the
    : select cases start to get called. If you have some textboxes with
    : those values in it, make sure you suck the textboxes values back in.
    :
    : next, if you do Select thousandsword and thousandsword = 1001, it
    : wont do anything to EnglishResult. Next, if two select statements
    : work, the second one will overwrite the contents of EnglishResult.
    :
    : I editted your code to assume only 1 number is entered with a
    : maximum value of 3999 (i base this off of how you wrote your select
    : statements).
    :
    : Put this in your button click code
    : [code]:
    : Dim Number As Integer
    :
    : 'This checks if the number entered is indeed a number
    : If IsNumeric(txtEnterNumber.Text) Then
    : Number = CInt(txtEnterNumber.Text)
    : Else
    : MsgBox("Please enter a numeric value into the text entry field") 'inform user bad entry
    : txtEnterNumber.Focus() ' set the entry pointer to the txtEnterNumber object
    : Exit Sub 'Exit this subroutine so nothing breaks
    : End If
    :
    : 'Math.Floor is a function that rounds a number down
    : Dim Thousands As Integer = Math.Floor(Number / 1000) * 1000
    : Dim Hundreds As Integer = Math.Floor((Number - Thousands) / 100) * 100
    : Dim Tens As Integer = Math.Floor((Number - Hundreds - Thousands) / 10) * 10
    : 'Mod is an operator that returns the "Remainder" of a given division problem
    : 'So mod 10 returns the 1's place.
    : Dim Ones As Integer = Number Mod 10
    :
    : Dim EnglishResult As String = ""
    :
    : 'Remember the &= operator is the same as saying
    : 'EnglishResult = EnglishResult & "String"
    : 'Or
    : 'EnglishResult = EnglishResult + "String"
    :
    : Select Case Thousands
    : Case 1000
    : EnglishResult &= "One Thousand "
    : Case 2000
    : EnglishResult &= "Two Thousand "
    : Case 3000
    : EnglishResult &= "Three Thousand "
    : End Select
    :
    : Select Case Hundreds
    : Case 100
    : EnglishResult &= "One Hundred "
    : Case 200
    : EnglishResult &= "Two Hundred "
    : Case 300
    : EnglishResult &= "Three Hundred "
    : Case 400
    : EnglishResult &= "Four Hundred "
    : Case 500
    : EnglishResult &= "Five Hundred "
    : Case 600
    : EnglishResult &= "Six Hundred "
    : Case 700
    : EnglishResult &= "Seven Hundred "
    : Case 800
    : EnglishResult &= "Eight Hundred "
    : Case 900
    : EnglishResult &= "Nine Hundred "
    : End Select
    :
    : Select Case Tens
    : Case 90
    : EnglishResult &= "Ninety-"
    : Case 80
    : EnglishResult &= "Eighty-"
    : Case 70
    : EnglishResult &= "Seventy-"
    : Case 60
    : EnglishResult &= "Sixty-"
    : Case 50
    : EnglishResult &= "Fifty-"
    : Case 40
    : EnglishResult &= "Forty-"
    : Case 30
    : EnglishResult &= "Thirty-"
    : Case 20
    : EnglishResult &= "Twenty-"
    : End Select
    :
    : Select Case Ones
    : Case 1
    : EnglishResult &= "One "
    : Case 2
    : EnglishResult &= "Two "
    : Case 3
    : EnglishResult &= "Three "
    : Case 4
    : EnglishResult &= "Four "
    : Case 5
    : EnglishResult &= "Five "
    : Case 6
    : EnglishResult &= "Six "
    : Case 7

    : EnglishResult &= "Seven "
    : Case 8
    : EnglishResult &= "Eight "
    : Case 9
    : EnglishResult &= "Nine "
    : Case 10
    : EnglishResult &= "Ten "
    : Case 11
    : EnglishResult &= "Eleven "
    : Case 12
    : EnglishResult &= "Twelve "
    : Case 13
    : EnglishResult &= "Thirteen "
    : Case 14
    : EnglishResult &= "Fourteen "
    : Case 15
    : EnglishResult &= "Fifteen "
    : Case 16
    : EnglishResult &= "Sixteen "
    : Case 17
    : EnglishResult &= "Seventeen "
    : Case 18
    : EnglishResult &= "Eighteen "
    : Case 19
    : EnglishResult &= "Nineteen "
    : End Select
    :
    : txtEnterNumber.Text = EnglishResult
    : lblResult.Text = EnglishResult
    : [/code]:
    :
    : Hope this helps!!!!
    : FireSickle.Com
    :

Sign In or Register to comment.