VB 6公共控件打开对话框出现问题,请帮助 [英] Weard problem with VB 6 common control open dialog please help
问题描述
有人可以帮助我理解为什么VB对话框控件正在执行此操作吗.
我有2个表格和1个模块
Form1
Form2
Module1
Module1代码为
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代码是
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
表格2的代码是
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
当我以启动代码的形式运行项目Form 2时,stCheckSign函数的返回值为0
但是,如果我从表单1运行项目并从路径中选择文件,则返回值将更改为-22669
两种代码都在做相同的事情,唯一的区别是Form1从公共对话框show open命令获取文件路径参数,而Form 2中的路径是硬编码的.
每当您单击显示打开对话框上的打开按钮时,我都无法理解返回值会发生变化.同样,一旦将值更改为-22669,Form2也不起作用,我需要关闭该项目并重新打开它,Form 2才能再次起作用.
谁能告诉我为什么常见的对话框打开按钮弄乱了strCheckSign函数的返回值吗?
[edit]已添加代码块-OriginalGriff [/edit]
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]
推荐答案
尝试实验:
将代码从Form 1 Command1_click函数添加到Form 2 Comand_Click.
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
这篇关于VB 6公共控件打开对话框出现问题,请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!