VB.NET

Moderators: seancampbell
Number of threads: 4020
Number of posts: 10026

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Im trying to convert numbers to english , Why wont this work ,,, Posted by JabaKaba1988 on 6 Oct 2008 at 1:09 PM
' 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
Report
Re: Im trying to convert numbers to english , Why wont this work ,,, Posted by seancampbell on 6 Oct 2008 at 1:57 PM
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
        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


Hope this helps!!!!
FireSickle.Com
Report
Re: Im trying to convert numbers to english , Why wont this work ,,, Posted by JabaKaba1988 on 6 Oct 2008 at 2:36 PM
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
:
: 
:         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
: 
:
:
: Hope this helps!!!!
: FireSickle.Com
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.