Results 1 to 30 of 30

Thread: Format("$#####0.00) FIGURED OUT

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131

    Format("$#####0.00) FIGURED OUT

    I am trying to get my grpTotalSales.Text and grpAverageSales.Text to display a dollar sign and then a money value. It works for my gross pay but it doesn't work for the others. Here is the code:

    VB Code:
    1. Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    2.         ' name abbreviations
    3.         SA = Val(nudSales.Text)
    4.         SP = Val(grpSalespersons.Text)
    5.         TS = Val(grpTotalSales.Text)
    6.         ' Compute value and display in Gross Pay
    7.         GP = BP + SA * CM
    8.         txtGross.Text = Format(GP, "$#####0.00")
    9.         ' Compute value and display in Salespersons
    10.         grpSalespersons.Text = (SP + 1).ToString
    11.         ' Compute value and display in Total Sales
    12.         grpTotalSales.Text = (SA + TS).ToString
    13.         grpTotalSales.Text = Format(TS, "$#####0.00")
    14.         ' Compute value and display in Average Sales
    15.         grpAverageSales.Text = Format("$#####0.00")
    16.         If SP = 0 Then
    17.             grpAverageSales.Text = (SA).ToString
    18.         Else
    19.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString
    20.  
    21.         End If
    22.  
    23.        
    24.     End Sub
    Last edited by twisted; Jun 9th, 2004 at 12:12 PM.
    Twisted

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Try, for example;

    TextGross.Text = FormatCurrency(GP, 2)



    By the way, if you are not previously updating SP at any time, your code:

    If SP = 0 Then
    grpAverageSales.Text = (SA).ToString
    Else
    grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString

    End If

    is unnecessary, as you can simply use

    grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString
    Last edited by taxes; Jun 8th, 2004 at 12:55 PM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    ***?

    grpTotalSales.Text = (SA + TS).ToString
    grpTotalSales.Text = Format(TS, "$#####0.00")

    You do realize line 2 will overwrite tesults from line 1?

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by taxes
    Hi,

    Try, for example;

    TextGross.Text = FormatCurrency(GP, 2)



    By the way, if you are not previously updating SP at any time, your code:

    If SP = 0 Then
    grpAverageSales.Text = (SA).ToString
    Else
    grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString

    End If

    is unnecessary, as you can simply use

    grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString
    Nope didn't work!
    I also tried this, but then it messes up my math.

    VB Code:
    1. grpTotalSales.Text = FormatCurrency((SA + TS), 2)
    Twisted

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131

    Re: ***?

    Originally posted by techgnome
    grpTotalSales.Text = (SA + TS).ToString
    grpTotalSales.Text = Format(TS, "$#####0.00")

    You do realize line 2 will overwrite tesults from line 1?

    TG
    Actually NO I didn't because I am the true definition of a VB newb, but thanks for clarifying this to me. How would I get it to display the $ with my value. Say Format to look like this $567.65??
    Twisted

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Did you try something like this . This part (ToString("c")) converts the number to the default currency profile on the user system .

    VB Code:
    1. Dim int As Integer = 20 + 30
    2.         Me.TextBox1.Text = int.ToString("c")

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    so that would be like so:
    grpTotalSales.Text = (SA + TS).ToString("c")

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by techgnome
    so that would be like so:
    grpTotalSales.Text = (SA + TS).ToString("c")

    TG
    hope it works ....

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    As soon as I add the ("c") to the end it doesn't add SA + TS anymore. It just displays the SA. I had exactly what your code looks like without the ("c") and it works, but as soon as I add the ("c") it doesn't.
    Twisted

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    This might help seeing my code:

    VB Code:
    1. Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    2.         ' name abbreviations
    3.         SA = Val(nudSales.Text)
    4.         SP = Val(grpSalespersons.Text)
    5.         TS = Val(grpTotalSales.Text)
    6.         ' Compute value and display in Gross Pay
    7.         GP = BP + SA * CM
    8.         txtGross.Text = Format(GP, "$#####0.00")
    9.         ' Compute value and display in Salespersons
    10.         grpSalespersons.Text = (SP + 1).ToString
    11.         ' Compute value and display in Total Sales
    12.         grpTotalSales.Text = (SA + TS).ToString
    13.  
    14.         ' Compute value and display in Average Sales
    15.         If SP = 0 Then
    16.             grpAverageSales.Text = (SA).ToString
    17.         Else
    18.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString
    19.  
    20.         End If
    21.  
    22.        
    23.     End Sub
    Twisted

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by twisted
    As soon as I add the ("c") to the end it doesn't add SA + TS anymore. It just displays the SA. I had exactly what your code looks like without the ("c") and it works, but as soon as I add the ("c") it doesn't.
    Add the two numbers in an integer or decimal type depends on the number format you'll get . Then use the ToString like shown before .

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by Pirate
    Add the two numbers in an integer or decimal type depends on the number format you'll get . Then use the ToString like shown before .
    You lost me! I did however add the ("c") behind my AverageSales and it worked fine, just won't work with my TotalSales:
    VB Code:
    1. If SP = 0 Then
    2.             grpAverageSales.Text = (SA).ToString("c")
    3.         Else
    4.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString("c")
    5.  
    6.         End If
    Twisted

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    We both posted at the same time .

    ToString("c") should be the last step and alone before assinging the total to the TextBox . So ,

    VB Code:
    1. If SP = 0 Then
    2.             grpAverageSales.Text = (SA).ToString("c")
    3.         Else
    4. Dim T As Integer =((SA + TS) / (SP + 1))
    5.             grpAverageSales.Text = T.ToString("c")
    6.  
    7.         End If
    Try this

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Now do you know why this doesn't work with this:
    VB Code:
    1. grpTotalSales.Text = (SA + TS).ToString("c")
    It doesn't add for me if I add the "c"
    Twisted

  15. #15
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by twisted
    Now do you know why this doesn't work with this:
    VB Code:
    1. grpTotalSales.Text = (SA + TS).ToString("c")
    It doesn't add for me if I add the "c"
    It must be something wrong with your logic . It does work fine for me . Try to set breakpoints to see the values of SA and TS .

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi twisted,

    When you say

    TextGross.Text = FormatCurrency(GP, 2)

    does not work, what result do you get? I have tried it with various combinations of decimal places and it works fine every time.

    From your other threads I assume that you declared GP as a Double.

    I suppose the $ is your default currency?

    You are using the 2003 version of .NET arn't you?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by Pirate
    It must be something wrong with your logic . It does work fine for me . Try to set breakpoints to see the values of SA and TS .
    Works OK for me also.


    twisted.

    Just a thought. Did you begin this project in VB6 and then convert it to VB.NET?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by taxes
    Hi twisted,

    When you say

    TextGross.Text = FormatCurrency(GP, 2)

    does not work, what result do you get?
    I already got my txtGross.Text to work. I'm trying to get grpTotalSales.Text to do the same, but it won't.
    It just doesn't do anything. My total sales still calculates fine, but it doesn't give me a $ sign or the money decimal places. For example: it shows up 800 instead of how I want it $800.00. Here is how my code looks:
    VB Code:
    1. Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    2.         ' name abbreviations
    3.         SA = Val(nudSales.Text)
    4.         SP = Val(grpSalespersons.Text)
    5.         TS = Val(grpTotalSales.Text)
    6.         ' Compute value and display in Gross Pay
    7.         GP = BP + SA * CM
    8.         txtGross.Text = Format(GP, "c")
    9.         ' Compute value and display in Salespersons
    10.         grpSalespersons.Text = (SP + 1).ToString
    11.         ' Compute value and display in Total Sales
    12.         grpTotalSales.Text = FormatCurrency(TS, 2)
    13.         grpTotalSales.Text = (SA + TS).ToString
    14.         ' Compute value and display in Average Sales
    15.         If SP = 0 Then
    16.             grpAverageSales.Text = (SA).ToString("c")
    17.         Else
    18.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString("c")
    19.  
    20.         End If
    21.  
    22.        
    23.     End Sub
    Twisted

  19. #19
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    OK. What you are doing wrong in this case is

    " grpTotalSales.Text = FormatCurrency(TS, 2)
    grpTotalSales.Text = (SA + TS).ToString

    "

    The second line overwrites the first. What you want is the single line


    grpTotalSales.Text=FormatCurrency(SA+TS, 2)


    or

    grpTotalSales.Text=(SA+TS).ToString("c")

    or

    grpTotalSales.Text = Format(SA+TS, "c")


    For the future, I suggest you pick one method and stick to it.
    Last edited by taxes; Jun 9th, 2004 at 08:39 AM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Weird! As soon as I try either one of those my SA doesn't add to TS. It just simply display SA. When I leave it like this;

    grpTotalSales.Text = (SA + TS).ToString

    it works fine. But I can't have no currency and can't figure out why only the Total Sales won't allow me to do this:

    grpTotalSales.Text = (SA + TS).ToString("c")

    All the others work in my code, just not TotalSales:
    VB Code:
    1. Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    2.         ' name abbreviations
    3.         SA = Val(nudSales.Text)
    4.         SP = Val(grpSalespersons.Text)
    5.         TS = Val(grpTotalSales.Text)
    6.         ' Compute value and display in Gross Pay
    7.         GP = BP + SA * CM
    8.         txtGross.Text = Format(GP, "c")
    9.         ' Compute value and display in Salespersons
    10.         grpSalespersons.Text = (SP + 1).ToString
    11.         ' Compute value and display in Total Sales
    12.         grpTotalSales.Text = (SA + TS).ToString
    13.         ' Compute value and display in Average Sales
    14.         If SP = 0 Then
    15.             grpAverageSales.Text = (SA).ToString("c")
    16.         Else
    17.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString("c")
    18.  
    19.         End If
    20.  
    21.        
    22.     End Sub
    Twisted

  21. #21
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    grpTotalSales.Text = FormatCurrency(TS, 2)
    grpTotalSales.Text = (SA + TS).ToString

    You're duplicating the code again.....
    grpTotalSales.Text = FormatCurrency(SA + TS)
    One line that's it... what was happening was you were setting it right, then overwriting it....

    TG

    EDIT: Whoopse, never mind taxes beat me to it.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    I know you guys are right and my code even looks right, but everytime I format TotalSales to show currency it doesn't add SA + TS anymore. It does display currency correct but only SA. Say if I enter 800.00 in SA then TS will display $800.00. Which is perfect, but when I enter a new value in SA, say 200.00 then I should get TS to be $1,000.00 but I'm getting the value of SA spit back at me $200.00. Before when I just have:

    grpTotalSales.Text = (SA + TS).ToString

    then it calculates fine, just doesn't have currency. WHICH I NEED!

    It has to be something wrong somewhere in my code that is causing this to not work. I know I should be able to just add the "c" and be fine, like I did with the others. Here is my code and I will put in red where my problem is.
    VB Code:
    1. Option Strict On
    2. Public Class frmGrossPayCalculator
    3.     Inherits System.Windows.Forms.Form
    4.     ' Assignment 2:     Gross Pay Calculator
    5.     ' Programmer:       Brad von Oven
    6.     ' Date:             June 11, 2004
    7.     ' Purpose:          Create an application to display
    8.     '                   a salesperson’s gross pay with base
    9.     '                   and commission based on the following:  
    10.     '                   Base pay is $500; commission is 6% of
    11.     '                   sales (use constants to represent these).  
    12.     '                   The user enters the salesperson’s total sales;
    13.     '                   keep track of each salesperson’s sales and the
    14.     '                   number of salespersons.  Display the current
    15.     '                   person’s gross pay and the summary of:  
    16.     '                   total salespersons, total amount of all sales,
    17.     '                   and average sales per salesperson.
    18.  
    19.     ' Set up constants for Base pay(BP) = $500 and commission(CM) is 6%
    20.     Const BP As Double = 500.0
    21.     Const CM As Double = 0.06
    22.     ' Set up variables for sales, gross pay, salespersons, total sales,
    23.     ' and average sales.
    24.     Dim SA, GP, SP, TS, AV As Double
    25.  
    26.     Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    27.         End
    28.     End Sub
    29.  
    30.     Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    31.         ' name abbreviations
    32.         SA = Val(nudSales.Text)
    33.         SP = Val(grpSalespersons.Text)
    34.         TS = Val(grpTotalSales.Text)
    35.         ' Compute value and display in Gross Pay
    36.         GP = BP + SA * CM
    37.         txtGross.Text = Format(GP, "c")
    38.         ' Compute value and display in Salespersons
    39.         grpSalespersons.Text = (SP + 1).ToString
    40.         ' Compute value and display in Total Sales
    41.         [COLOR=red]grpTotalSales.Text = (SA + TS).ToString("c")[/COLOR]
    42.         ' Compute value and display in Average Sales
    43.         If SP = 0 Then
    44.             grpAverageSales.Text = (SA).ToString("c")
    45.         Else
    46.             grpAverageSales.Text = ((SA + TS) / (SP + 1)).ToString("c")
    47.  
    48.         End If
    49.  
    50.        
    51.     End Sub
    52.  
    53.     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    54.         nudSales.Text = "1.0"
    55.         txtGross.Text = ""
    56.         nudSales.Focus()
    57.  
    58.     End Sub
    59.  
    60.     Private Sub btnResetAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetAll.Click
    61.         SA = 1.0
    62.         txtGross.Text = ""
    63.         grpSalespersons.Text = ""
    64.         grpTotalSales.Text = ""
    65.         grpAverageSales.Text = ""
    66.         nudSales.Focus()
    67.     End Sub
    68.  
    69.     Private Sub nudSales_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudSales.LostFocus
    70.         nudSales.Text = Format(nudSales.Value, "#,###.##")
    71.  
    72.     End Sub
    73. End Class

    Thanks for all the help guys!
    Twisted

  23. #23
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    HI,

    OK. I've got it!!!!!


    When you set the grpTotalSales.Text to include a currence sign, that means the result of val(grpTotalSales.Text will always be 0, because this expression gives the numerical value of all characters BEFORE the first non numerical character.


    I am working on a way round this and will come back to you
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  24. #24
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    If you want to maintain the currency sign then you will have to us two form scope variables.

    The following works:

    In the General Section of the form

    Dim SP, TS As Double

    Then amend your code to

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' name abbreviations
    3.         Dim CM As Double = 0.05
    4.         Dim BP As Double = 3000
    5.         Dim SA, GP As Double
    6.         SP = SP + 1
    7.         SA = Val(nudSales.Text)
    8.         TS = TS + SA
    9.         ' Compute value and display in Gross Pay
    10.         GP = BP + TS * CM
    11.         txtGross.Text = Format(GP, "c")
    12.         ' Compute value and display in Salespersons
    13.         grpSalespersons.Text = (SP).ToString
    14.         ' Compute value and display in Total Sales
    15.         grpTotalSales.Text = (TS).ToString("c")
    16.         ' Compute value and display in Average Sales
    17.         grpAverageSales.Text = (TS / SP).ToString("c")
    18.  
    19.  
    20.  
    21.     End Sub

    That should get you there, but other people may have other solutions.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Worked awesome! But now I ran into a new problem with this. My Reset All value will reset everything blank which is good, but when I try to type new values in nudSales it retains all the old values and calculates using them. How do I get my Reset all to wipe out all the old values and start from scratch again! Here is what I did with my code:

    VB Code:
    1. Dim SA, GP, SP, TS As Double
    2.  
    3.  
    4.     Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    5.         End
    6.     End Sub
    7.  
    8.     Private Sub btnGross_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGross.Click
    9.         ' name abbreviations
    10.         SP = SP + 1
    11.         SA = Val(nudSales.Text)
    12.         TS = TS + SA
    13.         ' Compute value and display in Gross Pay
    14.         GP = BP + TS * CM
    15.         txtGross.Text = Format(GP, "c")
    16.         ' Compute value and display in Salespersons
    17.         grpSalespersons.Text = (SP).ToString
    18.         ' Compute value and display in Total Sales
    19.         grpTotalSales.Text = (TS).ToString("c")
    20.         ' Compute value and display in Average Sales
    21.         grpAverageSales.Text = (TS / SP).ToString("c")
    22.  
    23.  
    24.        
    25.     End Sub
    26.  
    27.     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    28.         nudSales.Text = "1.0"
    29.         txtGross.Text = ""
    30.         nudSales.Focus()
    31.  
    32.     End Sub
    33.  
    34.     Private Sub btnResetAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetAll.Click
    35.         SA = 1.0
    36.         txtGross.Text = ""
    37.         grpSalespersons.Text = ""
    38.         grpTotalSales.Text = ""
    39.         grpAverageSales.Text = ""
    40.         nudSales.Focus()
    41.     End Sub
    42.  
    43.     Private Sub nudSales_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudSales.LostFocus
    44.         nudSales.Text = Format(nudSales.Value, "#,###.##")
    45.  
    46.     End Sub
    47. End Class
    Twisted

  26. #26
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    You need to clear out the variable too, not just the text boxes.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    That's what I thought, so I tried to use:

    SP = ""

    but Option Strict is On so how would I write that??
    Twisted

  28. #28
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Since SP is a number, set it to 0.

    SP = 0


    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    May 2004
    Posts
    131
    Originally posted by taxes
    Hi,

    If you want to maintain the currency sign then you will have to us two form scope variables.

    The following works:

    In the General Section of the form

    Dim SP, TS As Double

    Then amend your code to

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ' name abbreviations
    3.         Dim CM As Double = 0.05
    4.         Dim BP As Double = 3000
    5.         Dim SA, GP As Double
    6.         SP = SP + 1
    7.         SA = Val(nudSales.Text)
    8.         TS = TS + SA
    9.         ' Compute value and display in Gross Pay
    10.         GP = BP + TS * CM
    11.         txtGross.Text = Format(GP, "c")
    12.         ' Compute value and display in Salespersons
    13.         grpSalespersons.Text = (SP).ToString
    14.         ' Compute value and display in Total Sales
    15.         grpTotalSales.Text = (TS).ToString("c")
    16.         ' Compute value and display in Average Sales
    17.         grpAverageSales.Text = (TS / SP).ToString("c")
    18.  
    19.  
    20.  
    21.     End Sub

    That should get you there, but other people may have other solutions.
    You changed my GP formula! I was fliping out, thinking what Now? Anyway, I changed it back to GP = BP + SA * CM

    Everything is absolutely perfect! This thread is finally closed. Thanks for all the help guys. More projects to come
    Twisted

  30. #30
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Sorry, I've taken a few hours off to play tennis.

    "You changed my GP formula! I was fliping out, thinking what Now? Anyway, I changed it back to GP = BP + SA * CM"



    Surely if you use SA instead of TS you are calculating your commission on your last sales entry only and not on your total sales.

    I wonder if you have done something to upset it in your reset code.

    your reset codes should be

    VB Code:
    1. Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
    2.         nudSales.Text = ""
    3.         txtGross.Text = ""
    4.         nudSales.Focus()
    5.  
    6.     End Sub
    7.  
    8.     Private Sub btnResetAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetAll.Click
    9.         SP = 0
    10.         TS = 0
    11.         grpSalespersons.Text = ""
    12.         grpTotalSales.Text = ""
    13.         grpAverageSales.Text = ""
    14.         btnReset.PerformClick()
    15.     End Sub

    You do not need to reset SA as that is done automatically in the Button_Click event.


    Now you have got this far, note that the only box in which entries are made by the operator is the nudSales textbox. Therefore, All THE OTHER textboxes SHOULD be Labels. Otherwise the operator might make erroneous entries and defeat the program
    Last edited by taxes; Jun 9th, 2004 at 05:03 PM.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

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