The default instance is another change in Visual Basic .NET is the default instance of the form, and many people developed from Visual Basic 6.0. Net development is confused because of the default instance that cannot be found. You must create an instance of it when you use a form object: DIM FRM AS New Form2Frm.Show () Visual Basic 2005 supports the default instance, so you can use the following syntax: Form2.show () if you can pass My.Forms collection to access the default form example is better: My.Forms.form2.show ()
Compiler WARNING Visual Basic 2005 supports compiler warnings, which allows you to get issues as much as possible before running in the program. WARNING gives it to the green wavy line in the code (and the error is given by the blue wavy line). The compiler warning includes recursive attribute access, Catch block, or CASE block overlap, created a function without return values, and so on. The most favorite warning example is the object that is not initialized: DIM Cust As Customerif Cust.Name.length = 0 Then '... Endiff Here, the background compiler will be placed on the IF statement CUST Wave line. Warning text is written in this: "Variable 'Cust' Is Used Before It Has Been Assigned A Value." (Variable "Cust" is not assigned). An null value reference exception will be triggered at runtime. How many times do not have the program when the program is running, I found this type of error in my code, and now, the compiler can discover these errors when compiling. By the way, when you type the above code in the code editor, the compiler will initially go to the green wavy line in the DIM statement and give a "unused local variable 'Cust' (not used." Local variable "CUST"). At the beginning, you will feel this very annoying because you just add this variable, but this feature finally ensures the simplicity of the code. All errors are no longer displayed in the task list in the IDE, but use a new Errors List window to separate errors, warnings, and information (see Figures 2 and Figure 6). You can set whether the compiler tag alert or error in the application designer's compile panel, and checkbox controls in the panel can be used to turn off all warnings or regard all warnings as an error. Using the OPTION STRICT ON statement can be used to automatically generate compile time errors. If you try to implicate contraction conversion (possibly cause data loss), Option Strict will be labeled in the code: DIM IVALUE AS INTEGERDIM LVALUE AS LongiValue = LVALUE 'Contraction Conversion Error Lvalue = ivalue' correct If you use late bindings It will also get an error. The advanced binding of an object is to say through the object type variable: DIM MyObj As ObjectCall myobj.method1 () 'Late Binding Error Now uses option strict in Visual Studio to write a good habit. As long as it may, you should open Option Strict in the Tools | Options menu, the method is to select the check box corresponding to the Option Strict on the Project setting. Alternatively, you can write an OPTION STRICT ON statement at the top of a class or module file.
@ The following is the text for users reference @Default InstancesAnother change to Visual Basic .NET that has tripped up many developers migrating from Visual Basic 6.0 is the lack of a default instance for forms You need to create an instance of the form before using it.: Dim frm As New Form2frm.Show () Visual Basic 2005 supports form default instances, so you can use the familiar syntax: Form2.Show () It's best if you access this default form instance through the My.Forms collection: My.Forms. Form2.Show () Compiler WarningsVisual Basic 2005 supports compiler warnings, which give you a heads-up on issues that may cause problems at run time. A warning is shown as a green squiggly line under your code (errors are shown as blue squiggles) .Compiler warnings include recursive property access, overlapping catch blocks or case statements, creating a function without a return value, and others My favorite warning is for a variable reference on an uninitialized object:. Dim cust As CustomerIf cust.Name.Length = 0 Then '... End Ifhere T he background compiler puts a green squiggly line under cust in the If statement. The warning text displayed reads "variable 'cust' is used before it has been assigned a value." A null reference exception could result at run time. I do not know how many times I've found this type of error in my code at run time, and now the compiler finds these errors at compile time.Incidentally, as you type the code above in the editor, the compiler initially puts a green squiggly under Cust in The Dim Statement with The Message "Unused Local Variable 'Cust'." At First this Seems A bit Annoying Because You '