need help with option strict on

Posted on 2006-04-21
Last Modified: 2010-04-23
I am taking a class in college and running into a problem. I have some code that runs good but when i put in "Option strict On", I then can no longer run my program. Please help. Here is my code:

Option Strict On

Public Class hagerstownWaterBill
    Inherits System.Windows.Forms.Form

    Private Sub uiCalculateBillButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiCalculateBillButton.Click
        'Set default variables
        Const waterChargePerGallon As Double = 0.00175
        Dim CurrentReading As Double
        Dim PreviousReading As Double
        Dim gallonsUsed As Double

        'Set default variables
            CurrentReading = Me.uiCurrentReadingTextBox.Text
            PreviousReading = Me.uiPreviousReadingTextBox.Text

            'if CurrentReading >= PreviousReading then do calculations, otherwise display message
            If CurrentReading >= PreviousReading Then
                'Perform calculations
                gallonsUsed = CurrentReading - PreviousReading
                uiGallonsUsedAmtLabel.Text = Format(gallonsUsed, "N0")
                gallonsUsed = gallonsUsed * waterChargePerGallon
                uiWaterChargeAmtLabel.Text = Format(gallonsUsed, "C2")
                'Display error message
                MessageBox.Show("The current reading must be greater than or equal to the previous reading", _
                "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub

    Private Sub hagerstownWaterBill_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress, uiCurrentReadingTextBox.KeyPress, uiPreviousReadingTextBox.KeyPress
        'user can only press numeric keys
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") Then
            e.Handled = True
        End If
    End Sub
    Private Sub hagerstownWaterBill_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiCurrentReadingTextBox.TextChanged, uiPreviousReadingTextBox.TextChanged
        'Clear error message
        Me.uiGallonsUsedAmtLabel.Text = ""
    End Sub
    Private Sub uiExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiExitButton.Click
        'Close Window
    End Sub
Question by:mappenzellar
    LVL 25

    Accepted Solution

    Can you post all the places the compiler is giving you errors.  These two are easy to spot:

              CurrentReading = Me.uiCurrentReadingTextBox.Text
              PreviousReading = Me.uiPreviousReadingTextBox.Text

    They should be:

              CurrentReading = cdbl(Me.uiCurrentReadingTextBox.Text)
              PreviousReading = cdbl(Me.uiPreviousReadingTextBox.Text)

    But there may be others.


    Author Comment

    I am not familiar with cdbl but that did in fact do the trick. Thanks!

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now