1 / 15

المحاضرة السادسة

المحاضرة السادسة. التعامل مع الملفات Files in Visual Basic By Hitham M. Abo Bakr. In This Lecture. INTRODUCTION SEQUENTIAL FILE HANDLING SEQUENTIAL FILE HANDLING FUNCTIONS SEQUENTIAL FILE HANDLING EXAMPLES SOME FILE MANUPULATION FUNCTIONS. Introduction.

toki
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 By Hitham M. Abo Bakr

  2. In This Lecture INTRODUCTION SEQUENTIAL FILE HANDLING SEQUENTIAL FILE HANDLING FUNCTIONS SEQUENTIAL FILE HANDLING EXAMPLES SOME FILE MANUPULATION FUNCTIONS

  3. Introduction • As far as Visual Basic 6 is concerned, there are three modes in which a file canbe accessed. • Text Mode (Sequential Mode) • Random Access Mode • Binary Mode

  4. Text Mode and Binary Mode In the Text Mode, data is ALWAYS written and retrieved as CHARACTERS. Hence, any number written in this mode will result in the ASCII Value of the number being stored. In the Binary Mode, everything is written and retrieved as a Number.Hence, The Number 17 Will be stored as [ 17 ] in this mode andcharacters will be represented by their ASCII Value as always.

  5. Random Access Mode Just like the Binary Mode, the Random Access Mode allows us to gain instant access to any piece of information lying anywhere in the file at a cost.In this case, we must standardize each piece of information. Random Access Mode allows us to read or write data at a particular record position rather than a byte position like in Binary Mode.

  6. SEQUENTIAL FILE HANDLING • To open a File in Sequential Mode, we need to use the Open Command like this: Open <FILENAME> For <MODE> As <FILE#> • FILENAME : Contains the Path of the File to be opened. • MODE : Can be INPUT, OUTPUT or APPEND • FILE# : Any number from 1 to 255 preceded by a #

  7. Open File Mode INPUT -> Used to Read From a File.OUTPUT -> Used to Write to a File. (Remove Old file if Exist)APPEND -> Used to Write to a File. (Appensd on Old File if Exist)

  8. Open and Close the File • to open a file Contacts.txt in Input Mode we use the Open Command like this: • Open "C:\Contacts.txt" For Input as #1 • Notice that the path of the file is mentioned. If the path is not mentioned, Visual BASIC assumes the file to be in the current directory. • To close the file we use the CLOSE Command like this • Close #1

  9. Examples C:\Contacts.txt" Dim tmp as String Open "C:\Contacts.txt" For Input as #1 Line Input #1, tmp Close #1 Msgboxtmp "Sanchit",9811122233 "Friend",9812345634 "Enemy",9821630236 Dim tmp as String, contents as String Open "C:\Contacts.txt" For Input as #1 While Eof(1) = 0 line input #1,tmp contents = contents + tmp Wend Close #1 Msgbox contents the Message Box displays: "Sanchit",9811122233

  10. Separate Two fields into Two Variables Input #1, strname, lngphone Msgbox "Name = "+strname Msgbox "Phone = "+Str(lngphone)

  11. Writing In Sequential Files My Phone number is 12345678  910 "My Phone number is 12345678",910 We Use Either Write or print Open "C:\names_database.txt" For Output As #1 Print #1, "My Phone number is 12345678", 910 Write #1, "My Phone number is 12345678", 910 Close #1 End What is the difference between Write and Print Print saves the text without separators like “ ” for string or # # for Date and but write do that..

  12. Examples See Examples

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

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

  15. Thanks

More Related