210 likes | 325 Views
المحاضرة العاشرة. التعامل مع الملفات وعناصر التصميم المرئي Files in Visual Basic (cont) & Visual Design Elements By Hitham M. Abo Bakr. In the previous lecture. SEQUENTIAL FILE HANDLING Open <FILENAME> For <MODE> As <FILE #> Line Input # nfile , sString Eof ( nfile )
E N D
المحاضرة العاشرة التعامل مع الملفات وعناصر التصميم المرئي Files in Visual Basic (cont) & Visual Design Elements By Hitham M. Abo Bakr
In the previous lecture • SEQUENTIAL FILE HANDLING • Open <FILENAME> For <MODE> As <FILE#> • Line Input #nfile, sString • Eof(nfile) • Print #nfile, var1,var2,var3,..varn [;] • Write #nfile,var1,var2,var3…varn [;] (separator) • Close #nfile
SEQUENTIAL FILE HANDLING FUNCTIONS FreeFile() : Returns an Integer representing the nextfile number available for use by the Open statement. EOF() : Returns anInteger containing the Boolean value True when the end of a file opened for sequential Input has been reached. FileLen() : Returns a Long specifying the length of a file in bytes. LOF() : Returns a Long representing the size, in bytes, of a file opened using the Open statement. Seek() : Returns a Long specifying the current read/write position within a file opened using the Open statement.
Some File Manipulation Functions • Copy Files using : • FilecopySourceFile, Destination File • To Delete a file • Kill Filename • To Rename File • Name Oldname As NewName • Create new Folder • MkDirDirName
In this Lecture • Random File Access • Visual Design Elements • Graphics Controls • Line Control • Shape Control • Image and picture control • Image Load Properties • Picture on a form • Picture on Image control • Picture on Picture Box • File List Box
Random Files Sequential files have no specific record structure The structure of the sequential file is defined by the code write this file not the file itself Sequential file is easy to read but hard to search within it. In Random file: there is a specific structure for the record in the file. The search will be more effective in Random files
Dealing with Random Files Creating Record Type Open a Random- Access file Adding and Retrieving record Seek for specific record
Create Record Type Private type Employee EmpID As Integer Lname As String*10 Fname As String*10 Title As String*10 End Type Dim Emp1 As Employee Emp1.Lname = “Ahmed” Emp1.Fname = “Mohamed” Emp1.title = “Engineer” Emp1.ID = 332 Using Type statement to define the record structure Define Variable Add values to this variable (with dot operator)
Opening a Random access file Open Filename for Random As #nfilelen=len(record) To open Random file we use the following command Where len(record) : is the length of the record saved in this file E.g. if the file contains records form Employee type defined in the previous slide Len = Len(emp1)
Adding and Retrieving Records Put #nfile,[record number],variable name Get #nfile,[record number],variable name Seek #nfile,RequireRecord# • To add records to Random File we use: • To retrieve records from Random File we use: • To reach for a specific field we use
Example Private Sub Command5_Click() fHnd = FreeFile numRecs = Len(recData) Open "c:\myFile.ext" For Random As fHnd Len = numRecs numRecs = LOF(fHnd) \ numRecs For I = 1 To 2 recData.CustCode = I recData.CustFirstName = InputBox("Please enter customer first name") recData.CustLastName = InputBox("Please enter customer last name") recData.SortFlag = I + 100 Put #1, , recData Next I Close fHnd End Sub Private Type recType DeleteCode As Byte SortFlag As Byte CustCode As Long CustFirstName As String * 10 CustLastName As String * 10 End Type Dim recData As recType Dim fHnd% Dim numRecs&
Example Private Sub Command6_Click() fHnd = FreeFile numRecs = Len(recData) Open "c:\myFile.ext" For Random As fHnd Len = numRecs numRecs = LOF(fHnd) \ numRecs Get fHnd, 2, recData Close fHnd MsgBox "No Of Customers is " + str(numRecs) + vbCrLf + "Selected Customer Code is : " + str(recData.CustCode) + vbCrLf + "The Customer Name : " + recData.CustFirstName + " " + recData.CustLastName End Sub
Visual Design Elements Chapter 6
Graphics Controls Line Control
Graphics Controls Shape Control
Graphics Controls FALSE <<Streach>>TRUE Image Control
Graphics Controls FALSE <<Auto size >>TRUE Picture Control
Image Load Properties Question what is the different between : • Picture on a form, • Picture on Image control, • Picture on Picture Box?
File List Box Control We can select the folder By: File1.Path = “”c:\windows”