Hi,
I want to read the contents of a file if it exists, otherwise, create that file.
Using the following code, the code will look for the file Nudge.txt in your Documents folder. If it doesn't exist, it will create the file with the lines 0, 0 & 0
However, because I want the variables as Double to be used in other procedures, I added the Public declarations.
This code works without the Public declarations, but not with it.
The code gets stuck on "Line Input #1, yAdjust", which is peculiar because it's Ok with vAdjust & xAdjust. (Compile error: Type mismatch)
The code resides in Forms, but to test it, I am not calling it yet.
Any ideas please ??
I want to read the contents of a file if it exists, otherwise, create that file.
Using the following code, the code will look for the file Nudge.txt in your Documents folder. If it doesn't exist, it will create the file with the lines 0, 0 & 0
However, because I want the variables as Double to be used in other procedures, I added the Public declarations.
This code works without the Public declarations, but not with it.
The code gets stuck on "Line Input #1, yAdjust", which is peculiar because it's Ok with vAdjust & xAdjust. (Compile error: Type mismatch)
The code resides in Forms, but to test it, I am not calling it yet.
Any ideas please ??
VBA Code:
Public vAdjust, xAdjust, yAdjust As Double
Sub GetDefaults()
'
Pathname = Left(Application.StartupPath, InStr(10, Application.StartupPath, "\") - 1)
On Error Resume Next
Open Pathname & "\Documents\Nudge.txt" For Input As #1
If (InStr(1, "52,53,75,76", Err.Number) > 0) Then
On Error GoTo 0
Close #1
Open Pathname & "\Documents\Nudge.txt" For Output As #1
Write #1, 0 ' Vertical point of origin nudge
Write #1, 0 ' Horizontal nudge
Write #1, 0 ' Vertical nudge
Close #1
Else
Line Input #1, vAdjust
Line Input #1, xAdjust
Line Input #1, yAdjust
Close #1
End If
End Sub