I am using text files to store data... which has 2 values...
1st is an Integer max is 400 and second value is text..which is the file path... (for eg: a record is like: 1, "c:\somedir\somefolder\somefile.jpg")
Now i want to convert from text file to random file...!!
Can anyone tell me how will i read and write to a random access file..and one more problem.. in random files the field size has to be defined..so if like the size of the file path is greater than the specified value what will happen ...or how can i overcome this problem..!
Type Customer
FirstName as string * 20
Age as integer
End Type
Now in your form, this is how you would write to the file.
Code:
Dim aCust as Customer 'Links back to module file
Open "C:\Random.txt" for Random as 1 len = len(aCust)
recnum = LOF(1) / len(aCust) 'Sees how many Customers entered
x = recnum + 1 'Makes the store slot the next slot after the last Customer
txtFirstName.text = Cust.FirstName 'Stores the text in aCust.FirstName
txtAge.text = aCust.Age
Put #1, x, aCust 'Stores the above 2 lines in the file.
Close #1
Here is how to retrieve
Code:
Dim aCust as Customer 'Links back to module file
Open "C:\Random.txt" for Random as 1 len = len(aCust)
recnum = LOF(1) / len(aCust)
Do until x = recnum 'Loop till last Customer
x = x + 1
Get #1, x, aCust
List1.additem aCust.FirstName
list2.additem aCust.Age
'This will retrieve all the Details into a listbox. Remeber how you
'made "Firstname * 20" in the module? That means it will store
'20 characters. If you dont meet those 20 characters it will add
'spaces at the end of it equals 20. So "Joe" will be saved
'as "Joe ".
'So to you want to check the text that a user has inputed 'with 'the text in the file, you will have to use the trim() function.
Close #1
Search for "Random Access File" and you will find a thread i started with 2 programs i made attacked in some of the posts.
They will show you what i've just explained.
nice idea CRB but there's a small problem...like what if user has selected a file which is located in so many sub folder...then i won't be able to set that if its longer than the defined size!
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe