1303次列车为什么便宜:VB6.0的自定义函数怎么传回值?

来源:百度文库 编辑:神马品牌网 时间:2024/05/09 02:42:27
比如,我自定义了一个函数:
Public Function MBox(Line1 As String, line2 As String, lStyle As Long)
Select Case lStyle
Case 1
FrmMsg.cmdOK.Visible = True
FrmMsg.lbl1.Caption = Line1
FrmMsg.lbl2.Caption = line2
FrmMsg.Show
Case 2
FrmMsg.cmdYes.Visible = True
FrmMsg.cmdNo.Visible = True
FrmMsg.lbl1.Caption = Line1
FrmMsg.lbl2.Caption = line2
FrmMsg.Show
End Select
End Function
然后画了一个FrmMsg,上面两个lbl,两个按钮。Yes,No,这样我传过去的值,可以显示出这个Form,但是用户选了Yes或者No怎么知道?
我希望的效果是:
自己建立一个和Msgbox一摸一样的东西。

1.FrmMsg窗体增加一个整型全局变量(比如public A as integer
2.在按钮事件中加入2句,一句设置变量的值,比如
cmdyes设a=1,no设a=2,一句是me.hide
3.函数改成Public Function MBox(Line1 As String, line2 As String, lStyle As Long) as integer
4.函数的show窗体语句改成show 1 (模态窗体)
5.函数最后加入一行 MBox=FrmMsg.A就行了。

一个不是很好但可行的方法,定义一个全局变量int的g_mSelect
在FrmMsg窗体的yes按钮click事件中加入代码把g_mSelect置1,no置2,ok置3
在你的那个函数的最后加上MBox=g_mSelect
到调用这个函数的地方去判断,最好把1,2,3都用mYes,mNo,mOK代替
如下例:
if MBox("aa", "bb", 2) = mYes then
'你的代码
endif

不知道楼主的核心意思是不是在不同窗体中传递变量,如果是的话这么试试
用public定义变量
例如定义a=1 or 0表示yes or no
在主窗体中定义 public a as single
然后在FrmMsg中调用,(格式为form1.a)
用户选择完后关闭窗体不要用unload FrmMsg 用FrmMsg.hide
这样a=0还是1就传回来了.

没看到"问题补充"
如果是这样在FrmMsg中public i as string 也可以
然后在你要使用的地方调用FrmMsg.i 就可以得到i的值了。

1.FrmMsg窗体增加一个整型全局变量(比如public A as integer
2.在按钮事件中加入2句,一句设置变量的值,比如
cmdyes设a=1,no设a=2,一句是me.hide
3.函数改成Public Function MBox(Line1 As String, line2 As String, lStyle As Long) as integer
4.函数的show窗体语句改成show 1 (模态窗体)
5.函数最后加入一行 MBox=FrmMsg.A就行了。

这个样子试试看
private Function CheckNull (by val mm as integer) as Variant

if isnull(mm) then
checknull =""
else
checknull=mm
endif

用click事件来完成
双击按钮会自动生成click事件、、
在里面贴你的函数
这个事件里面的程序只有当运行中按下该按钮时运行