Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Conversion...


Reply
 
Thread Tools Display Modes
  #1  
Old 10-07-2002, 04:36 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default Conversion...


Boo!

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

Thanks!
Reply With Quote
  #2  
Old 10-07-2002, 06:01 AM
juvestar15 juvestar15 is offline
Regular
 
Join Date: Aug 2002
Posts: 83
Default

Make a Module and enter this into it.

Code:
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.
Reply With Quote
  #3  
Old 10-07-2002, 06:12 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

Hi!

You have defined the size of the field in the following code:

Code:
Type Customer
FirstName As String * 20
Age As Integer
End Type
what if i don't know the exact size coz its going to be changed everytime...
__________________
Holla! If ya hear me!
Reply With Quote
  #4  
Old 10-07-2002, 07:39 AM
randtek's Avatar
randtek randtek is offline
Contributor
 
Join Date: Jun 2002
Location: the Milky Way Galaxy
Posts: 525
Default

You need to set the size of the string to the largest size you expect to see in this field (or slightly larger).
__________________
Murphy was an optimist!
Reply With Quote
  #5  
Old 10-08-2002, 04:53 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

then i think this is not possible!
__________________
Holla! If ya hear me!
Reply With Quote
  #6  
Old 10-08-2002, 09:07 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Just create the field large enough for most filenames, or convert
the filenames to DOS short paths using the GetShortPathName API.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #7  
Old 10-09-2002, 06:35 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

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!
__________________
Holla! If ya hear me!
Reply With Quote
  #8  
Old 10-09-2002, 10:50 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Convert ALL paths to short paths, without checking them first.
Then write them to the file - no problems..
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #9  
Old 10-10-2002, 02:23 AM
RemoteHoax RemoteHoax is offline
Centurion
 
Join Date: Sep 2002
Location: Chandigarh
Posts: 143
Default

heh ok thanks!
__________________
Holla! If ya hear me!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
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
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->