locked
Option Strict On Problem RRS feed

  • Question

  • Hi Good People

    I am Using A DataContext in my code to Check If the new record Being inserted ... already exists in the database, But when I turn Option Strict on For another part of my code I get squiggly lines in part of my code, And when I hover over the Squiggly lines it says (Option Strict on Disallows late Binding)  Is there another way to check If a record Being inserted already Exists.

    Where I get the Squiggly Lines are underLined in the code Below.

      Private Sub txtDropAddress_Leave(sender As Object, e As EventArgs) Handles txtDropAddress.Leave
    
            Dim Fares As New FareDataContext
    
            If txtDropAddress.Text = "" Then
                MessageBox.Show("Please insert a Drop Address for.... " & vbCrLf & txtPickupAddress.Text)
                txtDropAddress.Focus()
            Else ' Checking if Address Already exists in the database
    
                Dim FA = From Fare In Fares.Fares _
                   Where Fare.PickupAddress = txtPickupAddress.Text _
                   AndAlso Fare.DropAddress = txtDropAddress.Text
    
                If Not FA.Count = 0 Then 'if Addresses does exist in the database then MessageBox show
                    MessageBox.Show("The Address " & vbCrLf & txtPickupAddress.Text & " To " & txtDropAddress.Text _
                           & " Already Exists" & MessageBoxButtons.OK)
    
                    FaresBindingNavigator.DeleteItem.PerformClick()
                    btnReturnAddress.Show()
                    btnAddNewFare.Enabled = False
    
                Else 'If the Addresses Does not exist then txtInsertfare .Focus
                    txtInsertFare.Focus()
                    lblCaption.Text = "Please insert a price for Address " & vbCrLf & "From...   " & txtPickupAddress.Text & _
                        "   TO... " & txtDropAddress.Text
    
                End If
    
            End If
        End Sub

    Kind Regards

    Gary


    Gary Simpson

    Wednesday, April 15, 2015 2:47 PM

Answers

  • What's the type of "FA" if you hover over it?

    Do you get "Option Strict on Disallows late Binding" for both underlined locations?

    Do you have Option Infer On or Off?


    Armin

    • Marked as answer by Gary Simpson Wednesday, April 15, 2015 4:44 PM
    Wednesday, April 15, 2015 2:54 PM
  • Option Strict on requires all variables Declarations to have an "As" Clause


    That's contradictive to what you wrote before: "I Do get "Option Strict on Disallows late Binding" for both underlined locations". Now you write a different message for the first location. Anyway, it seems you have Option Infer Off.

    You have two choices:

    a) Switch Option Infer On. This automatically declares FA as the correct type.

    b) Declare FA explicitly:

          Dim FA As ____ = From ....

    I do not know what you have to insert for "____" because I don't know the data types. Probably you will have to write

          Dim FA As IEnumerable(Of Fare) = From ....


    Armin

    • Edited by Armin Zingler Wednesday, April 15, 2015 4:02 PM formatting
    • Proposed as answer by Paul P Clement IV Wednesday, April 15, 2015 4:10 PM
    • Marked as answer by Gary Simpson Wednesday, April 15, 2015 4:43 PM
    Wednesday, April 15, 2015 4:00 PM

All replies

  • What's the type of "FA" if you hover over it?

    Do you get "Option Strict on Disallows late Binding" for both underlined locations?

    Do you have Option Infer On or Off?


    Armin

    • Marked as answer by Gary Simpson Wednesday, April 15, 2015 4:44 PM
    Wednesday, April 15, 2015 2:54 PM
  • Hi Armin

    Thank again for looking into my question.

    Do get "Option Strict on Disallows late Binding" for both underlined locations?

    and I don't have option infer at all

    Gary


    Gary Simpson


    Wednesday, April 15, 2015 3:13 PM

  • Do you get "Option Strict on Disallows late Binding" for both underlined locations?

    and I don't have option infer at all

    Sorry to ask again: What's the type of "FA" if you hover over it? (with the mouse pointer)

    I ask because I can't test it as most types are missing here.

    Open the project's properties (on the "compile" tab) to see the Option Infer setting. Default is "On".


    Armin

    Wednesday, April 15, 2015 3:19 PM
  • Armin

    I not really sure what you're asking "What's the type of "FA" It is a string, Varchar, text?

    Gary


    Gary Simpson

    Wednesday, April 15, 2015 3:33 PM
  • FA is a variable. Every variable has a type. I'd like to know the type of variable FA. To find it out, you can hover the mouse pointer over the variable name. A tooltip is shown that shows the type. Please let me know which type it is. An alternative is moving the caret to the variable name and pressing Ctrl+I.

    Armin

    Wednesday, April 15, 2015 3:42 PM
  • Hi Armin

    Or you could be looking for what does FA stand for..

    FA is short for Fares

    Gary


    Gary Simpson

    Wednesday, April 15, 2015 3:44 PM
  • Hi Armin

    Option Strict on requires all variables Declarations to have an "As" Clause

    Gary


    Gary Simpson

    Wednesday, April 15, 2015 3:51 PM
  • I think what Armin is saying is that you need to specify the data type for FA in the Dim statement, otherwise I believe it would be Object and you would be using late binding.

    Dim FA As ... = From Fare In Fares.Fares


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, April 15, 2015 3:56 PM
  • Option Strict on requires all variables Declarations to have an "As" Clause


    That's contradictive to what you wrote before: "I Do get "Option Strict on Disallows late Binding" for both underlined locations". Now you write a different message for the first location. Anyway, it seems you have Option Infer Off.

    You have two choices:

    a) Switch Option Infer On. This automatically declares FA as the correct type.

    b) Declare FA explicitly:

          Dim FA As ____ = From ....

    I do not know what you have to insert for "____" because I don't know the data types. Probably you will have to write

          Dim FA As IEnumerable(Of Fare) = From ....


    Armin

    • Edited by Armin Zingler Wednesday, April 15, 2015 4:02 PM formatting
    • Proposed as answer by Paul P Clement IV Wednesday, April 15, 2015 4:10 PM
    • Marked as answer by Gary Simpson Wednesday, April 15, 2015 4:43 PM
    Wednesday, April 15, 2015 4:00 PM
  • I think what Armin is saying is ...


    No, before giving a suggestion, I was actually still in the phase of trying to find out things, which is sometimes pretty hard.

    Armin

    Wednesday, April 15, 2015 4:04 PM
  • I was just trying to get the OP to look at it from a different angle. Based upon the code FA is an Object, and there are a couple of different ways to resolve the Option Strict issue in this instance.

    You can put that in your follow-up. Oh, wait! You did! ;-)


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, April 15, 2015 4:09 PM
  • Hi Armin

    I am So sorry For The Mix-up That Contradicted myself. How You Guy's Put up with me asking question and not being able to give you guy's the information you require to help Me.

    What I think happened when I put my cursor over the second Line I got that message  "Option Strict on Disallows late Binding", I then got distracted. And when I resumed the Check, I put my cursor over the same second line. (Doh My Bad)

    I am so Sorry for my mistake and I hope this does not put you off help other people out or people like me. you Guy's that do what you do on here is so valuable to people like me. I can not thank you enough.

    Best regards

    Gary 


    Gary Simpson

    Wednesday, April 15, 2015 4:40 PM
  • Thanks Gary, no problem, you're welcome.

    Armin

    Wednesday, April 15, 2015 4:54 PM