Username: Password: -Author Message BioHazardousWaste Posted: Wed Mar 03, 2004 10:27 pm Post subject: Tutorial Reading/Writing Random Access Files OK. Forgive me if this tutorial is not pefect, because it is the first one i've written. Here goes nothing. First off, I must warn you, this tutorial is a little advanced, containing types, records, and file handling.
![Random pdf files Random pdf files](/uploads/1/2/5/6/125623435/197110029.jpg)
So if your new to VB you will problably be confused as hell. Random Access files are VERY useful, they allow you to write huge amounts of data to a file (generally a database file), and then read certain parts of the file back in. There are three parts to a Random Access File, and I will explain them in the following order: 1) The Record(s) 2) Writing to a File 3) Reading From A File 1) The Record(s) The record is the most important part of this process. It holds all your information, in a nice easy to get to place. If you know how to create records allready, feel free to skip this part, otherwise read on.
RECORDS CANNOT BE CREATED IN A FORM!!! Never, they must be created in a module. To add a module to your project (in VB6.0 anyways) Right-Click on a blank spot in your Project Explorer, go to Add and click Module. Choose Module, click open. The code for your new module will be displayed.
In this module you must create your records. This is done using the Type and End Type command, with your variables in between.
For string variables, you must also specify how long the string is by using the. sign. For a 30 character string you would use VARNAME. 30. EXAMPLE: code. Type RecContactInfo Name as String. 75 Address as String.
75 Address2 as String. 75 PhoneNum as String. 75 CellNum as String. 75 End Type In this example we have 5 variables, Name, Address, Address2, PhoneNum, and CellNum, all strings, 75 characters long. (Note: You do not have to dim these, although you may want to in order to create arrays) The next thing you have to do, is to declare this type as a record in the general section of the form you want to handle the data in.
Ex.1- is pure Random (I think it is random, that is without delimiters) you can copy a file this way by Read and then Writing the file. Ex.2- read and write a line at a time with no delimiters ex.3 read/write of comma sepreated variable Each I would think can be accomplished with about 4-10 lines of code no more. Reading and Writing Text (formatted) Files with C library. In order to access a file, you must define a file pointer variable Defining a file pointer variable: #include FILE *fp; All file operations will need to use a file pointer to locate the file.
![Topics Topics](/uploads/1/2/5/6/125623435/236430664.png)
EXAMPLE: I want the user to enter this information into previously created textboxes in frmInfo, then save to my record. The first thing I have to do is to decleare a variable as the record.
In this case I might use code. Open (Location) For Random As # Len = Len(Record) Get # filenumber, recnumber , varname Close # Now, if you were paying attention, you would noticed that the command to save the record, and the command to open the record only differ by one word. Put has been Changed to Get. Yes, that means that as soon as you load data from a file, it overwites everything in the current record in your program. EXAMPLE: I want to return the users name that I saved to the file c: ConactInfo.dat into a textbox called Name.
To do this, the first thing I have to do is read the record from a file. And can I delete a record without rewriting the entire file? I do not know of a way to do this, if you needed to the best thing I could think of would be to have a database control program which reads in all your records, lists them in a listbox, you could then choose which ones you want to delete. Have it read the file in, then output it with everything except for the records you want to delete. Thats the only way I know of, and my manuals don't say anything about it sorry. Tony Posted: Thu Mar 04, 2004 5:22 pm Post subject: (No subject) that's alright. Guess I can't expect much from a datafile I just know that with a DB, you can just run a SQL statement to delete a record or two Tony's.
BioHazardousWaste Posted: Fri Mar 05, 2004 3:56 pm Post subject: (No subject) Its not really nessecary to delete a record, if you use WHICH record it is as a variable. Have a text box for which record spot you want to record in, and if it exists have the name in a textbox underneath it. Then, whenever you want to delete a record, just save a new one over top. Let me kno if you need code/ example proggy Display posts from previous: -Page 1 of 1 5 Posts Jump to: Style: Search.
Reading and Writing with Files Description This tutorial is an introduction to working with text files in. Gives you the ability to write information to text files and read information from text files. You can use this for logging data, giving your robot a memory, a way to read in data you might not want to ly enter in a script and anything else that your imagination might lead you to use text files for. Controls This tutorial uses the following controls: Step 1. Open a project With, locate the 'Open' icon and click it. So I did a quick experiment and here are some issues, you can add scripted data in your text file or comma separated file for an to take action on, but as you read in the lines you will assign them out to variables - which you then need to translate to an action.
I don't see a way for to understand its own scripting language from a file or to directly re-translate it. This is why in the past I have used my own short hand commands in text files for the robot to read such as: Justin Ratliff,Smile Josh,Wave DJ,Faint That data might be in text file for people my robot knows and my scripts then use IF-THEN logic to carry out other scripts and actions based on those indicators in the text file like 'Smile, Wave, Faint, etc.'