Results 1 to 4 of 4

Thread: Gas Gauge

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    105

    Smile Gas Gauge

    I would like to know how to program a "gas gauge" if you will. I know the MPG of our shuttle and the mileage for each shuttle run but I am not sure how to make the gas gauge work. I am using a progress bar for that. Any ideas? Any help would be appreciated.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Gas Gauge

    I don't understand the question.

    What is the progress bar supposed to show the progress of?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    105

    Re: Gas Gauge

    Okay, sorry. I have a Shuttle Van Program that I am working on and I am using a progress bar to simulate a fuel gauge. Whenever a user inserts a new shuttle run I want it to calculate the fuel consumption and show it on the progress bar. How do I do that?

    Also, I am having trouble adding the miles to the destination to the mileage on the car. I get 89000.5 and it only does it once for some reason. I am using My.Settings to store mileage and adding to it as each shuttle run is put into the database.

    Code:
    Try
                Dim NewMPG As Decimal
                NewMPG = lblMiles.Text + MilesTextBox.Text
                lblMiles.Text = NewMPG
                My.Settings.Mileage = lblMiles.Text
                My.Settings.Save()
                lblMiles.Text = "ESTIMATED VEHICLE MILEAGE: " &   My.Settings.Mileage
            Catch ex As Exception
    
            End Try

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Gas Gauge

    You are assuming that this:
    Code:
    NewMPG = lblMiles.Text + MilesTextBox.Text
    will automatically convert both strings to numbers for you, which it won't. "1" + "2" is "12", not "3". Additions of strings is concatenation. If you want to add numbers then you need to have numbers. You shouldn't be using the Text of the Label at all because in order to display a number in a Label you must have had a number in the first place, so you should use that. As for the TextBox, you could use a NumericUpDown instead, or you could use Decimal.TryParse to convert the Text of the TextBox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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