Option Strict On disallows implicit conversions from 'Double' to 'Decimal'.

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.

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
Full Code
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
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back