Monday 16 July 2012

String Functions in Visual Basic 6


String Functions in Visual Basic 6 by Muhammad Waqas at muftarticles

VB has numerous built-in string functions for processing strings. Most VB string-handling functions return a string, although some return a number (such as the Len function, which returns the length of a string and functions like Instr and InstrRev, which return a character position within the string). The functions that return strings can be coded with or without the dollar sign ($) at the end, although it is more efficient to use the version with the dollar sign.
The first time I started trying to understand the VB6 string functions I was somewhat confused. This tutorial will walk you through all the different ways you can us VB to handle strings. If you are still confused feel free to post a comment and hopefully we can help get you cleared up. Also there are many other string related tutorials on this site so feel free to browse around.
Function:
Len
Description:
Returns a Long containing the length of the specified string
Syntax:
Len(string)
Where string is the string whose length (number of characters) is to be 
returned.
Example:
lngLen = Len("Visual Basic")    ' lngLen = 12


Function:
Mid$ (or Mid)
Description:
Returns a substring containing a specified number of characters from a 
string.
Syntax:
Mid$(string, start[, length])
The Mid$ function syntax has these parts:
string Required. String expression from which characters are returned.
start Required; Long. Character position in string at which the part to
 be taken begins. If start is greater than the number of characters in 
string, Mid returns a zero-length string ("").
length Optional; Long. Number of characters to return. If omitted or if 
there are fewer than length characters in the text (including the
 character at start), all characters from the start position to the end of
 the string are returned.

Example:

strSubstr = Mid$("Visual Basic", 3,       ' strSubstr = "sual"
Note: Mid$ can also be used on the left side of an assignment
 statement, where you can replace a substring within a string.
strTest = "Visual Basic"
Mid$(strTest, 3, 4) = "xxxx"

'strTest now contains "Vixxxx Basic"
In VB6, the Replace$ function was introduced, which can also be
 used to replace characters within a string.


Function:
Left$ (or Left)
Description:
Returns a substring containing a specified number of characters from
 the beginning (left side) of a string.
Syntax:
Left$(string, length)
The Left$ function syntax has these parts:
string Required. String expression from which the leftmost characters 
are returned.
length Required; Long. Numeric expression indicating how many 
characters to return. If 0, a zero-length string ("") is returned. If 
greater than or equal to the number of characters in string, the entire
string is returned.

Example:
strSubstr = Left$("Visual Basic", 3)    ' strSubstr = "Vis"

' Note that the same thing could be accomplished with Mid$:
strSubstr = Mid$("Visual Basic", 1, 3)


Function:
Right$ (or Right)
Description:
Returns a substring containing a specified number of characters from
 the end (right side) of a string.
Syntax:
Right$(string, length)
The Right$ function syntax has these parts:
string Required. String expression from which the rightmost 
characters are returned.
length Required; Long. Numeric expression indicating how many
 characters to return. If 0, a zero-length string ("") is returned.
If greater than or equal to the number of characters in string, the
 entire string is returned.
Example:
strSubstr = Right$("Visual Basic", 3)   ' strSubstr = "sic"

' Note that the same thing could be accomplished with Mid$:
strSubstr = Mid$("Visual Basic", 10, 3)


Function:
UCase$ (or UCase)
Description:
Converts all lowercase letters in a string to uppercase. Any existing
 uppercase letters and non-alpha characters remain unchanged.
Syntax:
UCase$(string)
Example:
strNew = UCase$("Visual Basic")     ' strNew = "VISUAL BASIC"


Function:
LCase$ (or LCase)
Description:
Converts all uppercase letters in a string to lowercase. Any existing
 lowercase letters and non-alpha characters remain unchanged.
Syntax:
LCase$(string)
Example:
strNew = LCase$("Visual Basic")     ' strNew = "visual basic"


Function:
Instr
Description:
Returns a Long specifying the position of one string within another.
The search starts either at the first character position or at the 
position specified by the start argument, and proceeds forward
 toward the end of the string (stopping when either string2 is found
 or when the end of the string1 is reached).
Syntax:
InStr([start,] string1, string2 [, compare])
The InStr function syntax has these parts:
start Optional. Numeric expression that sets the starting position
for each search. If omitted, search begins at the first character
position. The start argument is required if compare is specified.
string1 Required. String expression being searched.
string2 Required. String expression sought.
compare Optional; numeric. A value of 0 (the default) specifies
binary (case-sensitive) search. A value of 1 specifies a
textual (case-insensitive) search.
Examples:
lngPos = Instr("Visual Basic", "a")
' lngPos = 5

lngPos = Instr(6, "Visual Basic", "a")
' lngPos = 9       (starting at position 6)

lngPos = Instr("Visual Basic", "A")
' lngPos = 0       (case-sensitive search)

lngPos = Instr(1, "Visual Basic", "A", 1)
' lngPos = 5       (case-insensitive search)


Function:
InstrRev
Description:
Returns a Long specifying the position of one string within another.
The search starts either at the last character position or at the
position specified by the start argument, and proceeds backward
toward the beginning of the string (stopping when either string2 is
found or when the beginning of the string1 is reached).
Introduced in VB 6.
Syntax:
InStrRev(string1, string2[, start, [, compare]])
The InStr function syntax has these parts:
string1 Required. String expression being searched.
string2 Required. String expression sought.
start Optional. Numeric expression that sets the starting position for
each search. If omitted, search begins at the last character position.
compare Optional; numeric. A value of 0 (the default) specifies a
binary (case-sensitive) search.
A value of 1 specifies a textual (case-insensitive) search.
Examples:
lngPos = InstrRev("Visual Basic", "a")
' lngPos = 9

lngPos = InstrRev("Visual Basic", "a", 6)
' lngPos = 5 (starting         at position 6)

lngPos =       InstrRev("Visual Basic", "A")
' lngPos = 0         (case-sensitive search)

lngPos =       InstrRev("Visual Basic", "A", , 1)
' lngPos = 9         (case-insensitive search)
' Note that this last example leaves a placeholder for the start argument


Notes on Instr and InstrRev:
·         Something to watch out for is that while Instr and InstrRev both accomplish
the same thing (except that InstrRev processes a string from last character to first
 while Instr processes a string from first character to last), the arguments to
these functions are specified in a different order. The Instr arguments are
(start, string1, string2, compare) whereas the InstrRev arguments are
(string1, string2, start, compare).
·         The Instr function has been around since the earlier days of BASIC,
whereas InstrRev was not introduced until VB 6.
·         Built-in "vb" constants can be used for the compare argument:
vbBinaryCompare for 0 (case-sensitive search)
vbTextCompare for 1 (case-insensitive search)

Function:
String$ (or String)
Description:
Returns a string containing a repeating character string of the
length specified.
Syntax:
String$(number, character)
The String$ function syntax has these parts:
number Required; Long. Length of the returned string.
character Required; Variant. This argument can either be a number
from 0 to 255 (representing the ASCII character code* of the
character to be repeated) or a string expression whose first character
is used to build the return string.
Examples:
strTest = String$(5, "a")
' strTest = "aaaaa"

strTest = String$(5, 97)
' strTest = "aaaaa" (97 is the ASCII code for "a")


Function:
Space$ (or Space)
Description:
Returns a string containing the specified number of blank spaces.
Syntax:
Space$(number)
Where number is the number of blank spaces desired.

Examples:
strTest = Space$(5)     ' strTest = "     "


Function:
Replace$ (or Replace)
Description:
Returns a string in which a specified substring has been replaced
with another substring a specified number of times.
Introduced in VB 6.
Syntax:
Replace$(expressionfindreplacewith[, start[, count[, compare]]])
The Replace$ function syntax has these parts:
expression Required. String expression containing sub-string
to replace.
find Required. Substring being searched for.
replacewith Required. Replacement substring.
start Optional. Position within expression where sub-string
search is to begin. If omitted, 1 is assumed.
count Optional. Number of substring substitutions to perform.
If omitted, the default value is –1, which means make all
possible substitutions.
compare Optional. Numeric value indicating the kind of comparison to
use when evaluating substrings. (0 = case sensitive, 1 = case-insensitive)
Built-in "vb" constants can be used for the compare argument:
vbBinaryCompare for 0 (case-sensitive search)
vbTextCompare for 1 (case-insensitive search)
Examples:
strNewDate = Replace$("08/31/2001", "/", "-")
' strNewDate = "08-31-2001"


Function:
StrReverse$ (or StrReverse)
Description:
Returns a string in which the character order of a specified string is reversed.
Introduced in VB 6.
Syntax:
StrReverse$(string)
Examples:
strTest = StrReverse$("Visual Basic")    ' strTest = "cisaBlausiV"



Function:
LTrim$ (or LTrim)
Description:
Removes leading blank spaces from a string.
Syntax:
LTrim$(string)
Examples:
strTest =         LTrim$("  Visual Basic  ")
' strTest =         "Visual Basic  "


Function:
RTrim$ (or RTrim)
Description:
Removes trailing blank spaces from a string.
Syntax:
RTrim$(string)
Examples:
strTest = RTrim$("Visual Basic")      ' strTest = "Visual Basic"


Function:
Trim$ (or Trim)
Description:
Removes both leading and trailing blank spaces from a string.
Syntax:
Trim$(string)
Examples:
strTest = Trim$("  Visual Basic  ")   ' strTest = "Visual Basic"
' Note: Trim$(x) accomplishes the same thing as LTrim$(RTrim$(x))


Function:
Asc
Description:
Returns an Integer representing the ASCII character code corresponding
to the first letter in a string.
Syntax:
Asc(string)
Examples:
intCode = Asc("*")      ' intCode = 42
intCode = Asc("ABC")    ' intCode = 65


Function:
Chr$ (or Chr)
Description:
Returns a string containing the character associated with the specified
character code.
Syntax:
Chr$(charcode)
Where charcode is a number from 0 to 255 that identifies the character.
Examples:
strChar = Chr$(65)     ' strChar = "A"

100 Keyboard Shortcuts


100 Keyboard Shortcuts by Muhammad Waqas at muftarticles

Note: The Windows key () is located between the Ctrl and Alt keys on most keyboards. However, some vendor keyboards and laptops don't have this key. The Application key () is adjacent to the right Windows key or in the upper-right corner on some laptop keyboards.


The shortcuts Keystroke
Function
Windows                                                                                           Opens the Start menu
Windows + E
Opens Computer
Windows + R
Opens the Run dialog box
Windows + F 
Opens Search
Windows + U
Opens Ease Of Access Center
Windows + X
Open Windows Mobility Center
Windows + Ctrl + F
Opens the Find Computers dialog box
Windows + Pause/Break
Open the System page
Windows + P
Chooses a Network Projector presentation display mode
Windows + 1..0
Launches a program pinned on the Taskbar in the position indicated by the number; or accesses a running program on the Taskbar in the position indicated by the number
Windows + Shift + 1..0
Launches a new instance of a program pinned on the Taskbar in the position indicated by the number
Windows + Ctrl + 1..0
Accesses the last active instance of a program pinned on the Taskbar in the position indicated by the number
Windows + Alt + 1..0
Accesses the Jump List of a program pinned on the Taskbar in the position indicated by the number
Windows + B 
Selects the first item in the Notification Area; use the arrow keys to cycle through the items and press Enter to open the selected item.



Windows + Ctrl + B
Accesses the program that is displaying a message in the Notification Area
Windows + T 
Cycles through the items on the Taskbar
Windows + M
Minimizes all windows
Windows + Shift + M
Restores all minimized windows
Windows + D
Show/Hide Desktop (minimizes/restores all windows)
Windows + L
Locks the computer
Windows + Tab
Accesses Windows Flip 3D and cycles forward through open programs
Windows + Shift + Tab
Accesses Windows Flip 3D and cycles backward through open programs
Windows + Ctrl + Tab
Opens Windows Flip 3D as a stationary object; use the arrow keys to cycle through open programs and press Enter to access the selected program.
Windows + Spacebar
Preview Desktop (makes all open windows transparent)
Windows + G
Cycles through gadgets
Windows + Up Arrow
Maximizes the current window
Windows + Down Arrow
Minimizes/restores the current window
Windows + Home
Minimizes all but the current window
Windows + Left Arrow
Tiles the window on the left side of the screen
Windows + Right Arrow
Tiles the window on the right side of the screen
Windows + Shift + Up Arrow
Extends the current window from the top to the bottom of the screen
Windows + Shift + Left/Right Arrow
Moves the current window from one monitor to the next
Windows + F1
Launches Windows Help And Support
Alt
Displays hidden Menu Bar
Alt + D
Selects the Address Bar
Alt + P
Displays the Preview Pane in Windows Explorer
Alt + Tab
Cycles forward through open windows
Alt + Shift + Tab
Cycles backward through open windows



Alt + F4
Closes the current window; opens the Shut Down Windows dialog box from the Desktop
Alt + Spacebar
Accesses the shortcut menu for the current window
Alt + Esc
Cycles between open programs in the order they were opened
Alt + Enter
Opens the Properties dialog box of the selected item
Alt + PrtScn
Takes a screen shot of the active window and places it on the Clipboard
Alt + Up Arrow
Moves up one folder level in Windows Explorer (like the Up Arrow in XP)
Alt + Left Arrow
Displays the previous folder
Alt + Right Arrow
Displays the next folder
Shift + Insert CD/DVD
Loads CD/DVD without triggering Autoplay or Autorun
Shift + Delete
Permanently deletes the item (rather than sending it to the Recycle Bin)
Shift + F6
Cycles backward through the elements in a window or dialog box
Shift + F10
Accesses the context menu for the selected item
Shift + Tab
Cycles backward through the elements in a window or dialog box
Shift + Click
Selects a consecutive group of items
Shift + Click on a Taskbar button
Launches a new instance of a program
Shift + Right-click on a Taskbar button
Accesses the context menu for the selected item
Ctrl + A
Selects all items
Ctrl + C
Copies the selected item
Ctrl + X
Cuts the selected item
Ctrl + V
Pastes the selected item
Ctrl + D
Deletes the selected item
Ctrl + Z
Undoes an action
Ctrl + Y
Redoes an action
Ctrl + N
Opens a new window in Windows Explorer
Ctrl + W
Closes the current window in Windows Explorer

Ctrl + E
Selects the Search box in the upper-right corner of a window
Ctrl + Shift + N
Creates a new folder
Ctrl + Esc
Opens the Start menu
Ctrl + Shift + Esc
Opens the Windows Task Manager
Ctrl + Alt + Tab
Uses arrow keys to cycle through open windows
Ctrl + Alt + Delete
Accesses the Windows Security screen
Ctrl + Mouse scroll wheel
Changes the icon size on the desktop or the Views setting in Windows Explorer
Ctrl + Click
Selects multiple individual items
Ctrl + Click and drag an item
Copies that item in the same folder
Ctrl + Shift + Click and drag an item
Creates a shortcut for that item in the same folder
Ctrl + Tab
Moves forward through tabs
Ctrl + Shift + Tab
Moves backward through tabs
Ctrl + Shift + Click on a Taskbar button
Launches a new instance of a program as an Administrator
Ctrl + Click on a grouped Taskbar button
Cycles through the instances of a program in the group
F1
Displays Help
F2
Renames a file
F3
Opens Search
F4
Displays the Address Bar list
F5
Refreshes the display
F6
Cycles forward through the elements in a window or dialog box
F7
Displays the command history in a Command Prompt
F10
Displays hidden Menu Bar
F11
Toggles full screen display
Tab
Cycles forward through the elements in a window or dialog box

PrtScn
Takes a screen shot of the entire screen and places it on the Clipboard
(Application Key)
Accesses the context menu for the selected item
Home
Moves to the top of the active window
End
Moves to the bottom of the active window
Delete
Deletes the selected item
Backspace
Displays the previous folder in Windows Explorer; moves up one folder level in the Open or Save dialog box
Esc
Closes a dialog box
Num Lock Enabled + Plus (+)
Displays the contents of the selected folder
Num Lock Enabled + Minus (-)
Collapses the selected folder
Num Lock Enabled + Asterisk (*)
Expands all subfolders under the selected folder
Press Shift 5 times
Turns StickyKeys on or off
Hold down right Shift for 8 seconds
Turns FilterKeys on or off
Hold down Num Lock for 5 seconds
Turns ToggleKeys on or off