Learn how to a build a cloud-first strategyRegister Now


need help with option strict on

Posted on 2006-04-21
Medium Priority
Last Modified: 2010-04-23
I am taking a vb.net 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

clockwatcher earned 200 total points
ID: 16513432
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

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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