怎样写一公用函数

learn_vb 2000-07-25 09:32:00
dim Con as control
for each Con in form1.controls
if typeof(Con) is textbox then
if trim(con.text)="" then
msgbox "...."
end if
end if
next
我想把它写成一个公用的函数来调用应该怎么写.
...全文
141 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mike 2000-07-25
  • 打赏
  • 举报
回复
你可以将以下代码放入一模块中:
Public Sub LookText(frmLook As Form)
Dim Con As Control
For Each Con In frmLook.Controls
If TypeOf Con Is TextBox Then
If Trim(Con.Text) = "" Then
MsgBox "....", , frmLook.Caption
End If
End If
Next
End Sub

然后在需要调用的Form中用如下语句:
LookText Me
Wingsun 2000-07-25
  • 打赏
  • 举报
回复
应该这么写:
Public Sub Procdure(frmParam as Form)
dim Con as control
for each Con in frmParam.controls
if typeof(Con) is textbox then
if trim(con.text)="" then
msgbox "...."
end if
end if
next
End Sub
TopHead 2000-07-25
  • 打赏
  • 举报
回复
应该这么写:


Public Function AAA(Para as 数据类型) as 数据类型

dim Con as control
for each Con in form1.controls
if typeof(Con) is textbox then
if trim(con.text)="" then
msgbox "...."
end if
end if
next

'如果需要返回值则
AAA=返回值

End Function


其中AAA为公用函数名,Para为参数名

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧