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!

Cannot Read and write a file at the same time

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
Below is the entire source, basically what I have is a *.dat file that has the structure of 'Sic2File' , I need to create a new dat file that has it's lat/lng bit as longs, and not doubles, I have a problem on the highlighted line below colored in red, the error says


Run-Time Error '5':

Invalid procedure call or argument



The Source
[tt]
Private Type Sic2File
Sic4 As Byte
latbit As Double
lngbit As Double
id As Long
End Type
Private Type Sic2Convt
Sic4 As Byte
latbit As Long
lngbit As Long
id As Long
End Type

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub


Private Sub File1_DblClick()
Dim Sic2er As Sic2File
Dim SicCvt As Sic2Convt

Dim SicFile
Dim Looper As Long

Looper = 1
If Right(File1.Path, 1) = "\" Then
Open File1.Path & File1.FileName For Random As #1 Len = Len(Sic2er)
Open File1.Path & "c_" & File1.FileName For Random As #2 Len = Len(Sic2Convt)
Else
Open File1.Path & "\" & File1.FileName For Random As #1 Len = Len(Sic2er)
Open File1.Path & "\c_" & File1.FileName For Random As #2 Len = Len(Sic2Convt)
End If

Do Until EOF(1)
Get #1, , Sic2er
'Read Data
SicCvt.id = Sic2er.id
SicCvt.latbit = Sic2er.latbit
SicCvt.lngbit = Sic2er.lngbit
SicCvt.Sic4 = Sic2er.Sic4
'Write Data
Put #2, , SicCvt
Loop
Close #1
Close #2
End Sub

[/tt]
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
hmm my bad, apparently I was supposed to use the name of the variable being referenced, not the name of the type. I thought I did that, but when I looked back over I used the wrong name.
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
I think thit is wrong :

Open File1.Path & "\c_" & File1.FileName For Random As #2 Len = Len(Sic2Convt)

most :

Open File1.Path & "c_\" & File1.FileName For Random As #2 Len = Len(Sic2Convt)
Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Actually no, because if I did it like you said
then my string would be

C:\kbstuffc_\sic.dat
not
C:\kbstuff\c_sic.dat
like I want it to be called.
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
Try using the len of the variable you have DIMmed rather than the length of the TYPE, i.e. LEN(SicCvt) not Len(Sic2Convt)

You will probably have the same problem with the other OPENs using the TYPE name instead of the VARIABLE name.

HTH

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top