Results 1 to 5 of 5

Thread: Total money calculator using number of coins

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2019
    Posts
    8

    Post Total money calculator using number of coins

    I'm new to VB and I'm having a problem with this code. It is very simple but I don't know how to solve the problem.
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Total money calculator using number of coins

    Firstly, please don't post images of code or error messages. Both are text so both can be posted as text.

    As for the issue, did you read the error message? It's telling you that an empty String cannot be converted to type Decimal. That type is for numbers so the issue should be obvious. Does an empty String represent a valid number? If not, why would you expect to be able to convert it? You're getting your input from a TextBox and the input is an empty String. What does that tell you?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2019
    Posts
    8

    Re: Total money calculator using number of coins

    That's the problem, I don't know how to convert it to a decimal. When I declare it as a decimal, the value just ends up as 0.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Total money calculator using number of coins

    Based on your Textbox naming - which I will commend you for since many people here post code with controls named TextBox1, Button1, etc. - it looks like txtOut is the Textbox in which you plan to display the total value of the coins of various types that have been entered.

    That being the case, I would imagine you are not intending that the user will type anything into txtOut. However, your code is attempting to convert the contents of txtOut from a String to a Decimal. If the txtOut TextBox is empty, which I believe it is your intention that it will be, then that conversion will throw the error you are receiving.

    So, your declaration statement of the totalmoney variable should have no reference to txtOut. Only after totalmoney has been calculated, then that value should be displayed in txtOut.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2019
    Posts
    8

    Re: Total money calculator using number of coins

    Thanks a lot!

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