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

Discussion in 'Web Design & Coding' started by VenomXt, Mar 6, 2007.

  1. VenomXt

    VenomXt Blame me for the RAZR's Folding Team

    Messages:
    3,453
    Location:
    Houston, Texas
    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
     
  2. falconguard

    falconguard Carbon based lifeform Political User Folding Team

    Messages:
    3,406
    Location:
    SoCal
    Try using float instead of Double