Results 1 to 16 of 16

Thread: pls help me!im begging you

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    85

    pls help me!im begging you

    this program is in CONSOLE OF VB.NET PLS CONVERT IT TO WINDOW APPLICATIO PLS


    Module m1

    Sub Main()

    Dim n, libo, daan, pagitanngsampu, isa, sampu, lolipop As Integer
    Dim layas As String = ""
    Dim unangletra As Char
    Dim tali As String
    Console.WriteLine("")
    Console.WriteLine(" convert number in words ")
    Console.Write("---------------------------------------------------- ")

    Console.Write("Enter a number from 1 to 9999: ")

    n = Console.ReadLine()
    If n > 9999 Then
    Console.Write("Number exceeds maximum recommended input.")
    Else


    libo = n \ 1000
    n = n Mod 1000

    daan = n \ 100
    n = n Mod 100

    If n >= 11 AndAlso n <= 19 Then
    pagitanngsampu = n Mod 10
    Else
    sampu = n \ 10
    n = n Mod 10
    isa = n
    End If
    End If

    If libo = 1 Then

    layas = layas + "one thousand "

    ElseIf libo = 2 Then

    layas = layas + "two thousand "

    ElseIf libo = 3 Then
    layas = layas + "three thousand "

    ElseIf libo = 4 Then
    layas = layas + "four thousand "

    ElseIf libo = 5 Then
    layas = layas + "five thousand "

    ElseIf libo = 6 Then
    layas = layas + "six thousand "

    ElseIf libo = 7 Then
    layas = layas + "seven thousand "

    ElseIf libo = 8 Then
    layas = layas + "eight thousand "

    ElseIf libo = 9 Then
    layas = layas + "nine thousand "

    End If


    If daan = 1 Then
    layas = layas + "one hundred "

    ElseIf daan = 2 Then
    layas = layas + "two hundred "

    ElseIf daan = 3 Then
    layas = layas + "three hundred "

    ElseIf daan = 4 Then
    layas = layas + "four hundred "

    ElseIf daan = 5 Then
    layas = layas + "five hundred "

    ElseIf daan = 6 Then
    layas = layas + "six hundred "

    ElseIf daan = 7 Then
    layas = layas + "seven hundred "

    ElseIf daan = 8 Then
    layas = layas + "eight hundred "

    ElseIf daan = 9 Then
    layas = layas + "nine hundred "
    End If


    If pagitanngsampu = 1 Then

    layas = layas + "eleven "

    ElseIf pagitanngsampu = 2 Then
    layas = layas + "twelve "

    ElseIf pagitanngsampu = 3 Then
    layas = layas + "thirteen "

    ElseIf pagitanngsampu = 4 Then
    layas = layas + "fourteen "

    ElseIf pagitanngsampu = 5 Then
    layas = layas + "fifteen "

    ElseIf pagitanngsampu = 6 Then
    layas = layas + "sixteen "

    ElseIf pagitanngsampu = 7 Then
    layas = layas + "seventeen "

    ElseIf pagitanngsampu = 8 Then
    layas = layas + "eighteen "

    ElseIf pagitanngsampu = 9 Then
    layas = layas + "nineteen "

    End If

    If sampu = 1 Then

    layas = layas + "ten "

    ElseIf sampu = 2 Then

    layas = layas + "twenty "

    ElseIf sampu = 3 Then
    layas = layas + "thirty "

    ElseIf sampu = 4 Then
    layas = layas + "fourty "

    ElseIf sampu = 5 Then
    layas = layas + "fifty "

    ElseIf sampu = 6 Then
    layas = layas + "sixty "

    ElseIf sampu = 7 Then
    layas = layas + "seventy "

    ElseIf sampu = 8 Then
    layas = layas + "eighty "

    ElseIf sampu = 9 Then
    layas = layas + "ninety "

    End If


    If isa = 1 Then
    layas = layas + "one "

    ElseIf isa = 2 Then
    layas = layas + "two "

    ElseIf isa = 3 Then
    layas = layas + "three "

    ElseIf isa = 4 Then
    layas = layas + "four "

    ElseIf isa = 5 Then
    layas = layas + "five "

    ElseIf isa = 6 Then
    layas = layas + "six "

    ElseIf isa = 7 Then
    layas = layas + "seven "

    ElseIf isa = 8 Then
    layas = layas + "eight "

    ElseIf isa = 9 Then
    layas = layas + "nine "

    End If

    lolipop = Len(layas)
    unangletra = UCase(Left(layas, 1))
    tali = Mid(layas, 2, lolipop)
    Console.Write("")
    Console.Write("{0}{1}", unangletra, tali)
    Console.ReadLine()
    End Sub


    End Module

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: pls help me!im begging you

    Have you try to do it yourself?

    Just two hints, you can replace the console.write/writeline by messagebox's, and the Console.read/readline by inputbox's...

    That's a quicky/dirty way to do the job.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: pls help me!im begging you

    I don't think that is a conversion that anybody can do for you, as it is where all the style comes into a program. I would suggest that you start a new project as a Windows Forms Application. You will be able to copy over all the code you currently have, but that would probably be easier than trying to add the right references, and the right items, to convert the existing program.

    In the Windows Forms Application, you will have one form to start with. Decide what controls you want to put on the form. How will you display the current output? It could either be in one or more labels, or in a textbox, or even a listbox. It looks like you are accepting user entry, so probably a textbox to accept that. Then the bulk of the work has to happen at some point. The typical point is to add a button to the form, and when the user clicks the button, then you check to see that the textbox has useable information in it, then process the information.

    Where you put the controls, and how you lay out the design, is entirely up to you, as it should be.
    My usual boring signature: Nothing

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: pls help me!im begging you

    There are many things you need to consider while converting console application to windows application. Where do u get the input from? Where do you write any output to? etc.

    As a first step, try the following things:
    1. Start a new windows application project.
    2. Form1 would be there by default. Add 2 textboxes and a button to it.
    3. Copy and paste that code to button click event. (copy whatever is between Sub Main...End Sub)
    4. Replace all Console.ReadLine() with TextBox1.Text
    5. Replace all Console.Write with TextBox2.AppendText
    6. Run the application and see if it works.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    85

    Re: pls help me!im begging you

    im having problem in this one


    lolipop = Len(layas)
    unangletra = UCase(Left(layas, 1))
    tali = Mid(layas, 2, lolipop)
    Console.Write("")
    Console.Write("{0}{1}", unangletra, tali)
    Console.ReadLine()


    .......i tried a lot but i didnt get it pls help

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: pls help me!im begging you

    If you're refering to this line:
    Code:
    Console.Write("{0}{1}", unangletra, tali)
    It formats the string, then prints it in the console. If you'd like to display the same text in a messagebox you'd do:
    Code:
    MessageBox.Show(String.Format("{0}{1}", unangletra, tali))
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    85

    Re: pls help me!im begging you

    the word LEFT IS THE ERROR

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: pls help me!im begging you

    Quote Originally Posted by izorcism View Post
    im having problem in this one


    lolipop = Len(layas)
    unangletra = UCase(Left(layas, 1))
    tali = Mid(layas, 2, lolipop)
    Console.Write("")
    Console.Write("{0}{1}", unangletra, tali)
    Console.ReadLine()


    .......i tried a lot but i didnt get it pls help
    That part would be replaced like this. (you can omit empty strings)
    Code:
            lolipop = Len(layas)
            unangletra = UCase(Strings.Left(layas, 1))
            tali = Mid(layas, 2, lolipop)
            TextBox2.AppendText(unangletra & tali)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: pls help me!im begging you

    Well if you had told us that right away and not leaving things for us to guess you'd save us some work would you not?

    You are using an awful lot of VB6 legacy methods. You should switch to the corresponding .NET ones:
    Left - String.Substring
    UCase - String.ToUpper
    Len - String.Length
    Mid - String.Substring

    All these methods are non-shared members of the string class, so you'd call them on your string objects.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    85

    Re: pls help me!im begging you

    THIS IS MY NEW CODE IN WINDOW APPLICATION UNFORTUNATELY SOME NUMBER LIKE NUMBERS GREATER THAN 99 ARE NOT WORKING EVEN 11 TO 19

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim libo, daan, pagitanngsampu, isa, sampu, lolipop As Integer
    Dim layas As String = ""
    Dim unangletra As Char
    Dim tali As String

    If TextBox1.Text > 9999 Then
    MsgBox("Number exceeds maximum recommended input.")
    ElseIf TextBox1.Text <= 99 Then


    libo = TextBox1.Text \ 1000
    TextBox1.Text = TextBox1.Text Mod 1000

    daan = TextBox1.Text \ 100
    TextBox1.Text = TextBox1.Text Mod 100

    If TextBox1.Text \ 100 Mod 10 >= 1 AndAlso TextBox1.Text \ 100 Mod 10 <= 9 Then
    pagitanngsampu = TextBox1.Text Mod 10


    Else

    sampu = TextBox1.Text \ 10
    TextBox1.Text = TextBox1.Text Mod 10
    isa = TextBox1.Text

    End If

    End If





    If libo = 1 Then

    layas = libo + "one thousand "

    ElseIf libo = 2 Then

    layas = layas + "two thousand "

    ElseIf libo = 3 Then
    layas = layas + "three thousand "

    ElseIf libo = 4 Then
    layas = layas + "four thousand "

    ElseIf libo = 5 Then
    layas = layas + "five thousand "

    ElseIf libo = 6 Then
    layas = layas + "six thousand "

    ElseIf libo = 7 Then
    layas = layas + "seven thousand "

    ElseIf libo = 8 Then
    layas = layas + "eight thousand "

    ElseIf libo = 9 Then
    layas = layas + "nine thousand "

    End If


    If daan = 1 Then
    layas = layas + "one hundred "

    ElseIf daan = 2 Then
    layas = layas + "two hundred "

    ElseIf daan = 3 Then
    layas = layas + "three hundred "

    ElseIf daan = 4 Then
    layas = layas + "four hundred "

    ElseIf daan = 5 Then
    layas = layas + "five hundred "

    ElseIf daan = 6 Then
    layas = layas + "six hundred "

    ElseIf daan = 7 Then
    layas = layas + "seven hundred "

    ElseIf daan = 8 Then
    layas = layas + "eight hundred "

    ElseIf daan = 9 Then
    layas = layas + "nine hundred "
    End If


    If pagitanngsampu = 1 Then

    layas = layas + "eleven "

    ElseIf pagitanngsampu = 2 Then
    layas = layas + "twelve "

    ElseIf pagitanngsampu = 3 Then
    layas = layas + "thirteen "

    ElseIf pagitanngsampu = 4 Then
    layas = layas + "fourteen "

    ElseIf pagitanngsampu = 5 Then
    layas = layas + "fifteen "

    ElseIf pagitanngsampu = 6 Then
    layas = layas + "sixteen "

    ElseIf pagitanngsampu = 7 Then
    layas = layas + "seventeen "

    ElseIf pagitanngsampu = 8 Then
    layas = layas + "eighteen "

    ElseIf pagitanngsampu = 9 Then
    layas = layas + "nineteen "

    End If

    If sampu = 1 Then

    layas = layas + "ten "

    ElseIf sampu = 2 Then

    layas = layas + "twenty "

    ElseIf sampu = 3 Then
    layas = layas + "thirty "

    ElseIf sampu = 4 Then
    layas = layas + "fourty "

    ElseIf sampu = 5 Then
    layas = layas + "fifty "

    ElseIf sampu = 6 Then
    layas = layas + "sixty "

    ElseIf sampu = 7 Then
    layas = layas + "seventy "

    ElseIf sampu = 8 Then
    layas = layas + "eighty "

    ElseIf sampu = 9 Then
    layas = layas + "ninety "

    End If


    If isa = 1 Then
    layas = layas + "one "

    ElseIf isa = 2 Then
    layas = layas + "two "

    ElseIf isa = 3 Then
    layas = layas + "three "

    ElseIf isa = 4 Then
    layas = layas + "four "

    ElseIf isa = 5 Then
    layas = layas + "five "

    ElseIf isa = 6 Then
    layas = layas + "six "

    ElseIf isa = 7 Then
    layas = layas + "seven "

    ElseIf isa = 8 Then
    layas = layas + "eight "

    ElseIf isa = 9 Then
    layas = layas + "nine "

    End If


    lolipop = Len(layas)
    unangletra = UCase(Strings.Left(layas, 1))
    tali = Mid(layas, 2, lolipop)
    TextBox2.AppendText(unangletra & tali)

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: pls help me!im begging you

    Put Option Strict ON. Fix the errors that you'll get.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: pls help me!im begging you

    It works good for me. Maybe you did something wrong.
    BTW if you wrap your code in [ CODE] [/ CODE] tags it would be easy for everyone to read here.

    Try this:
    Code:
        Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim n, libo, daan, pagitanngsampu, isa, sampu, lolipop As Integer
            Dim layas As String = ""
            Dim unangletra As Char
            Dim tali As String
    
            n = TextBox1.Text
            If n > 9999 Then
                TextBox2.AppendText("Number exceeds maximum recommended input.")
            Else
                libo = n \ 1000
                n = n Mod 1000
    
                daan = n \ 100
                n = n Mod 100
    
                If n >= 11 AndAlso n <= 19 Then
                    pagitanngsampu = n Mod 10
                Else
                    sampu = n \ 10
                    n = n Mod 10
                    isa = n
                End If
            End If
    
            If libo = 1 Then
                layas = layas + "one thousand "
            ElseIf libo = 2 Then
                layas = layas + "two thousand "
            ElseIf libo = 3 Then
                layas = layas + "three thousand "
            ElseIf libo = 4 Then
                layas = layas + "four thousand "
            ElseIf libo = 5 Then
                layas = layas + "five thousand "
            ElseIf libo = 6 Then
                layas = layas + "six thousand "
            ElseIf libo = 7 Then
                layas = layas + "seven thousand "
            ElseIf libo = 8 Then
                layas = layas + "eight thousand "
            ElseIf libo = 9 Then
                layas = layas + "nine thousand "
            End If
    
            If daan = 1 Then
                layas = layas + "one hundred "
            ElseIf daan = 2 Then
                layas = layas + "two hundred "
            ElseIf daan = 3 Then
                layas = layas + "three hundred "
            ElseIf daan = 4 Then
                layas = layas + "four hundred "
            ElseIf daan = 5 Then
                layas = layas + "five hundred "
            ElseIf daan = 6 Then
                layas = layas + "six hundred "
            ElseIf daan = 7 Then
                layas = layas + "seven hundred "
            ElseIf daan = 8 Then
                layas = layas + "eight hundred "
            ElseIf daan = 9 Then
                layas = layas + "nine hundred "
            End If
    
            If pagitanngsampu = 1 Then
                layas = layas + "eleven "
            ElseIf pagitanngsampu = 2 Then
                layas = layas + "twelve "
            ElseIf pagitanngsampu = 3 Then
                layas = layas + "thirteen "
            ElseIf pagitanngsampu = 4 Then
                layas = layas + "fourteen "
            ElseIf pagitanngsampu = 5 Then
                layas = layas + "fifteen "
            ElseIf pagitanngsampu = 6 Then
                layas = layas + "sixteen "
            ElseIf pagitanngsampu = 7 Then
                layas = layas + "seventeen "
            ElseIf pagitanngsampu = 8 Then
                layas = layas + "eighteen "
            ElseIf pagitanngsampu = 9 Then
                layas = layas + "nineteen "
            End If
    
            If sampu = 1 Then
                layas = layas + "ten "
            ElseIf sampu = 2 Then
                layas = layas + "twenty "
            ElseIf sampu = 3 Then
                layas = layas + "thirty "
            ElseIf sampu = 4 Then
                layas = layas + "fourty "
            ElseIf sampu = 5 Then
                layas = layas + "fifty "
            ElseIf sampu = 6 Then
                layas = layas + "sixty "
            ElseIf sampu = 7 Then
                layas = layas + "seventy "
            ElseIf sampu = 8 Then
                layas = layas + "eighty "
            ElseIf sampu = 9 Then
                layas = layas + "ninety "
            End If
    
            If isa = 1 Then
                layas = layas + "one "
            ElseIf isa = 2 Then
                layas = layas + "two "
            ElseIf isa = 3 Then
                layas = layas + "three "
            ElseIf isa = 4 Then
                layas = layas + "four "
            ElseIf isa = 5 Then
                layas = layas + "five "
            ElseIf isa = 6 Then
                layas = layas + "six "
            ElseIf isa = 7 Then
                layas = layas + "seven "
            ElseIf isa = 8 Then
                layas = layas + "eight "
            ElseIf isa = 9 Then
                layas = layas + "nine "
            End If
            lolipop = Len(layas)
            unangletra = UCase(Strings.Left(layas, 1))
            tali = Mid(layas, 2, lolipop)
            TextBox2.AppendText("")
            TextBox2.AppendText(unangletra & tali)
        End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    85

    Re: pls help me!im begging you

    thnk you very much!



    ------ there is something wrong in textbox2.text
    ---- it appends the answer in the textbox?
    which should not be

    example:

    first try :
    i inputted : 21
    output : Twenty one

    second try:
    i inputted: 23
    output : Twenty one Twenty three (WHICH IS WRONG)

    PLS HELP,....
    THANK YOU

  14. #14
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: pls help me!im begging you

    Just put TextBox2.Clear in the beginning of the sub...

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  15. #15
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: pls help me!im begging you

    Option Strict ON would be a VERY good idea for this program. All the implicit conversions and manipulations you were doing in the code could have caused most of the problems you were having. Pradeep solved most of that by putting the textbox into an integer in a single step, though even that is risky, because it assumes that the contents of the textbox CAN be converted to an integer. If it can't, the program will crash.

    Replacing:

    n = TextBox1.Text

    with:

    Code:
    If Not Integer.TryParse(TextBox1.Text,n) Then
     Windows.Forms.Messagebox.Show("Some nasty message because it wasn't an integer.")
     Return
    End If
    would be safer.
    My usual boring signature: Nothing

  16. #16
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: pls help me!im begging you

    Quote Originally Posted by izorcism View Post
    thnk you very much!



    ------ there is something wrong in textbox2.text
    ---- it appends the answer in the textbox?
    which should not be

    example:

    first try :
    i inputted : 21
    output : Twenty one

    second try:
    i inputted: 23
    output : Twenty one Twenty three (WHICH IS WRONG)

    PLS HELP,....
    THANK YOU
    What I did there was a quick conversion of Console Application to Windows Application. I ignored many things, since I just concentrated on the conversion part.
    What you need to do now is go line by line and fix things.
    There are many things that are fundamentally different in Console and Windows applicaitons. e.g. All input and output is at same place. Things are almost always appended to the output rather than an overwrite/replace. Fixed messages as well as program output goes at same place.. etc.

    Here are some fixes you would like to do now:
    1. Fixed messages like "Enter a number from 1 to 9999: " etc. would go into labels placed at appropriate places.
    2. Warning/Error messages like "Number exceeds maximum recommended input." go into MessageBox/MsgBox.
    3. You won't like to append the new output to previous output. Instead you want an overwrite/replace of previous output. This means TextBox2.AppendText should now be replaced by appropriate assignment operator. e.g. TextBox2.AppendText(unangletra & tali) should be replaced by: TextBox2.Text = unangletra & tali
    4. Put appropriate checks on user input as SH pointed out in previous post to avoid application from crashing.
    5. You won't like anyone writing in your output box. So make it readonly.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width