Download presentation
Presentation is loading. Please wait.
Published byMonica Hunter Modified over 9 years ago
1
1 Record Structured Data
2
We now look at actual record structured data. Using our dimensions example: struct name { membertype membername;...... }; struct dimensions{ int length; int width; int area; }; [Public | Private] Structure name Dim elementname As elementtype...... End Structure Structure dimensions Dim length as Integer Dim width as Integer Dim area as Integer End Structure 2 c/c++VB
3
We now look at actual record structured data. Using our dimensions example: struct dimensions{ int length; int width int area; }; dimensions livingRoom; dimensions rooms[9];... livingRoom.length=20; rooms[5].width=12; Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Dim livingRoom As dimensions Dim rooms(9) As dimensions... livingRoom.length = 20 rooms(5).width = 12 3 c/c++VB Index goes here not there Like c/c++, the index goes here
4
4. Dim myRooms As dimensions Dim record, fields(1) As String Dim inFile As StreamReader Dim outFile As StreamWriter inFile = File.OpenText (“measures.csv”) outFile = File.CreateText (“results.csv”) Do While (inFile.Peek <> -1) record = infile.ReadLine fields = Split(record,”,”) myRooms.length = Cint(fields(0)) myRooms.width = Cint(fields(1)) myRooms.area = myRooms.length * myRooms.width outFile.Write(myRooms.length & ”,”) outFile.Write(myRooms.width & ”,”) outFile.WriteLine(myRooms.area) Loop inFile.close() outFile.close(). Dim record, fields(1) As String Dim length, width, area As Integer Dim inFile As StreamReader Dim outFile As StreamWriter inFile = File.OpenText (“measures.csv”) outFile = File.CreateText (“results.csv”) Do While (inFile.Peek <> -1) record = infile.ReadLine fields = Split(record,”,”) length = Cint(fields(0)) width = Cint(fields(1)) area = length * width outFile.Write(length & ”,”) outFile.Write(width & ”,”) outFile.WriteLine(area) Loop inFile.close() outFile.close() Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure
5
When copying data: 5 Looks like more work, so why should we use structured data? Dim mylength, yourlength As Integer Dim mywidth, yourwidth As Integer Dim myarea, yourarea As Integer mylength = 100 mywidth = 50 myarea = mylength * mywidth yourlength = mylength yourwidth = mywidth yourarea = myarea Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Dim myroom, yourroom As dimensions myroom.length = 100 myroom.width = 50 myroom.area = myroom.length * myroom.width yourroom = myroom UnstructuredStructured
6
When working with multiple-related arrays: 6 Looks like more work, so why should we use structured data? Dim length(99) Dim width(99 Dim area(99) …length(i)… …width(i)… …area(i)… Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Dim rooms(99) …room(i).length… …room(i).width… …room(i).area… UnstructuredStructured.................. length width area.................. rooms.length.width.area
7
When working with files: 7 Looks like more work, so why should we use structured data? Dim length(99) Dim width(99 Dim area(99) …length(i)… …width(i)… …area(i)… outFile.WriteLine(length(i)) outFile.WriteLine(width(i)) outFile.WriteLine(area(i)) Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Dim rooms(99) …room(i).length… …room(i).width… …room(i).area… outFile.WriteLine(rooms(i)) UnstructuredStructured This will not work!!! Since outFile would have been declared as a StreamWriter for TEXT files.
8
Open: FileOpen (fileReferenceNumber, fileName, mode[,,, RecordLength]) FileOpen(1,"testingstruc",OpenMode.Random,,,Len(rooms(0))) Transfer: FileGet(fileReferenceNumber, data) FileGet(1,rooms(i)) FilePut(fileReferenceNumber, data) FilePut(2,rooms(i)) Close: FileClose(fileReferenceNumber) FileClose(3) 8 Looks like more work, so why should we use structured data? To read/write structured data, we have to use a different File I/O Class I got an exception when opening an input file with OpenMode.Input and an output file with OpenMode.Output. To learn more about FileOpen and the other parameters, use HelpHelp To learn more about FileOpen and the other parameters, use HelpHelp The Len function tells the size (in bytes) of the structure The Len function tells the size (in bytes) of the structure
9
9 Looks like more work, so why should we use structured data? Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Dim rooms(99) …room(i).length… …room(i).width… …room(i).area… outFile.WriteLine(rooms(i)) FileOpen(1,"testingstruc",OpenMode.Random) FileClose(1) FilePut(1,rooms(i)) When working with files: When working with random access files, the records MUST be the same size. Since all the fields in dimensions are Integer, this is not a problem. We will address the problem that occurs with strings in the next assignment! When working with random access files, the records MUST be the same size. Since all the fields in dimensions are Integer, this is not a problem. We will address the problem that occurs with strings in the next assignment!
10
10 Sharing
11
11 Multiple Forms and Modules
12
Sharing Properties Variables Constants Structures 12 When you have two or more forms, it is quite common to share information amoung these forms. This information can be:
13
Properties 13 Preface the object name with the form name: Brown frmExample txtName frmMain
14
Variables 14 Preface the variable name with the form name in which it is declared: Public x As Integer. outFile.WriteLine(x). frmExample. frmExample.x = 25. frmMain Cannot be Dim or Private
15
Variables 15 Create a module and place global (Public) declarations there:. frmExample.x = 25. frmMain Public x As Integer. outFile.WriteLine(x). frmExample MyModule Public x As Integer. x = 25
16
Constants 16 Same as variables: MyModule Public x As Integer. Public Constant noOfStudents = 25
17
Structures 17 Same as variables: MyModule Public x As Integer Public Constant noOfStudents = 25. Public Structure dimensions Dim length As Integer Dim width As Integer Dim area As Integer End Structure Public rooms(99) As dimensions
18
18 Hide & Seek Show
19
Viewing Multiple Forms 19 frmExample.Show() ‘frmExample.ShowDialog() ‘frmExample.Visible = True Me.Hide() ‘Me.Visible = False frmMain. frmMain.Show() ‘frmMain.ShowDialog() ‘frmMain.Visible = True Me.Hide() ‘Me.Visible = False. frmExample Modeless Modal Setting the visibility is equivalent to Show() or Hide() Setting the visibility is equivalent to Show() or Hide() Note: Always show the other form before hiding the current one Note: Always show the other form before hiding the current one
20
Which Form Starts Up First? 20 The one you create first, hopefully frmMain If not, then … Double-click
21
Read the Description of Assigment-6 21
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.