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!

Get random in VB6

Status
Not open for further replies.

robertgenova

Programmer
Jan 24, 2008
4
IT
Hi
for beginning thanks for your help!
I want to make a general program that use the "get random" but I found a problem

Infact it seem that "Get random" needs a string where put the record of the right lenght: this string MUST be of the right lenght of the record and the lenght of the string could be defined directly or only with a const
I tried to modify the string len, but program give me error

Because I want to use the same code for different files (with different record length) , is it possible to "jump" this problem?

Here a sample of my code

Const len_rec = 207 'len record + chr(13) and chr(10)
Dim FileRecord As String * len_rec
dim File_1 as string
.
.
.

Open File_1 For Random As 1 Len = len_rec
dim I as long
dim NumFile_INP as integer

I = 1
File_1 " "c:\file1.txt"
NumFile_INP = freefile
Do While True
FileRecord = Space(len_rec)
Get #NumFile_INP, I, FileRecord
If Not EOF(#NumFile_INP) Then

else
exit do
end if

I = I + 1
Loop

Close #NumFile_INP

Thanks again
 
I'm not quite sure what your asking but this may help you... Here's two samples, the first reads the entire file in one go, the other reads the file line by line

Dim intFree As Integer
Dim sText As String
Dim File_1 As String

intFree = FreeFile
File_1 = "c:\file1.txt"

Open File_1 For Binary Access Read As #intFree
sText = Space$(LOF(intFree))
Get intFree, , sText
Close #intFree
Debug.Print sText

'===================================

Dim intFree As Integer
Dim sText As String
Dim lText As String
Dim File_1 As String

intFree = FreeFile
File_1 = "c:\file1.txt"

Open File_1 For Input As #intFree
While Not EOF(intFree)
Input #intFree, lText
Debug.Print lText
sText = sText & lText
Wend
Close #intFree
Debug.Print sText
 
Thanks memememememememe for the answer

I forgot to say that the problem is that I received the file from mainframe and so they contains "strange characters" that are interpreted as "eof"

This is the reason why I need to to read each record for the right length (and I want to hange the length dinamically)

I will to use anyway your second methiod

best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top