1 / 21

المحاضرة العاشرة

المحاضرة العاشرة. التعامل مع الملفات وعناصر التصميم المرئي 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 )

Download Presentation

المحاضرة العاشرة

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. المحاضرة العاشرة التعامل مع الملفات وعناصر التصميم المرئي Files in Visual Basic (cont) & Visual Design Elements By Hitham M. Abo Bakr

  2. 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

  3. 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.

  4. 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

  5. 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

  6. 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

  7. Dealing with Random Files Creating Record Type Open a Random- Access file Adding and Retrieving record Seek for specific record

  8. 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)

  9. 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)

  10. 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

  11. 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&

  12. 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

  13. Visual Design Elements Chapter 6

  14. Graphics Controls Line Control

  15. Graphics Controls Shape Control

  16. Graphics Controls FALSE <<Streach>>TRUE Image Control

  17. Graphics Controls FALSE <<Auto size >>TRUE Picture Control

  18. Image Load Properties Question what is the different between : • Picture on a form, • Picture on Image control, • Picture on Picture Box?

  19. File List Box Control We can select the folder By: File1.Path = “”c:\windows”

  20. Example

  21. Thanks

More Related