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

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.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
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 coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
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!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR