Page 1
Page 2
Page 3
Labelling all the controls on your form
Let's now give our controls a more meaningful name.
lf we look at our code in a few months time, it will all make sense (hopefully).
Please see below a list of the controls and their new names and property
settings to which we will refer to in our code.
For the "TEXT" property for the various
controls indicated below, please make sure this property is blank. With
the "VISIBLE" property for cboCurrency, ensure you set this
property to "FALSE". The other two combo boxes (cboTo and cboFrom)
set their "STYLE" property to "2-VbDrop Down List Box.
Control
|
Name |
Text / Caption |
Property Settings |
| Text1 |
txtFrom |
delete the default text name |
|
| Label1 |
lblTo |
delete the default text name |
|
| Label2 |
lblFileDate |
delete the default text name |
|
| Combo1 |
cboFrom |
delete the default text name |
Style=2-VbDropDown list Box |
| Combo2 |
cboTo |
delete the default text name |
Style=2-VbDropDown list Box |
| Combo3 |
cboCurrency |
delete the default text name |
Visible = False |
| File1 |
File1 |
|
|
| Form1 |
FrmCurrency |
Currency Converter |
|
Once you have completed the naming of the various
controls on the form and you are happy with the form's appearance.. now
would be a good time to save your form.
Programming
Lets begin programming our Currency Converter application
control. To access the code, either double click on the form in the visual
form editor or select the form in the project explorer and click on the
View Code icon. We want our code to run as soon as the form has loaded.
To do this, we use the "Form_Load" event. Select "Form"
in the left combo box and "Load" in the right combo box. You
should see your cursor positioned in the Form_Load sub as pictured below.

Type in the following code in the Form_Load
event.
Dim myArray as Variant
Dim myString as String
Dim I as Integer
File1.Open "\My Documents\Currency\Currency.txt", fsModeInput
myArray = File1.InputFields(250)
'Populate the combo boxes with information gathered from the
textfile
For i = 0 To 249
myString = myArray(i)
If myString >= Chr(65) And myString <= Chr(90) Then
cboFrom.AddItem myString
cboTo.AddItem myString
ElseIf myString >= Chr(48) And myString <= Chr(57) Then
cboCurrency.AddItem myString
End If
Next
File1.Close 'Close the open "Currency.txt" file
lblFileDate.Caption = cboFrom.List(0)'Display current file version
'Remove the first entry from the Combo Box
cboFrom.RemoveItem (0)
cboTo.RemoveItem (0)
'Set some default Countries in the Combo Box/s
cboFrom.ListIndex = 0
cboTo.ListIndex = 1
How the code works
After we declare our variables, the following line
opens our text file ready for input from our directory location.
Dim myArray as Variant
Dim myString as String
Dim I as Integer
File1.Open "\My Documents\Currency\Currency.txt",
fsModeInput
Please Note: You will need to create a directory
"Currency" in the "My Documents" directory on you
Pocket PC. The "Currency.txt" file can be obtained from http://users.bigpond.net.au/dcarnsew/currency.txt
On our next line of code, the "InputFields"
method reads characters from the "Currency.txt" file and returns
a Variant array with a specified number of elements. "InputFields
reads a stream of characters until it finds a comma character. When it
finds a comma character, it determines the Variant type represented by
the previous characters and stores the Variant in an array element ("myArray").
"InputFields" continues reading characters and filling array
elements until the specified number of array elements is filled.
myArray = File1.InputFields(250)
Previous Page
Next Page