******************************************* 如果我要写以一段程序:Public Sub text() ………… ………… End Sub请问我应该怎么定义这个text()子函数啊? ********************************************首先说明,这个是你的自定义的通用过程,不是什么函数 你要实现什么功能的话就直接在里面写好了,跟别的基于事件的过程没多少区别 调用的时候直接写一句text就可以了,这样也行call text你最好换个过程名字,这个text可能会引起错误
VB中不用定义,调用时用 call text 就可以执行text函数了。
Public Function text()
End Function 再加上你需要的参数
過程是 sub 函數是 function ,不同是過程沒有返回值,函數有返回值無參數的過程: Private Sub CenterWindow() With frmMain .Top = (Screen.Height - .Height) / 2 .Left = (Screen.Width - .Width) / 2 End With End Sub有參數的過程: Private Sub CenterWindow(hForm As Form) With hForm .Top = (Screen.Height - .Height) / 2 .Left = (Screen.Width - .Width) / 2 End With End Sub--------------------------------------------- 無參數的函數:Private Sub Command1_Click() MsgBox Demo End SubPrivate Function Demo() As String Demo = "This is Only a Demo!" End Function有參數的函數:Private Sub Command1_Click() MsgBox Demo("This is Only a Demo!!!") End SubPrivate Function Demo(strMsg As String) As String Demo = strMsg End Function
如果我要写以一段程序:Public Sub text()
…………
…………
End Sub请问我应该怎么定义这个text()子函数啊?
********************************************首先说明,这个是你的自定义的通用过程,不是什么函数
你要实现什么功能的话就直接在里面写好了,跟别的基于事件的过程没多少区别
调用的时候直接写一句text就可以了,这样也行call text你最好换个过程名字,这个text可能会引起错误
call text 就可以执行text函数了。
End Function
再加上你需要的参数
Private Sub CenterWindow()
With frmMain
.Top = (Screen.Height - .Height) / 2
.Left = (Screen.Width - .Width) / 2
End With
End Sub有參數的過程:
Private Sub CenterWindow(hForm As Form)
With hForm
.Top = (Screen.Height - .Height) / 2
.Left = (Screen.Width - .Width) / 2
End With
End Sub---------------------------------------------
無參數的函數:Private Sub Command1_Click()
MsgBox Demo
End SubPrivate Function Demo() As String
Demo = "This is Only a Demo!"
End Function有參數的函數:Private Sub Command1_Click()
MsgBox Demo("This is Only a Demo!!!")
End SubPrivate Function Demo(strMsg As String) As String
Demo = strMsg
End Function