Calculations in VS2008


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Calculations in VS2008

  1. #1
    Join Date
    Sep 2008
    Posts
    41

    Calculations in VS2008

    Hi all,

    Having a little trouble doing some calculations in VS2008 i am putting figures on a daily basis so not all the text boxes will have a figure in them have linked to a save button on the form but would like to have it that once each text box has lost focus it will update the total in TxtTotalIncome.Text.

    eg
    text box 1 has 12 once lost focus total will have 12
    text box 2 has 12 once lost focus total will have 24 (text box 1 + text box 2)

    but when i type in the figures in to the monday and tuesday text boxes it comes up with an error about the missing figure in the wednesday text box and so on.

    Any help will be greatly appriciated.

    Regards

    Aidan

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What is the exact error and error number and what code do you have in the Lost Focus event that triggers the calculations?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Sep 2008
    Posts
    41
    Hi Hack,

    Conversion from string "" to type 'Integer' is not valid. this is what i get back when i try it the database field was set as currency and i have now changed to number but think it is something to do with it being left blank.

    Code:
     
            Dim TotalIncome As Integer
            Dim MondaySales As Integer
            Dim TuesdaySales As Integer
            Dim WednesdaySales As Integer
            Dim ThursdaySales As Integer
            Dim FridaySales As Integer
            Dim SaturdaySales As Integer
            Dim SundaySales As Integer
    
    
            TxtTotalIncome.Text = TotalIncome
            MondaySales = MondaySalesTextBox.Text
            TuesdaySales = TuesdaySalesTextBox.Text
            WednesdaySales = WednesdaySalesTextBox.Text
            ThursdaySales = ThursdaySalesTextBox.Text
            FridaySales = FridaySalesTextBox.Text
            SaturdaySales = SaturdaySalesTextBox.Text
            SundaySales = SundaySalesTextBox.Text
    
    
    
            TotalIncome = (MondaySales + TuesdaySales + WednesdaySales)
    This is the code i have in the save_click command button but would like to change this to when i lose focus on the box i have just entered the figure in to it totals it up to total income text box

    Regards

    Aidan

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try this
    Code:
    MondaySales = Integer.Parse(MondaySalesTextBox.Text)
    TuesdaySales = Integer.Parse(TuesdaySalesTextBox.Text)
    WednesdaySales = Integer.Parse(WednesdaySalesTextBox.Text)
    ThursdaySales = Integer.Parse(ThursdaySalesTextBox.Text)
    FridaySales = Integer.Parse(FridaySalesTextBox.Text)
    SaturdaySales = Integer.Parse(SaturdaySalesTextBox.Text)
    SundaySales = Integer.Parse(SundaySalesTextBox.Text)
    Last edited by Hack; 09-22-2008 at 09:11 AM.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Sep 2008
    Posts
    41
    to do the calculation on the lost focus would the formula be put in that decleration?. ie on lose focus mondaysales+tuesdaysales = totalsales.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    That depends on where it makes the most sense for you and your application.

    TextBox controls do have a Lost Focus event that can be used. The only thing I would put in there would be TotalIncome = (MondaySales + TuesdaySales + WednesdaySales+etc)

    In the Lost Focus event (or something other event that would make sense) I would put the individual variable settings, i.e., MondaySales = Integer.Parse(MondaySalesTextBox.Text) would go in the Lost Focus for the MondaySalesTextBox event. TuesdaySales = Integer.Parse(TuesdaySalesTextBox.Text) would go in the Lost Focus for the TuesdaySalesTextBox event, etc, etc.

    Perhaps what makes the most sense right now isn't readily apparent...that happens. So, just try a few things. First off, make sure the math is working properly. That is number one.

    When that works, then you can fiddle around with where things go and how they will be displayed.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Vs2008 Database deployment problem
    By Aidanb79 in forum .NET
    Replies: 12
    Last Post: 09-19-2008, 01:27 PM
  2. VS2008 Express - SQL data source
    By csillagyitzik in forum .NET
    Replies: 0
    Last Post: 05-30-2008, 03:03 PM
  3. Replies: 7
    Last Post: 03-03-2008, 02:06 PM
  4. Is it possile to make DB do calculations.
    By landslide in forum Database
    Replies: 3
    Last Post: 07-29-2007, 11:52 AM
  5. calculations
    By daisy_polly in forum VB Classic
    Replies: 3
    Last Post: 07-12-2005, 11:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center