background preloader

Unsorted (Visual Basic)

Facebook Twitter

If...Then...Else Statement (Visual Basic) Conditionally executes a group of statements, depending on the value of an expression. ' Multiple-line syntax: If condition [ Then ] [ statements ] [ ElseIf elseifcondition [ Then ] [ elseifstatements ] ] [ Else [ elsestatements ] ] End If ' Single-line syntax: If condition Then [ statements ] [ Else [ elsestatements ] ] condition Required.

If...Then...Else Statement (Visual Basic)

Expression. Must evaluate to True or False, or to a data type that is implicitly convertible to Boolean. If the expression is a Nullable Boolean variable that evaluates to Nothing, the condition is treated as if the expression is not True, and the Else block is executed. Parameters Collection (ADO) FIND Function. MS Access 2003: Create a parameter query that performs a wildcard search. Parameters Collection (ADO) Command Object Parameters.

'BeginManualParamCmd On Error GoTo ErrHandler: Dim objConn As New ADODB.Connection Dim objCmd As New ADODB.Command Dim objParm1 As New ADODB.Parameter Dim objRs As New ADODB.Recordset ' Set the CommandText as a parameterized SQL query. objCmd.CommandText = "SELECT OrderID, OrderDate, " & _ "RequiredDate, ShippedDate " & _ "FROM Orders " & _ "WHERE CustomerID = ?

Command Object Parameters

" & _ "ORDER BY OrderID" objCmd.CommandType = adCmdText ' Prepare command because we will be executing it more than once. objCmd.Prepared = True ' Create new parameter for CustomerID. Initial value is ALFKI. Set objParm1 = objCmd.CreateParameter("CustId", adChar, _ adParamInput, 5, "ALFKI") objCmd.Parameters.Append objParm1 ' Connect to the data source.

Set objConn = GetNewConnection objCmd.ActiveConnection = objConn ' Execute once and display. Not all providers support prepared commands. ADO Parameter Object. Item Method (VBA Add-In Object Model) (Visual Basic Add-In Model) Forward reference to user-defined type. Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion. String Functions (Visual Basic) The following table lists the functions that Visual Basic provides to search and manipulate strings.

String Functions (Visual Basic)

You can use the Option Compare statement to set whether strings are compared using a case-insensitive text sort order determined by your system's locale (Text) or by the internal binary representations of the characters (Binary). The default text comparison method is Binary. This example uses the UCase function to return an uppercase version of a string. ' String to convert.

Dim LowerCase As String = "Hello World 1234" ' Returns "HELLO WORLD 1234". How to: Access Characters in Strings in Visual Basic. Returning a regex match in VBA (excel) Worksheet function - Is there an Excel formula to identify special characters in a cell? MATCH function. Visual Basic, Using arrays as arguments in Let and Get Properties. Vb6 - How to pass a function for parameter? Visual Basic Secrets. AddressOf Operator. AddressOf Operator (Visual Basic) Creates a procedure delegate instance that references the specific procedure. procedurename Required.

AddressOf Operator (Visual Basic)

Specifies the procedure to be referenced by the newly created procedure delegate. The AddressOf operator creates a function delegate that points to the function specified by procedurename. When the specified procedure is an instance method then the function delegate refers to both the instance and the method. The AddressOf operator can be used as the operand of a delegate constructor or it can be used in a context in which the type of the delegate can be determined by the compiler.

This example uses the AddressOf operator to designate a delegate to handle the Click event of a button. ' Add the following line to Sub Form1_Load(). The following example uses the AddressOf operator to designate the startup function for a thread. Public Sub CountSheep() Dim i As Integer = 1 ' Sheep do not count from 0. Reference Other Resources. AddressOf/Delegate question clarified - VB6.0, .NET question.

Visual Basic Language: Delegates. Delegate & events - Visual Basic(Microsoft): Version 5 & 6. Relaxed Delegate Conversion (Visual Basic) Relaxed delegate conversion enables you to assign subs and functions to delegates or handlers even when their signatures are not identical.

Relaxed Delegate Conversion (Visual Basic)

Therefore, binding to delegates becomes consistent with the binding already allowed for method invocations. In place of exact signature match, relaxed conversion requires that the following conditions be met when Option Strict is set to On: A widening conversion must exist from the data type of each delegate parameter to the data type of the corresponding parameter of the assigned function or Sub. In the following example, the delegate Del1 has one parameter, an Integer. Parameter m in the assigned lambda expressions must have a data type for which there is a widening conversion from Integer, such as Long or Double. ' Definition of delegate Del1. If Option Strict is set to Off, the widening restriction is removed in both directions. How to: Pass Procedures to Another Procedure in Visual Basic.

How to: Invoke a Delegate Method (Visual Basic) Delegates (Visual Basic) Delegates are objects that refer to methods.

Delegates (Visual Basic)

They are sometimes described as type-safe function pointers because they are similar to function pointers used in other programming languages. But unlike function pointers, Visual Basic delegates are a reference type based on the class System.Delegate. Delegates can reference both shared methods — methods that can be called without a specific instance of a class — and instance methods. Delegates are useful in situations where you need an intermediary between a calling procedure and the procedure being called.

For example, you might want an object that raises events to be able to call different event handlers under different circumstances. Although you can create your own delegates, in most cases Visual Basic creates the delegate and takes care of the details for you. AddHandler Button1.Click, New EventHandler(AddressOf Button1_Click) ' The following line of code is shorthand for the previous line. AddressOf [expression.]methodName. Vb6 - How to call a function with function name reference to a string value in VB.