VenomXt
\
- Joined
- 11 Mar 2004
- Messages
- 3,454
I don't use Option Strict On normally but i need to start. getting these errors when I debug.
Option Strict On disallows implicit conversions from 'Double' to 'Decimal'.
Ok, what do i need to change in this code to make this compile without errors?
I now the issue is the way im doing the math in the Select Case statement.
Full Code
Option Strict On disallows implicit conversions from 'Double' to 'Decimal'.
Ok, what do i need to change in this code to make this compile without errors?
I now the issue is the way im doing the math in the Select Case statement.
Code:
Function Total(ByVal grade As String, ByVal gallons As Double) As Decimal
Select Case grade
Case "Regular"
Convert.ToDecimal(gallons)
Return 2.09 * gallons
Case "Special"
Convert.ToDecimal(gallons)
Return 2.16 * gallons
Case "Super"
Convert.ToDecimal(gallons)
Return 2.26 * gallons
End Select
End Function
Code:
Option Strict On
Public Class gasPump
Dim gallons As Double
Private Sub regButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles regButton.Click
totalTextBox.Text = String.Format("{0:C}", Total(regButton.Text, Convert.ToDouble(numOfGalTextBox.Text)))
End Sub
Private Sub numOfGalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numOfGalTextBox.TextChanged
gallons = Convert.ToDouble(numOfGalTextBox.Text)
End Sub
Function Total(ByVal grade As String, ByVal gallons As Double) As Decimal
Select Case grade
Case "Regular"
Convert.ToDecimal(gallons)
Return 2.09 * gallons
Case "Special"
Convert.ToDecimal(gallons)
Return 2.16 * gallons
Case "Super"
Convert.ToDecimal(gallons)
Return 2.26 * gallons
End Select
End Function
Private Sub specButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles specButton.Click
totalTextBox.Text = String.Format("{0:C}", Total(specButton.Text, Convert.ToDouble(numOfGalTextBox.Text)))
End Sub
Private Sub superButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles superButton.Click
totalTextBox.Text = String.Format("{0:C}", Total(superButton.Text, Convert.ToDouble(numOfGalTextBox.Text)))
End Sub
Private Sub gasPump_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub totalTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles totalTextBox.TextChanged
End Sub
End Class