The actuall dll code is rather long, but the calling routine is as follows
Private Declare Sub ParseBDF Lib _
"C:\MyDllLibrary\BDF Parser\BDFParserDLL.dll" _
(ByVal FName As String) ', ByRef Gctr As Integer)
Sub Main()
Dim FName As String
If Command$ <> "" Then
FName = Command$
Else
With Form1.CD1
.FileName = ""
.CancelError = True
.DialogTitle = "Select BDF File"
.Filter = "Bulk Data File (*.bdf)|*.bdf|All Files (*.*)|*.*"
.Flags = cdlOFNFileMustExist Or cdlOFNExplorer Or cdlOFNLongNames
.ShowOpen
FName = .FileName
End With
End If
MsgBox (FName)
ParseBDF FName ', Gctr)
Stop
End Sub
The dll starts as follows
Sub ParseBDF(ByVal FName As String) ', ByRef Gctr As Integer)
Dim FNum As Integer: FNum = FreeFile
Dim TStr As String
Dim tmpstr As String
Dim tmplen1 As Integer
Dim tmplen2 As Integer
Dim comlen1 As Integer
Dim comlen2 As Integer
Dim FileType As String * 3
Dim LineType As String
Erase Grid
Gctr = 0: Pctr = 0: Mctr = 0
Close FNum
Open FName For Input As FNum
Sub ParseBDF(ByVal FName As String) ', ByRef Gctr As Integer)
Dim FNum As Integer: FNum = FreeFile
Dim TStr As String
Dim tmpstr As String
Dim tmplen1 As Integer
Dim tmplen2 As Integer
Dim comlen1 As Integer
Dim comlen2 As Integer
Dim FileType As String * 3
Dim LineType As String
Erase Grid
Gctr = 0: Pctr = 0: Mctr = 0
Close FNum <----------------------- REMOVE THIS LINE
Open FName For Input As FNum
Line Input #FNum, TStr
...
CLOSE FNUM <----------------------- Place it here..
End Sub
Freefile will give you the next available free file number .. Closing this file number may be causing your problem..
Erase Grid
Gctr = 0: Pctr = 0: Mctr = 0
Close FNum
Open FName For Input As FNum
Line Input #FNum, TStr
in the DLL part, How can you close anything that has not been opened yet.
Before closing the File, you need to open it. And your function doesn't open anything prior to Close FNum statement.
try doing this instead.
Code:
Erase Grid
Gctr = 0: Pctr = 0: Mctr = 0
Open FName For Input As FNum
Line Input #FNum, TStr
...
Close FNum
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
Actually, the close FNum statement is not the culprit. I added a message box after that line to see what FName is, and it comes up ?????????. However, just before calling the dll I have teh same message box and FName is correct. Any thoughts?
Well i wrote a small program and it seems Close statement in the above posted code will not give this error. There seems to be some other problem.
Not sure if you can step through the DLL. As your function (in the DLL) is not a big one, you can put simple Message Boxes after each statement and then you will be able to know which statement is actually erroring out.
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
End Sub
Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
Sheets("CUTTING").Select
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
Please go back and reformat your code. Use CODE TAGS, and also include the connection information that you are using. You need to use 'late-binding' so that you can use any version of a product.
Code:
Option Explicit
' These are both examples of Late Binding
Public Sub RunAccessMacro(strDB As String, strMacro As String)
'================================================================
'for late binding declare it As Object and use CreateObject() function
Dim AccessDB As Object
Set AccessDB = CreateObject("Access.Application")
With AccessDB
.OpenCurrentDatabase strDB
.DoCmd.RunMacro strMacro, 1
'.Visible = True 'you decide
.CloseCurrentDatabase
End With
Set AccessDB = Nothing
End Sub
Public Sub ExcelMacro()
Dim excl As Object
Dim wrbk As Object
Set excl = CreateObject("Excel.Application")
excl.DisplayAlerts = False
Set wrbk = excl.Workbooks.Open("myfile", , True, , "mypassword")
excl.Run "MacroName", "arg1", "arg2"
End Sub
have the same problem with the following piece of code help plz i have over 1000 lines code working already aand really need this bit to work but cant work it out :
Code:
frm_winnings.lblnumbers_matched = ("you have matched " & result & "numbers")
Select Case result
Case result < 3
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #1
winnings(1) = Input(LOF(6), 1)
Close #1
Case result = 3
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #2
winnings(2) = Input(LOF(6), 2)
Close #2
Case result = 4
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #3
winnings(3) = Input(LOF(6), 3)
Close #3
Case result = 5
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #4
winnings(4) = Input(LOF(6), 4)
Close #4
Case result = 6
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #5
winnings(5) = Input(LOF(6), 5)
Close #5
Case result = 7
Open "N:\Computing\Advanced Higher Computing\Software Development\winnings.txt" For Input As #6
winnings(6) = Input(LOF(6), 6)
Close #6
End Select
End Sub
Bookmarks