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

Joined
Mar 11, 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

Perris Calderon wrote on Electronic Punk's profile.
Hey ep!

All good with me, applying for microsoft mvp right now, should have done this a while ago.

Notifications don't work, I only found your response by comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...

Forum statistics

Threads
61,975
Messages
673,270
Members
89,047
Latest member
hargadetocline