Thursday, May 27, 2010

Search for text files in your drives and display them

This program let you choose your drives and folders and displays all the text files from the chosen folder in a list box. You need to place a combo box, a DriveListBox, a DirListbox and a Listbox into your form.
The code is as follows:

Private Sub Form_Load()
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2
Combo1.Text = "All Text Files"
Combo1.AddItem "All Text Files"
Combo1.AddItem "All Files"
End Sub

Private Sub Combo1_Change()
If ListIndex = 0 Then
File1.Pattern = ("*.txt")
Else
Fiel1.Pattern = ("*.*")
End If
End Sub

Scientific Calculator

The value of pi is now obtained by using the Atn function (Arc Tangent). We know that Tan(pi/4)=1, so Atn(1)=pi/4, therefore pi=Atn(1)*4. By using this function, we will obtain a more accurate value of pi. 

In this project, we shall also limit the numbers to be less than 30 digit. If any user enters a number with more than 30 digits, an error message "data overflow" will be shown. 
The Interface:

Excel VBA Objects

Most programming languages today deal with objects, a concept called object oriented programming. Although Excel VBA is not a truly object oriented programming language, it does deal with objects. VBA object is something like a tool or a thing that has certain functions and properties, and can contain data. For example, an Excel Worksheet is an object, cell in a worksheet is an object, range of cells is an object, font of a cell is an object, a command button is an object, and a text box is an object and more.

An Excel VBA object has properties and methods. Properties are like the characteristics or attributes of an object. For example, Range is an Excel VBA object and one of its properties is value. We connect an object to its property by a period(a dot or full stop). The following example shows how we connect the property value to the Range object.

InputBox and MsgBox

The InputBox function and the MsgBox function are two very important functions in VB. The InputBox function is to accept data from the user and the MsgBox function is to output data to the user. They are considered a form of simple dialog box for the user to interact with the VB program.
The Inputbox function with return a value of any data type, which means the value could be integer,single, string, boolean ,data and more. Normally you need to declare the data type for values to be accepted in the Inputbox. 

Example:
Dim StudentName As String
Dim Mark As Integer
StudentName=InputBox("Enter Student Name")
Mark=InputBox("Enter Student Mark")