Here are some handy VB tips I've collected.

• Coding Conventions
• A long statement can be broken into several lines by including a space and underscore ( _) at the end of each line.
• One statement per line is standard. Multiple statements can be put on the same line if a colon (:) is placed between statements.
• Use ampersand (&) to link strings and use plus sign (+) to link numerical values.
• Visual Basic prefixes octal numbers with &O and hexadecimal numbers with &H. EG: 15 = &O17 = &HF.
• Using the Option Explicit keywords at the start of each code module should almost be mandatory. It enables VB to check for errors on your identifiers.
• vbCrLf is a Standard Visual Basic Constant signifying the ANSI characters 13 and 10, i.e. Carriage Return and Line Feed. It is useful in entering a linebreak in string.
• DoEvents, aka "Pixie Dust", is a Visual Basic Statement that temporarily returns processor control to the operating system. It is useful to execute this statement in the middle of code that takes a long time to process. It is also good for whenever you want stuff redrawn immediately.
• Use the Container property of an object to specify which container contains the control. A container, eg a Form, Frame, PictureBox, or Toolbar, can contain several controls of different types.
• To free memory and system resources used by objects, be sure to assign the Nothing keyword to the object variable with the Set statement when finished with the object variable and to use the Unload keyword for forms.
• When establishing your tab order, start with the last control by setting its TabIndex property to 0 and then repeat with the second to the last, and so on.
• Use Str() to convert a number to a string. Use Val() to convert a string to a number. Use Format() to format a string.
• Right clicking on a variable or procedure can yield lots of info. EG: Definition will take you to where the variable was declared or to where the procedure was written.
• Help for VB is available through the MSDN Library. If you have VB and the Library open and then close VB, it will also close the Library but your favorites in the Library will not be saved. If you have VB and the Library open and then close the Library, then your favorites will be saved but you'll have to then close VB.
• The graphic formats that VB recognize include: BMP (bitmap), ICO (icon), CUR (cursor), RLE (run-length encoded), WMF (Windows metafile), GIF (Graphical Interchange Format), and JPEG (Joint Photographic Experts Group).
• An enumeration is like a Long Integer data type that is limited to the values of enumerated constants.
• When using a variable whose data type is enumerated, VB can show utilize Auto List Member.
• Enumerations start with 0 by default and go up by 1.
• You can explicitly set values of enumerated constants.
• More than one enumerated constant may have the same value.
• You may qualify the enumerated constant with the enumeration name.
• Create public or private enumerations with the Enum statement in the declarations section of a standard module or public class module.
• A UDT (User Defined Type) is like an object with different objects, each of which may be a different data type or object type.
• Create public or private UDTs with the Type statement in the declarations section of a standard module or class module.
• Create private UDTs with the Type statement in the declarations section of a form module.
• UDTs may be nested.
• Debug a VB project for a dll without compiling the dll:
1. Make sure any objects called by the dll are registered on the developer's machine.
2. Set break points in the VB project for a dll.
3. Run that VB project for a dll.
4. Run a VB project that uses the dll.
• Here are 3 methods to place a quotation mark (") in your strings. All of the following examples say: He said, "hi"..
• Use 2 quotation marks in a row. EG: str1 = "He said, ""hi"".". (c or JS would use \".)
• Use the a character code. EG: str1 = "He said, " & Chr(34) & "hi" & Chr(34) & ".". (c would use \u0022.)
• Use a constant. EG:
Const q As String = Chr(34)
str1 = "He said, " & q & "hi" & q & "."
• VBScript has 2 undocumented functions of note:
• Escape(string). Returns string where the non-alphanumeric characters are URL encoded (i.e. with the format of %hexadecimal;). This include the following characters: * + - . / @ _.
• Unescape(string). Returns string where the URL encoding is converted to its corresponding ASCII character.

Page Modified: (Hand noted: ) (Auto noted: )