Option Strict and Explicit ?

myblueocean

Well-known member
Joined
Jun 29, 2007
Messages
161
Location
England
Programming Experience
Beginner
"Option Strict On
Option Explicit On
Imports System.Convert"

What does this all mean, I've never seen this piece anywhere.
 
Hi, i'm a beginner too, but I think its do do with converting variable types.
With them switched on, you have to manually put in any conversions from one type to another. With them off vb will automatically do the conversions. I think it is better to leave them on because it forces you to code the conversions yourself avoiding errors as you are in control.

Anyone who knows better feel free to expand or correct me altogether.
 
Option Explicit On - you have to declare all variables before you can use them
Option Strict On - all conversions must be explicit, implicit conversions wont be allowed
Imports System.Convert - System.Convert is imported and those methods can be used without typing in "Convert" before the ToString, ToInt32, ToDouble, etc
 
The options are set in application properties, Build tab. In classic VB before .Net you had to use code to set these options. You can still use option code to override the default project setting for only some classes.
all conversions must be explicit
Not entireliy correct, widenings is allowed with strict, not implicit narrowing.
 
Hmm....righty, well thanks at least for leading me on a path...
 
Back
Top