|
-
Jul 4th, 2003, 08:48 AM
#1
Thread Starter
New Member
accessing text files within dll's
I have written a program where I have opened a text file as #1 ie.
Open MyFile for Input as #1
..and then tried to reference it in a dll thatI had written earlier:
InRec = bu.GetRec(1,10,EndOfFile)
where the first parameter (ie. 1) is the unit number of the file that I have opened, and the second parameter is the ASCII code used as a record delimiter in this file.
However when I call the dll I get 'bad file name or number' even though if I include the class module that contained the source code in my project it works OK.
I can only conclude that the refence to #1 does not carry through to the dll. Is there a way around this apart from opening the file from within the dll itself?
-
Jul 4th, 2003, 12:36 PM
#2
Fanatic Member
Could you please post your code for the subroutine or function that is opening the file and making the call to the dll. Also post your code for the dll. I will see if I can get it to work, and if not atleast others can look at your code as well and maybe fine something wrong.
-
Jul 4th, 2003, 07:23 PM
#3
in your DLL...are you trying to open the file again?
please post more code...(like th function in the DLL)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 7th, 2003, 03:52 AM
#4
Thread Starter
New Member
here is the actual code ...
This is my vb code:
Private Sub Command2_Click()
t1 = 1
t2 = 6
t3 = 35
t4 = 81
t5 = 126
NoFiles = 0
TotRecs = 0
Open "d:\xx egypt\progs\xxFiles.txt" For Input As #3
Open "d:\xx egypt\progs\xxEgypt.txt" For Output As #2
Print #2, Date, Time
Print #2, ""
Print #2, "xx Egypt file summary"
Print #2, "---------------------"
Print #2, ""
Print #2, Tab(t1); "Num"; Tab(t2); "File Name"; Tab(t3); "First Record"; _
Tab(t4); "Last Record"; Tab(t5); "Quantity"
Print #2, Tab(t1); "---"; Tab(t2); "---------"; Tab(t3); "------------"; _
Tab(t4); "-----------"; Tab(t5); "--------"
While Not EOF(3)
Line Input #3, MyFile
' set default values for first and last records in case they are not found
FirstRec = ""
LastRec = ""
Open MyPath + MyFile For Input As #1
On Error GoTo CloseFile
NoFiles = NoFiles + 1
NoRecs = 0
FirstRec = bu.GetRec(1, 10, FileEnd)
LastRec = FirstRec
NoRecs = 1
While Not FileEnd
LastRec = bu.GetRec(1, 10, FileEnd)
NoRecs = NoRecs + 1
Wend
CloseFile:
Close #1
TotRecs = TotRecs + NoRecs
Print #2, Tab(t1); bu.LpadNumber(NoFiles, 3); Tab(t2); MyFile; Tab(t3); _
FirstRec; Tab(t4); LastRec; Tab(t5); bu.LpadNumber(NoRecs, 8)
' Print #2, bu.lpadnumber(nofiles,3)+ MyFile
' Print #2, " First Record: " + FirstRec
' Print #2, " Last Record: " + LastRec
' Print #2, " No. Records: " + Str(NoRecs)
' Print #2, ""
Wend
Print #2, Tab(t1); "---------"; Tab(t5); "--------"
Print #2, Tab(t1); "TOTAL QTY"; Tab(t5); bu.LpadNumber(TotRecs, 8)
Print #2, Tab(t1); "---------"; Tab(t5); "--------"
Print #2, ""
Print #2, "***End of Report.***"
Close #2
Close #3
End Sub
Private Sub Form_Load()
MyPath = "d:\xx egypt\data\"
End Sub
and this is my dll code:
Public Function GetRec(FileNo As Long, Delimiter As Long, EndFile As Boolean) As String
Dim ThisChar As String, DChar As String
' this function reads a file opened as #FileNo until it reaches a 'Delimiter'
' character supplied by the user (as an ASCII code) and returns
' the portion of te file it has read.
' EndFile is set to True if the end of file was reached whilst searching
' for the 'Delimiter'
GetRec = ""
DChar = Chr(Delimiter)
EndFile = False
NextChar:
ThisChar = Input(1, FileNo)
If EOF(FileNo) Then
EndFile = True
If ThisChar <> DChar Then GetRec = GetRec + ThisChar
Exit Function
End If
If ThisChar = DChar Then Exit Function
GetRec = GetRec + ThisChar
GoTo NextChar
End Function
Public Function LpadNumber(InputNo As Long, TotalLength As Long) As String
Dim lp As Long
' This function converts a number (InputNo) to a string
' and left pads it with spaces to TotalLength characters
LpadNumber = Str(InputNo)
' get rid of any spaces at the start of the number from 'Str'
If Left$(LpadNumber, 1) = " " Then LpadNumber = Mid$(LpadNumber, 2)
lp = Len(LpadNumber)
If (lp >= TotalLength) Then
Exit Function
Else
LpadNumber = String$(TotalLength - lp, " ") + LpadNumber
End If
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|