realmike15
Baseband Member
- Messages
- 90
I just started my first Intro to VB.NET class, and I'm having a little difficulty with a take home project. I'd e-mail my teacher, but he takes forever to get back to you and I thought someone may be able to give me some quick help.
Sorry if this post sounds a little confusing, I'm trying to get the VB language down still, but see if you can follow me.
I'm trying to get the hang of using declarations, and so far I dont seem to get any errors calculating the numeric values, but when I try to parse my calculations to a string in order to show them in the text box it wont allow me.
The specific build error is "value of type 'string' cannot be converted to 'System.Windows.Forms.Label'
The program is just intended to calculate fuel consumption and gas cost, based on:
1. Gallons purchased
2. Price per gallon
3. Initial Odometer reading
4. Final Odometer reading
Before I post the code I have so far below, I know I'm using Integer for all my numbers when I probably shouldn't, declaring each variable in individual statements, and probably some others things I shouldn't be doing. I would appreciate it if I could just get help build error at the moment, one thing at a time . I'm really just trying to get a handle on understanding how to write the code first.
---------------------------------------------------------------------------------
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Declare variables
Dim gallonsInteger As Integer
Dim pricePerInteger As Integer
Dim initialOdometerInteger As Integer
Dim finalOdometerInteger As Integer
Dim fuelConsumptionInteger As Integer
Dim gasCostInteger As Integer
'Convert input values to numeric variables
gallonsInteger = Integer.Parse(txtGallons.Text)
pricePerInteger = Integer.Parse(txtPricePerGallon.Text)
initialOdometerInteger = Integer.Parse(txtInitialOdometer.Text)
finalOdometerInteger = Integer.Parse(txtFinalOdometer.Text)
'Calculate Fuel Consumption and Gas Cost
gasCostInteger = gallonsInteger * pricePerInteger
fuelConsumptionInteger = finalOdometerInteger - initialOdometerInteger
'Convert to string and display calculations
lblFuelConsumption = fuelConsumptionInteger.ToString()
lblGasCost = gasCostInteger.ToString()
Sorry if this post sounds a little confusing, I'm trying to get the VB language down still, but see if you can follow me.
I'm trying to get the hang of using declarations, and so far I dont seem to get any errors calculating the numeric values, but when I try to parse my calculations to a string in order to show them in the text box it wont allow me.
The specific build error is "value of type 'string' cannot be converted to 'System.Windows.Forms.Label'
The program is just intended to calculate fuel consumption and gas cost, based on:
1. Gallons purchased
2. Price per gallon
3. Initial Odometer reading
4. Final Odometer reading
Before I post the code I have so far below, I know I'm using Integer for all my numbers when I probably shouldn't, declaring each variable in individual statements, and probably some others things I shouldn't be doing. I would appreciate it if I could just get help build error at the moment, one thing at a time . I'm really just trying to get a handle on understanding how to write the code first.
---------------------------------------------------------------------------------
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Declare variables
Dim gallonsInteger As Integer
Dim pricePerInteger As Integer
Dim initialOdometerInteger As Integer
Dim finalOdometerInteger As Integer
Dim fuelConsumptionInteger As Integer
Dim gasCostInteger As Integer
'Convert input values to numeric variables
gallonsInteger = Integer.Parse(txtGallons.Text)
pricePerInteger = Integer.Parse(txtPricePerGallon.Text)
initialOdometerInteger = Integer.Parse(txtInitialOdometer.Text)
finalOdometerInteger = Integer.Parse(txtFinalOdometer.Text)
'Calculate Fuel Consumption and Gas Cost
gasCostInteger = gallonsInteger * pricePerInteger
fuelConsumptionInteger = finalOdometerInteger - initialOdometerInteger
'Convert to string and display calculations
lblFuelConsumption = fuelConsumptionInteger.ToString()
lblGasCost = gasCostInteger.ToString()