VB中引用自定义函数
PrivateSubCommand1_Click()Picture1.FillColor=vbYellowPicture1.FillStyle=0draw()EndSub...
Private Sub Command1_Click()
Picture1.FillColor = vbYellow
Picture1.FillStyle = 0
draw()
End Sub
draw是我自己定义的函数,我想再按钮控件里引用,这样写不对,该怎么写啊? 展开
Picture1.FillColor = vbYellow
Picture1.FillStyle = 0
draw()
End Sub
draw是我自己定义的函数,我想再按钮控件里引用,这样写不对,该怎么写啊? 展开
2个回答
展开全部
VB的自定义函数也就是自己根据自己的需求编制一个符合自己格式的函数
自定义函数一般都是把许多VB自带的函数编制一个符合自己需要的函数
例如制作一个辨别一个数是否为素数的函数
工具-添加过程-单选函数项
我输入的函数名为:ssif
格式为 只有一个参数为整型
是素数返回真 不是返回假
Public Function ssif(Nos As Integer) As Boolean
For i = 2 To Nos
If Nos Mod i = 0 Then
ssif = False
Exit For
End If
Next i
ssif = True
End Function
function conn() As adodb.connection
Dim adoconn As adocb.Connection
Set adoconn = New ADODB.Connection
t1 = GetFromIni("database", "server", ".\\thjl.ini")
Debug.Print t1
t2 = GetFromIni("database", "user", ".\\thjl.ini")
t3 = GetFromIni("database", "password", ".\\thjl.ini")
t4 = GetFromIni("database", "data", ".\\thjl.ini")
constr = "Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=" & t4 & ";Data Source=" & t1 & ""
adoconn.ConnectionString = constr
adoconn.CursorLocation = adUseClient
adoconn.Open constr, t2, t3
conn = adoconn
End function
自定义函数一般都是把许多VB自带的函数编制一个符合自己需要的函数
例如制作一个辨别一个数是否为素数的函数
工具-添加过程-单选函数项
我输入的函数名为:ssif
格式为 只有一个参数为整型
是素数返回真 不是返回假
Public Function ssif(Nos As Integer) As Boolean
For i = 2 To Nos
If Nos Mod i = 0 Then
ssif = False
Exit For
End If
Next i
ssif = True
End Function
function conn() As adodb.connection
Dim adoconn As adocb.Connection
Set adoconn = New ADODB.Connection
t1 = GetFromIni("database", "server", ".\\thjl.ini")
Debug.Print t1
t2 = GetFromIni("database", "user", ".\\thjl.ini")
t3 = GetFromIni("database", "password", ".\\thjl.ini")
t4 = GetFromIni("database", "data", ".\\thjl.ini")
constr = "Provider=SQLOLEDB.1;Persist Security Info=True;Initial Catalog=" & t4 & ";Data Source=" & t1 & ""
adoconn.ConnectionString = constr
adoconn.CursorLocation = adUseClient
adoconn.Open constr, t2, t3
conn = adoconn
End function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询