10 Replies - 582 Views - Last Post: 16 October 2013 - 03:11 PM Rate Topic: -----

#1 kenjiharima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-October 13

Converting a typed number into a number in word form.

Posted 14 October 2013 - 09:27 PM

Ok so to begin I have scoured the forums for related topics, but none come close to helping.
So basically my teacher wants us to make a program that takes user input such as 1 and makes it into "one"
My problem with this lies in once I get into the 10s, 100s, and 1000s I'm not sure how to go about taking the input and assigning each number a word. I'm not allowed to use arrays and such only case, if..then and string search type functions.

So far this is what I have
Option Strict On
Public Class Form1


    Dim num0 As String = "Zero"
    Dim num1 As String = "One"
    Dim num2 As String = "Two"
    Dim num3 As String = "Three"
    Dim num4 As String = "Four"
    Dim num5 As String = "Five"
    Dim num6 As String = "Six"
    Dim num7 As String = "Seven"
    Dim num8 As String = "Eight"
    Dim num9 As String = "Nine"
    Dim num10 As String = "Ten"
    Dim num11 As String = "Eleven"
    Dim num12 As String = "Twelve"
    Dim num13 As String = "Thirteen"
    Dim num14 As String = "Fourteen"
    Dim num15 As String = "Fifteen"
    Dim num16 As String = "Sixteen"
    Dim num17 As String = "Seventeen"
    Dim num18 As String = "Eightteen"
    Dim num19 As String = "Nineteen"
    Dim num20 As String = "Twenty"
    Dim num30 As String = "Thirty"
    Dim num40 As String = "Fourty"
    Dim num50 As String = "Fifty"
    Dim num60 As String = "Sixty"
    Dim num70 As String = "Seventy"
    Dim num80 As String = "Eighty"
    Dim num90 As String = "Ninety"
    Dim numsd As String = ""
    Dim num100 As String = "Hundred"
    Dim num1000 As String = "Thousand"

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim firstAndlastName As String = InputBox("Please enter first and last name:", "Enter Name:", "John Doe")
        
        lblfnameoutput.Text = firstAndlastName.Substring(0, firstAndlastName.IndexOf(" "))
        lbllnameoutput.Text = firstAndlastName.Substring(firstAndlastName.IndexOf(" ") + 1)
        lbldtimeoutput.Text = CStr(Date.Today())

    End Sub

    Private Sub btnenglishconv_Click(sender As Object, e As EventArgs) Handles btnenglishconv.Click
        Dim usernumber As Integer = CInt(txtboxnumbinput.Text)


        If usernumber < 0 Then
            MessageBox.Show("Number must be greater than 0")
        ElseIf usernumber > 3999 Then
            MessageBox.Show("Number must be less than 4000")
        End If
        If usernumber = 0 Then
            lbld.Text = num0
        ElseIf usernumber <= 20 Then
            Select Case usernumber
                Case 1
                    lbld.Text = num1
                Case 2
                    lbld.Text = num2
                Case 3
                    lbld.Text = num3
                Case 4
                    lbld.Text = num4
                Case 5
                    lbld.Text = num5
                Case 6
                    lbld.Text = num6
                Case 7
                    lbld.Text = num7
                Case 8
                    lbld.Text = num8
                Case 9
                    lbld.Text = num9
                Case 10
                    lbld.Text = num10
                Case 11
                    lbld.Text = num11
                Case 12
                    lbld.Text = num12
                Case 13
                    lbld.Text = num13
                Case 14
                    lbld.Text = num14
                Case 15
                    lbld.Text = num15
                Case 16
                    lbld.Text = num16
                Case 17
                    lbld.Text = num17
                Case 18
                    lbld.Text = num18
                Case 19
                    lbld.Text = num19
                Case 20
                    lbld.Text = num20
            End Select
        End If
    End Sub
End Class



I'm curious whether a const would be better to store the variables in or if each number should have its own?
Also if I do a const and do an index to find different numbers and match then up would that be an easier solution?
My main problem is not knowing how to take the usernumber dividing it by a 10,100, or 1000 and getting the number needed from it for each place value. I apologize if I do not come across as clear, but I've been spending hours on something which seems easy, but to me is not.

Is This A Good Question/Topic? 0
  • +

Replies To: Converting a typed number into a number in word form.

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 736
  • View blog
  • Posts: 3,221
  • Joined: 03-December 12

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 08:28 AM

I'm sorry that this is of no help. This assignment seems absolutely asinine. I look at programming in the terms of work smarter not harder and all I can say is you have A LOT of typing to do to create a dictionary that is better suited in something other than multiples of variables. Unless you didn't fully understand the requirements.

Does the input have to come from a text box? If not, use any number of numericupdowns for each placement value, so three updowns for a maximum value of 999. Then you can assign the values to the numbers based on the location of the number provided.

I take it back, while there is a smarter way to do it, it makes you think of a simpler solution still.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 492
  • View blog
  • Posts: 3,271
  • Joined: 12-January 10

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 08:34 AM

so what output is expected if someone enters 100 or 123 for example?
Was This Post Helpful? 0
  • +
  • -

#4 kenjiharima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-October 13

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 08:42 AM

View Postastonecipher, on 15 October 2013 - 08:28 AM, said:

I'm sorry that this is of no help. This assignment seems absolutely asinine. I look at programming in the terms of work smarter not harder and all I can say is you have A LOT of typing to do to create a dictionary that is better suited in something other than multiples of variables. Unless you didn't fully understand the requirements.

Does the input have to come from a text box? If not, use any number of numericupdowns for each placement value, so three updowns for a maximum value of 999. Then you can assign the values to the numbers based on the location of the number provided.

I take it back, while there is a smarter way to do it, it makes you think of a simpler solution still.

Thank you for the response. And yes the input must come from a textbox. I understood the requirements, but his requirements for completing the project are a bit much. If I could I would use an array or even enum, but he wants the class to complete the work with what "he taught us" which is not much.

View PostDarenR, on 15 October 2013 - 08:34 AM, said:

so what output is expected if someone enters 100 or 123 for example?

Either One Hundred or One Hundred Three.
Was This Post Helpful? 0
  • +
  • -

#5 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 492
  • View blog
  • Posts: 3,271
  • Joined: 12-January 10

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 08:54 AM

for hundreds you will have to create a mod thing for it
like
dim result as double
result = your_input  mod 100 // will give you hundreds
                     mod 1000  // thousands
                     mod 10 // tens

ect

you will most likely need a loop go through these






you can also look here for a different method
http://www.vb-helper..._to_words2.html

mod operator
http://msdn.microsof...z(v=vs.90).aspx

This post has been edited by DarenR: 15 October 2013 - 08:55 AM

Was This Post Helpful? 1
  • +
  • -

#6 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 736
  • View blog
  • Posts: 3,221
  • Joined: 03-December 12

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 09:18 AM

Do you have a ceiling or is it infinite?

I am not by my computer to verify but, to give an idea.

Using darenR's input's:



Dim numLength as integer = count(textbox1.text)
Dim onePlace as string
Dim tenPlace as string
Dim hundredPlace as string

OnePlace = textbox1.text.substring(count, 1)

TenPlace = textbox1.text.substring(count -1, 1)

HundredPlace = textbox1.text.substring(count-2, 1)




OnePlace values are "", zero to nine UNLESS tenPlace value equals 1
TenPlace values are "", zero, twenty, thirty, fourth, ect to ninety
Same for hundreds up to as high as needed adding strings to concatenation between the values as needed.

"100" = "One" & " Hundred " trimmed for display = "One Hundred"
"123" = "One" & " Hundred " & "Twenty" & " " & "Three"

The hard part is I don't know what you were taught so I can't say what is wanted and what isn't.

This post has been edited by astonecipher: 15 October 2013 - 09:24 AM

Was This Post Helpful? 1
  • +
  • -

#7 kenjiharima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-October 13

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 12:28 PM

View Postastonecipher, on 15 October 2013 - 09:18 AM, said:

Do you have a ceiling or is it infinite?

I am not by my computer to verify but, to give an idea.

Using darenR's input's:



Dim numLength as integer = count(textbox1.text)
Dim onePlace as string
Dim tenPlace as string
Dim hundredPlace as string

OnePlace = textbox1.text.substring(count, 1)

TenPlace = textbox1.text.substring(count -1, 1)

HundredPlace = textbox1.text.substring(count-2, 1)




OnePlace values are "", zero to nine UNLESS tenPlace value equals 1
TenPlace values are "", zero, twenty, thirty, fourth, ect to ninety
Same for hundreds up to as high as needed adding strings to concatenation between the values as needed.

"100" = "One" & " Hundred " trimmed for display = "One Hundred"
"123" = "One" & " Hundred " & "Twenty" & " " & "Three"

The hard part is I don't know what you were taught so I can't say what is wanted and what isn't.

My ceiling would be around 4000 or so. Not to high ,but annoying to do. I'll try to do what you guys showed me. I wondering about count though.I don't think I can use it, would running it through something like string.length = yada yada be enough?
Was This Post Helpful? 0
  • +
  • -

#8 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 736
  • View blog
  • Posts: 3,221
  • Joined: 03-December 12

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 02:24 PM

Yes length is the correct method, I don't know why I was thinking count.
Was This Post Helpful? 0
  • +
  • -

#9 kenjiharima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-October 13

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 04:01 PM

View Postastonecipher, on 15 October 2013 - 09:18 AM, said:

Do you have a ceiling or is it infinite?

I am not by my computer to verify but, to give an idea.

Using darenR's input's:



Dim numLength as integer = count(textbox1.text)
Dim onePlace as string
Dim tenPlace as string
Dim hundredPlace as string

OnePlace = textbox1.text.substring(count, 1)

TenPlace = textbox1.text.substring(count -1, 1)

HundredPlace = textbox1.text.substring(count-2, 1)




OnePlace values are "", zero to nine UNLESS tenPlace value equals 1
TenPlace values are "", zero, twenty, thirty, fourth, ect to ninety
Same for hundreds up to as high as needed adding strings to concatenation between the values as needed.

"100" = "One" & " Hundred " trimmed for display = "One Hundred"
"123" = "One" & " Hundred " & "Twenty" & " " & "Three"

The hard part is I don't know what you were taught so I can't say what is wanted and what isn't.

Would I be able to run lets say run TenPlace through a case or even an if else list and retrieve the variable I need than go back. And do the onePlace the same way? Afterwards printing the two variables tenplace and oneplace in label text? Thing is I can't really use arrays so my only other way to get the numbers are from the dim statements themselves or from cases already setup. And to make the problem worse I have to have option strict on the whole time.
Was This Post Helpful? 0
  • +
  • -

#10 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 736
  • View blog
  • Posts: 3,221
  • Joined: 03-December 12

Re: Converting a typed number into a number in word form.

Posted 15 October 2013 - 04:06 PM

Option strict is a good thing! You are basically going to do nested case statements throughout check pm for the example.
Was This Post Helpful? 1
  • +
  • -

#11 kenjiharima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-October 13

Re: Converting a typed number into a number in word form.

Posted 16 October 2013 - 03:11 PM

Thanks for the help everyone. I figured out a way to do it without using math, but it just takes longer to write. Ironically it came to me when I least expected it. :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1