Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27206

VS 2010 Error when Option Strict On vs. Option Explicit On

$
0
0
I recently joined VBForums and this is my first post. Hopefully I've put it in the right forum group.

I am looking for some help with a question. Normally I use Option Explicit enforced with my code (lots of VBA and a couple of VB.Net projects). Here's a code snippet that raises an error when Option Strict is enforced, but not when Option Explicit is enforced:




Dim lngFlags As Long
Dim flgReturn As Boolean = False

Try
If InternetGetConnectedState(lngFlags, 0) Then
flgReturn = True
If (lngFlags And ConnectionStates.LAN) Then
strConnectionState = "LAN"
ElseIf (lngFlags And ConnectionStates.Modem) Then




The lines that perform the lngFlags and ConnectionStates comparisons (e.g., "If (lngFlags And ConnectionStates.LAN) Then") raise errors. The error number is 3 and the error message is:

"Option Strict On disallows implicit conversions from 'Long' to 'Boolean'."

The various ConnectionStates are defined as Integer types in an enum at the beginning of the code module (e.g,. "RasInstalled = &H10").

I use the above code in a procedure that tests whether or not my machine is connected to the Internet. This procedure is used in quite a few of my VBA projects, and now in several of my VB.Net projects. It works fine, unless Option Strict On is set.

I've poked around my VB books and various VB websites, but haven't found anything to explain these errors. Can somebody please tell me what I need to change to make this code run without errors when Option Strict is enforced?

I would appreciate any insight and advice someone can give me regarding this code.

Thanks,

Mark

Viewing all articles
Browse latest Browse all 27206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>