Tuesday 24 August 2010

Visual Basic Codes (snippets)

Using the Do/Loop While structure
Option Explicit
Private Sub Command1_Click()
Dim counter As Integer
counter = 1
Do
Print counter & Space$(2);
counter = counter + 1
Loop Until counter = 10
Print
End Sub

 

Traping Error
On Error GoTo ErrHandler
ErrHandler:
MsgBox Err.Description
Resume Next
 
 
Using  Visual Basic Variables
Place three text boxes , two command buttons and three labels on a form as shown in the screen shot
Copy and paste the following code

Option Explicit
Dim First As String
Dim Last As String
Dim Combined As String

Private Sub Command1_Click()
First = Text1.Text
Last = Text2.Text
Combined = First & " " & Last
Text3.Text = Combined
End Sub

Private Sub Command2_Click()
End
End Sub

ScreenShot

Visual Basic Codes (complete project)

Notepad-like Editor
This is an implementation of Notepad in VB. Good introduction for beginners who want to get started with document editors.
Screen shot


Search Directories or Hard Drive for Picture Files
PicFinder is a utility program that search the selected directory or drive for picture files (i.e., files with the extension .gif, .jpg, .bmp, .ico, or .wmf.). Found pictures are displayed in a list box and you can preview each one. 
Screenshot




Clock Screen Saver
Compile this project with a .scr extension, copy it to your windows directory and it works as a screen saver that displays the time.
Screenshot
  

Contact Manager Using Random Access Files
This is an address book that uses Random Access Files instead of a database to store information. It also includes a simple memo module (which also uses random access files) and a calculator.
Screenshot
 

Folder Browsing and Manipulation Application
This application lets you browse folder and files on your system, view folder properties, and create or delete folders. A good demo of the use of Drive, Directory, and File List Boxes.
Screenshot
 

Search For, Preview, and Open Files
Nice utility to search for files, preview those found and open them in an associated application. Demonstrates numerous useful API functions and a possible alternative to the Windows search utility.
Screenshot