Can someone help me understand this why VB dialog control is doing this.
I have 2 Forms and 1 Module
Form1
Form2
Module1
Module1 code is
Public Declare Function stCheckSign Lib "NEWSTSIGN.dll" (ByVal szpath As String) As Integer
Form1 code is
Private Sub Command1_Click()
Dim strFileToOpen As String
On Error GoTo Command1_Click_Exit
With CommonDialog1
.CancelError = True
.InitDir = mstrLastDir
.Flags = cdlOFNHideReadOnly & &H8
.FileName = ""
.Filter = "Text Files(*.mll)|*.txt|All Files(*.*)|*.*"
.ShowOpen
strFileToOpen = .FileName
End With
On Error GoTo Command1_Click_Error
MsgBox Module1.stCheckSign(strFileToOpen)
Exit Sub
Command1_Click_Error:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Open Error"
Command1_Click_Exit:
End Sub
Form 2 code is
Public spath As String
Private Sub Command1_Click()
MsgBox Module1.stCheckSign(spath)
End Sub
Private Sub Form_Load()
spath = C:\Users\anand.sharma\Desktop\Sign\1011200218.mll
End Sub
When I run the project Form 2 as start-up code works and the return value come 0 from the stCheckSign function
But if I run the project from form 1 and selects the file from the path the return value changes to -22669
Both code are doing the same thing only the difference is Form1 is getting the file path arrgument from common dialog show open command and in Form 2 the path is hardcoded.
I can't able to understand the return value gets changed whenever you click on open button on the show open dialog. Also once the value is changed to -22669 Form2 also does not work and I need to close the project and reopen it for Form 2 to work again.
Can anyone show me some light why the common dialog open button is messing the return value of strCheckSign function?
[edit]Code block added - OriginalGriff[/edit]