-
May 30th, 2023, 05:22 AM
#1
Thread Starter
PowerPoster
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.
-
May 30th, 2023, 06:44 AM
#2
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
-
May 30th, 2023, 08:51 AM
#3
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
 
-
May 30th, 2023, 06:01 PM
#4
Thread Starter
PowerPoster
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.
-
May 30th, 2023, 07:42 PM
#5
Re: VB implicit variable typing
Try setting it in your Project Properties
Project-->Properties-->Compile-->Option Infer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 30th, 2023, 09:09 PM
#6
Thread Starter
PowerPoster
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.
-
May 30th, 2023, 10:21 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|