Results 1 to 7 of 7

Thread: RESOLVED - VB implicit variable typing

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved RESOLVED - VB implicit variable typing

    Hello,
    I have 2 VB projects open in VS 2019 on the same computer, one is my main project, the other is a proof-of-concept program written by a colleague. I am copying over some code from the proof-of-concept project to the main one.
    In my colleague's code, there will be statements like:
    "Dim request = New MailKit.FetchRequest(MailKit.MessageSummaryItems....etc."
    and if I hover "request", VS indicates that the type is "MailKit.FetchRequest".
    When I copy this over to the main project, VS doesn't "know" what the type is, and reports that it is "Object".

    How do I make the main project recognize the type?
    (As it is, I have to do "Dim request As MailKit.FetchRequest = New MailKit.FetchRequest(MailKit.MessageSummaryItems....etc.")
    Last edited by BruceG; May 30th, 2023 at 09:10 PM. Reason: Resolved
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,316

    Re: VB implicit variable typing

    Check to see if the Option Infer has been set on (in the poc app) or off (in your app) ... you can do this by setting Option Infer at the top of hte code file (like Option Explicit is) or in the project properties.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,495

    Re: VB implicit variable typing

    It seems like you also probably have Option Strict OFF, which it should not be.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: VB implicit variable typing

    Hey guys - searching the "entire solution" for both projects yields same results:
    "Option Strict" appears in Application.Designer.vb, Resources.Designer.vb, and Settings.Designer.vb.
    "Option Infer" does not appear at all.
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,288

    Re: VB implicit variable typing

    Try setting it in your Project Properties

    Project-->Properties-->Compile-->Option Infer

  6. #6

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: VB implicit variable typing

    Thanks .paul. - actually just found that! And that was the cause of my issue - the POC project had it on, but the main project had it off.
    "It's cold gin time again ..."

    Check out my website here.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109,808

    Re: RESOLVED - VB implicit variable typing

    You should set Option Strict On in the VS options so that it will be On by default in every new project you create. The only good reason to have Option Strict Off at the project level is that you have upgraded VB6 code that would generate a large number of errors otherwise. It seems that Microsoft chose to have it Off by default to make migrating from VB6 easier - many VB6 developers don't need any extra excuses not to migrate - but also to maintain VB's reputation as being easier for beginners. Anyone who understands the implications or wants to write the best code they can should immediately turn it On by default and only turn it Off is the specific cases where late binding is required. Even then, it should be On at the project level and Off at the file level in only those files that require it. Partial classes should be used to keep the code in those files to an absolute minimum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width