Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text to Random Access

Status
Not open for further replies.

Joeb1

Technical User
Nov 13, 2000
4
US
I have a text file with items such as this:
1001
1002
1004
D1001
D1002
D1004
G1001
G1002
G1008

The number of lines in this file can potentially go to 10,000. I can already parse out the different ID's, no letter or different letters. My goal is to take this parsed data and search for missing increments.

Because text files don't lend themselves to random access, I want to load these into a random file. I could then drop the letter, change the string to a integer, add 1 to it and compare it to the second number. If equal compare the second to the third etc. etc. Once I get a <> condition change it back to a string, add the letter back and save it to a text box.

Here is a test piece of code that errors on the Put command.

I defined this type in a module then when I try to run the code below it errors out on the Put statement.

Public Type Product
ProdID As String
End Type


Dim rProdFile As Product
Dim iTest As Integer
iTest = 0
Open &quot;C:\VSS\ProdID.txt&quot; For Input As #8
Open &quot;C:\Product ID\Test.dat&quot; For Random As #9 Len = Len(rProdFile)
While Not EOF(8)
iTest = iTest + 1
sCheck = Input(6, #8)
rProdFile.ProdID = sCheck
MsgBox sCheck, rProdFile.ProdID
Put #9, iTest, rProdFile
MsgBox &quot;Record &quot;, iTest, &quot;Product &quot;, rProdFile.ProdID
Wend

Looks so simple I am missing it. I have tried defining the sCheck as a string and as a string * 6. I have also done the same with the ProdID. I was thinking there may have been a CRLF issue. The data must not jive I guess.


BTW, I use to recreational program in Pascal and I am trying to learn VB6. Got a small project I am doing and then on to a mid-size that will include using access. Then maybe a real big one if I feel energetic.

Thanks for the help.

Joeb1
 
Public Type Product
ProdID As String * 6
End Type


sCheck = Input(6, #8)
change this to
input #8, scheck

there are errors in your msgbox lines. Rem these out.



David Paulson


 
You should also consider the implication of the file manipulation process. Rember that Disk access is at least an order of magnitude slower than memory access. If you are attempting to become a programmer, you should carefully consider alternative soloutions. Placing the whole thinggy in an array in memory. Your &quot;Type&quot; could be expanded to include the various &quot;manipulations&quot; as additional members of the UDT, so you could read in the data once, do all of the manipulations - IN MEMORY.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Michael,

I guess this comes from my old timer attitude. During the DOS days memory became an issue. My array could potentially go to 10,000 strings. In the old days you could run out of space with everything else running. I will try the array.

David,

Thanks I will try the input #8,scheck

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top