Title: Kung Hei Fat Choi Welcome Back' Todays Lecture: Introduction to Functions , Use of Secondary Storage
1Kung Hei Fat Choi! Welcome Back. Todays
Lecture Introduction to Functions , Use of
Secondary Storage -Files- , a further explanation
of Variables and more VBScript
2As stated in Lecture 3 Files will be covered in
lecture in around two week Review from Lecture
3!
- Files are important to be able to setup record
keeping systems. - Today Ill introduce them in lecture since we
need to assure that you understand the concepts. - Will be very important for your class project.
3Steps in Reading Data from Files
- 1. Choose a number to be the reference number for
the file - 2. Execute an Open statement
- 3. Read the data sequentially using Input
statements - 4. Close the file
4Example of Reading from a File
- Open DATA.TXT For Input As 1
- Input 1, num1
- Input 1, num2
- Close 1
5Example of Reading from a File
- Open DATA.TXT For Input As 1 Input 1,
num1, num2 picOutput.Print num1num2 - Close 1
6Tutorial
- We will go thought the tutorial together,
- The first tutorial is Chapter 14 of the new
online text. http//www.vbtutor.net/lesson14.html
7The program to Create A text File From the
on-lime tutorial
- Private Sub create_Click() Dim intMsg As String
Dim StudentName As String - Open "c\My Documents\sample.txt" For Output As
1 intMsg MsgBox("File sample.txt opened")
intMsg MsgBox("File sample.txt opened") Print
1, StudentName intMsg MsgBox("Writing a"
StudentName " to sample.txt ") - Close 1
- intMsg MsgBox("File sample.txt closed")
- End Sub
8Dim Statements
- The first two statements in our tutorial program
is - Dim intMsg As String
- Dim StudentName As String
- As we have seen in lecture 3, the Dim statement
is used to declare variables, for a complete
explanation of variable go to the following
hyperlink and read through - http//www.vbtutor.net/lesson5.html
9This program introduces two new features -
MsgBox and InputBox
- In our progam for today we see the statement
- intMsg MsgBox("File sample.txt opened")
- When this code is executed it will cause a box to
appear on the screen with the message - File sample.txt opened
- For an explanation fo MsgBox and InputBox
functions, go to the following hyperlink - http//www.vbtutor.net/lesson10.html
10InputBox
- The InputBox gives us a way to input data into a
file. In our program the code - intMsg MsgBox("File sample.txt opened")
- This will give us a InputBox on our screen to
accept data
11Let us now get the program to work
- The first place we have to modify is the path to
where we want to save the file in Secondary
storage - Open "c\My Documents\sample.txt" For Output As
1
12Upon finishing the program,
- try and get the second program of the tutorial,
the read program to work on your own - Private Sub Reading_Click() Dim variable1 As
String Open "c\My Documents\sample.txt" For
Input As 1 Input 1, variable1 Text1.Text
variable1 Close 1 - End Sub
- Go to the hyperlink http//www.vbtutor.net/lesson
14.html
13VB ability to Access and Manage Data Bases
- If you create a data base with MS Access, Dbase,
Paradox and etc you can use VB to Access and
manage the data base - VB is a tool that makes great user interfaces and
the tools mentioned above specialize in making
data Bases.
14Let us examine how we can access an existing
data base
- Go to the document at the hyperlink
- http//www.vbtutor.net/lesson19.html
- Let us go through the tutorial together
15For you final tutorial today, go to our first
on-line textbook
- Go to the lesson on File System Controls
- http//www.kcl.ac.uk/lifelong/vb6/default.htm
- Today we will do only the 1.0 of the tutorial and
I will guide you through the tutorial.
16VBScript for today!
- Let take up VBScript again by going to an online
exercise again. - Let us go to And do the exercise together and
see the results - http//www.intranetjournal.com/corner/wrox/progref
/vbt/ch21_17_first_ex.shtml
17Some things to note!
- In html we have declared a forms as follows
- ltFORM NAME"frmExercise1"gt
- ltINPUT TYPE"Button" NAME"cmdClickMe" VALUE"Clic
k Me"gt - lt/FORMgt
- We use the MsgBox the same way in VBScript as in
VB 6.0 - MsgBox "A simple example of VBScript in action."
18Now you go to the next lesson and do it on your
own.
- Do the lesson, but first let me explain Arrays
- An array is another name for a table. In the
example of the lesson we have the statements Dim
States (50) which will set aside 51 locations to
put in state names. - It is explained that VB is a Because VBScript
arrays are zero-based (starts with the first
element of the array addressed as (0)!
19- In addition, we can have multiple dimensions
VBScript Arrays. - For the example, Dim StateInfo(50,1) is a two
dimension array. - Exampe of address is StateInfo(18,0) "Michigan"
- StateInfo(18,1) "Lansing"
- VB supports up to 60 dimensions.
- Go to the Hyperlinkand do the tutorial
- http//www.intranetjournal.com/corner/wrox/progref
/vbt/ch21_18.shtml
20Conclusions of Todays Lecture
- VB is a powerful user interface tool but does not
have good secondary storage handling capability. - VBScript uses many of the same objects but not
able to define them in an IDE (you normally have
to code in html. - Enough information for the first day after a
holiday week, any questions?