Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Currency

Currency

Scheduled Pinned Locked Moved Visual Basic
tutorial
17 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    You're a real beginner at this aren't you? What you would do is store the decimal version of the currency in a variable. THen when you need to show the value in a currency format, you supply the Format specification. Something like this:

    Dim amount As Single
    

    amount = 10.5
    Console.WriteLine("Amount is " & Format(amount, "Currency"))
    Console.WriteLine("Amount is " & Format(amount, "C"))
    Console.WriteLine("Amount is " & Format(amount, "$###,##0.00"))

    All three Format specifications do the exact same thing. The one exception is the "Currency" and "C" specifications will use the format of the Windows Locale currentcy format, specified in the Regional and Language Options Control Panel. RageInTheMachine9532

    I Offline
    I Offline
    ibok23
    wrote on last edited by
    #5

    Yes, I am a newbie. I have a box that is going to = $10.00. So I would write: dim baserate as double = 84.5 costofroom.text = Console.writeline(Format(amount,"Currency")) am i close Thank you, ibok23

    D 1 Reply Last reply
    0
    • I ibok23

      Yes, I am a newbie. I have a box that is going to = $10.00. So I would write: dim baserate as double = 84.5 costofroom.text = Console.writeline(Format(amount,"Currency")) am i close Thank you, ibok23

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #6

      Not quite... I'm assuming you have a TextBox on your Form called costofroom. I'm also assuming that you want the 'baserate' to be displayed in the TextBox and not 'amount' like in my example code.

      dim baserate as double = 84.5
      costofroom.text = Format(baserate,"Currency")

      RageInTheMachine9532

      I 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Not quite... I'm assuming you have a TextBox on your Form called costofroom. I'm also assuming that you want the 'baserate' to be displayed in the TextBox and not 'amount' like in my example code.

        dim baserate as double = 84.5
        costofroom.text = Format(baserate,"Currency")

        RageInTheMachine9532

        I Offline
        I Offline
        ibok23
        wrote on last edited by
        #7

        sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23

        G N D 3 Replies Last reply
        0
        • I ibok23

          sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23

          G Offline
          G Offline
          Guillermo Rivero
          wrote on last edited by
          #8

          Try this... Dim amount as double amount = 10.5 Console.Writeline(amount.ToString("C")) Free your mind...

          1 Reply Last reply
          0
          • I ibok23

            sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23

            N Offline
            N Offline
            Nadroj
            wrote on last edited by
            #9

            maybe try

            Console.Writeline(Format(0,"$#,###0.00"))
            

            i havent tried this but i remember i used something just like it before, i forget exactly what it was. mess around with that if it gives an error. itll b just around the corner. ------------------------ Jordan. III

            1 Reply Last reply
            0
            • I ibok23

              sorry about that.. i tried. ok, I have put that in.. have not tried one more error. if I have $0.00 dollars as the amount for a box additonalguestcharge.text I put... additionalguesstcharge.text = format(0,"currency") getting an error..but of course. now what. By the way thanks for all the input. Thank you, ibok23

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #10

              First, what's the error? RageInTheMachine9532

              I 2 Replies Last reply
              0
              • D Dave Kreskowiak

                First, what's the error? RageInTheMachine9532

                I Offline
                I Offline
                ibok23
                wrote on last edited by
                #11

                i am not sure. I just now ran the problem and I received a yellow arrow at one of my endifs. Not sure what to do. Thank you, ibok23

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  First, what's the error? RageInTheMachine9532

                  I Offline
                  I Offline
                  ibok23
                  wrote on last edited by
                  #12

                  I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23

                  I D N 3 Replies Last reply
                  0
                  • I ibok23

                    I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23

                    I Offline
                    I Offline
                    ibok23
                    wrote on last edited by
                    #13

                    I have to leave, be back in one hour if I need to. Thanks again. Thank you, ibok23

                    1 Reply Last reply
                    0
                    • I ibok23

                      I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #14

                      ibok23 wrote: total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) That's because you adding String of characters together, not number values. What's going to make you redesign your code is the fact the the numbers you see in the TextBoxs can't be used in calculations. TextBoxs are lousy places to keep number values. You should only use them to display results. Since I can't see all of your code, I can't tell you exactly what you have to do to make things right, but I can tell you you need to keep the value you use in calculations in numeric type variables. You also need to rename your TextBoxes so that their names don't conflict with any other variable names. I would suggest renaming them with a 'txt' prefex, like this:

                      total                    becomes   txtTotal
                      subtotal                 becomes   txtSubTotal
                      additionalguestcharge    becomes   txtAdditionalGuestCharge
                      ...
                      

                      Now, keep your numeric values in variables something like this:

                      Dim subtotal As Double
                      Dim additionalguestcharge as Double
                      Dim rollbed as Double
                      Dim total as Double
                      
                      total = subtotal + additionalguestcharge + rollbed
                      txtTotal.Text = Format(total, "C")
                      

                      Get the idea? RageInTheMachine9532

                      A 1 Reply Last reply
                      0
                      • I ibok23

                        I finally got it done. Now i am haveing problems with my total. I am trying to add three boxes together. I love math and I know what to do. I put total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) in my answer it gives me $209.00$5.00$10.00 instead of adding it up. This is weird. Thank you, ibok23

                        N Offline
                        N Offline
                        Nadroj
                        wrote on last edited by
                        #15

                        when adding text in labels, textboxes, etc etc, you must convert them to a number first. they are concatenating (putting together) the text, with what you are doing right now. do something like: total.text = CInt(CInt(subtotal.text) + CInt(additionalguestcharge.text) + CInt(rollbed.text)) ------------------------ Jordan. III

                        1 Reply Last reply
                        0
                        • D Dave Kreskowiak

                          ibok23 wrote: total.text = ((subtotal.text) + (additionalguestcharge.text) + (rollbed.text)) That's because you adding String of characters together, not number values. What's going to make you redesign your code is the fact the the numbers you see in the TextBoxs can't be used in calculations. TextBoxs are lousy places to keep number values. You should only use them to display results. Since I can't see all of your code, I can't tell you exactly what you have to do to make things right, but I can tell you you need to keep the value you use in calculations in numeric type variables. You also need to rename your TextBoxes so that their names don't conflict with any other variable names. I would suggest renaming them with a 'txt' prefex, like this:

                          total                    becomes   txtTotal
                          subtotal                 becomes   txtSubTotal
                          additionalguestcharge    becomes   txtAdditionalGuestCharge
                          ...
                          

                          Now, keep your numeric values in variables something like this:

                          Dim subtotal As Double
                          Dim additionalguestcharge as Double
                          Dim rollbed as Double
                          Dim total as Double
                          
                          total = subtotal + additionalguestcharge + rollbed
                          txtTotal.Text = Format(total, "C")
                          

                          Get the idea? RageInTheMachine9532

                          A Offline
                          A Offline
                          Anonymous
                          wrote on last edited by
                          #16

                          Thanks - I see what I was doing wrong, I don't understand it all the way, but I do see. Now one more question if you don't mind How do you get to set a date picker back to the current date when you push the clear button? I want them to be able when they push the clear button to default back to the current date.

                          D 1 Reply Last reply
                          0
                          • A Anonymous

                            Thanks - I see what I was doing wrong, I don't understand it all the way, but I do see. Now one more question if you don't mind How do you get to set a date picker back to the current date when you push the clear button? I want them to be able when they push the clear button to default back to the current date.

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #17

                            Anonymous wrote: I want them to be able when they push the clear button to default back to the current date. Easy enough ... just set the Value property of the DateTimePicker control to the current Date using Now(). Put this code in the handler for the Clear button click:

                            dtpArrival.Value = Now()
                            dtpCheckout.Value = Now()
                            

                            RageInTheMachine9532

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups