• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

need help with option strict on

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
1 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.

mappenzellarAuthor Commented:
I am not familiar with cdbl but that did in fact do the trick. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now