| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/Visual_Basic_.NET |
| Contents |
|---|
| Syntax |
| Simple example |
| Comparison with the classic Visual Basic |
| Visual Basic | ||||
|---|---|---|---|---|
| Paradigm | Multi-paradigm: structured, imperative, object-oriented, declarative, generic, reflective and event-driven | |||
| Designed by | Microsoft | |||
| Developer | Microsoft | |||
| First appeared | 2001;25 years ago (2001) | |||
|
The Windows Forms library is most commonly used to create GUI interfaces in Visual Basic. All visual elements in the Windows Forms class library derive from the Control class. This provides the minimal functionality of a user interface element such as location, size, color, font, text, as well as common events like click and drag/drop. The Control class also has docking support to let a control rearrange its position under its parent. Forms are typically designed in the Visual Studio IDE. In Visual Studio, forms are created using drag-and-drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls have attributes and event handlers associated with them. Default values are provided when the control is created, but may be changed in the Visual Studio IDE GUI or in code. Many attribute values can be modified during run time by code such as based on user actions, or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted. Syntaxedit
Visual Basic uses statements to specify actions. The most common statement is an expression statement, consisting of an expression to be evaluated, on a single line. As part of that evaluation, functions or subroutines may be called and variables may be assigned new values. To modify the normal sequential execution of statements, Visual Basic provides several control-flow statements identified by reserved keywords. Structured programming is supported by several constructs including two conditional execution constructs (If ... Then ... Else ... End If and Select Case ... Case ... End Select ) and four iterative execution (loop) constructs (Do ... Loop, For ... To, For Each, and While ... End While) . The For ... To statement has separate initialisation and testing sections, both of which must be present. (See examples below.) The For Each statement steps through each value in a list. In addition, in Visual Basic:
Simple exampleeditThe following is a very simple Visual Basic program, a version of the classic "Hello, World!" example created as a console application: SubMain()
This line defines a subroutine called "Main". "Main" is the entry point, where the program begins execution. =1
WriteLine("Allowed range is 1 and {0}",Integer.MaxValue)
Loop
' Output of Floyd's Triangle
DimcurrentAsInteger=1
DimrowAsInteger
DimcolumnAsInteger
Forrow=1Torows
Forcolumn=1Torow
Write("{0,-2} ",current)
current+=1
Next
WriteLine()
Next
EndSub
''' <summary>
''' Like Console.ReadLine but takes a prompt string.
''' </summary>
FunctionReadLine(OptionalpromptAsString=Nothing)AsString
IfpromptIsNotNothingThen
Write(prompt)
EndIf
ReturnConsole.ReadLine()
EndFunction
EndModule
Comparison with the classic Visual BasiceditThe 'cmd' prefix is replaced by the 'btn' prefix, conforming to the new convention previously mentioned.
| ||||