Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
Public Declare Function stCheckSign Lib "NEWSTSIGN.dll" (ByVal szpath As String) As Integer

Form1 code is

VB
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

VB
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]
Posted
Updated 3-Jul-11 18:37pm
v4
Comments
Christian Graus 3-Jul-11 22:46pm    
Can someone explain to me why anyone would use VB6 in this day and age ?

1 solution

Try an experiment:
Add the code from your Form 1 Command1_click function to your Form 2 Comand_Click.
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 strFileToOpen
MsgBox spath
MsgBox Module1.stCheckSign(strFileToOpen)
MsgBox Module1.stCheckSign(spath)
End Sub

Now look at the values you are getting: each pair should be identical
 
Share this answer
 
Comments
asmanu 22-Apr-11 5:30am    
Out put of above is

C:\Users\anand.sharma\Desktop\Sign\1011200218.mll
C:\Users\anand.sharma\Desktop\Sign\1011200218.mll
-20669
-20669

but if I reverse the function call

like this

Public spath As String

Private Sub Command1_Click()
Debug.Print spath
Debug.Print Module1.stCheckSign(spath)

Dim strFileToOpen As String
With CommonDialog1
.CancelError = True
.InitDir = mstrLastDir
.Flags = cdlOFNHideReadOnly & &H8
.FileName = ""
.Filter = "Text Files(*.mll)|*.txt|All Files(*.*)|*.*"
.ShowOpen
strFileToOpen = .FileName
End With

Debug.Print strFileToOpen
Debug.Print Module1.stCheckSign(strFileToOpen)
End Sub

Then the output is

C:\Users\anand.sharma\Desktop\Sign\1011200218.mll
0
C:\Users\anand.sharma\Desktop\Sign\1011200218.mll
-20669
OriginalGriff 22-Apr-11 5:48am    
Interesting. Do you have the source for the stCheckSign function in NEWSTSIGN.DLL?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900