一維回傳
二維參數
二維回傳
集合參數
集合回傳
主系統 <===>webBrowser(元件) <=php系統==>AppServ < ===> database
一維參數
一維回傳
class Ani3
Public Function fun1() As Integer()
Dim a(2) As Integer
a(0) = 14
a(1) = 15
fun1 = a
End Function
Private Sub CommandButton5_Click()
Dim con3 As New Ani3
Dim b '由引數決定
b = con3.fun1
MsgBox (Str(b(0)) + ":" + Str(b(1)))
End Sub
==================================================
二維參數
Public Function fun2(b() As Integer)
MsgBox (b(1, 0))
End Function
Private Sub CommandButton6_Click()
Dim a(1, 1) As Integer
a(0, 0) = 12
a(0, 1) = 13
a(1, 0) = 14
a(1, 1) = 15
Dim cin3 As New Ani3
cin3.fun2 a
End Sub
================================
二維回傳
Public Function fun3() As String()
Dim a(1, 1) As String
a(0, 0) = "bill"
a(0, 1) = "lisa"
a(1, 0) = "vovo"
a(1, 1) = "dodo"
fun3 = a
End Function
Private Sub CommandButton7_Click()
Dim cin3 As New Ani3
Dim b
b = cin3.fun3
MsgBox (b(1, 1))
End Sub
===============================
集合元件 Collection
Dim 元件 as New Collection
元件.Add String
set 函數名稱 = 元件
回傳
D變數 Collectuon
set 變數 = 類別元件‧函數
變數‧Item(項目索引值)
===============================
集合回傳
Private Sub CommandButton8_Click()
Dim cin3 As New Ani3
Dim b As Collection '在類別中決定為集合,不須再new
Set b = cin3.fun4
MsgBox b.Item(2)
End Sub
Public Function fun4() As Collection
Dim a As New Collection
a.Add "bill"
a.Add "lisa"
Set fun4 = a
End Function
=========================================
集合參數回傳
Public Function fun5(a As Collection)
MsgBox a.Item(2)
End Function
Private Sub CommandButton9_Click()
Dim cin3 As New Ani3
Dim a As New Collection
a.Add "bill"
a.Add "lisa"
cin3.fun5 a
End Sub
====================================
呼叫函數;無參數無回傳值
無參數有回傳值
有參數無回傳值
有參數有回傳值
當參數或回傳值
1.純變數
2.一維陣列
3.二維陣列
4.元件
=============================
ex:
Private Sub CommandButton10_Click()
Dim qcon As New Qain4
Dim rq '由物件決定
Dim sql As String
Dim idquery As String
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox1.SetFocus
If TextBox1 <> "" Then
On Error GoTo Label1
idquery = TextBox1.Text
sql = "select * from persondata where 編號='" + idquery + "'"
rq = qcon.qfun1(sql) '傳字串參數
TextBox2.Text = rq(1)
TextBox3.Text = rq(2)
TextBox4.Text = rq(3)
TextBox5.Text = rq(4)
Exit Sub
Label1:
MsgBox "查無此筆資料"
TextBox1 = ""
TextBox1.SetFocus
Else
MsgBox "請輸入資料"
TextBox1.SetFocus
End If
End Sub
Private Sub CommandButton2_Click()
Dim com1 As New Ani1
com1.fun2 a:=12, b:=45
End Sub
Private Sub CommandButton3_Click()
Dim com1 As New Ani1
Dim i As Integer
i = com1.fun3
MsgBox i
End Sub
==============================
Public Function qfun1(ByVal q As String) As String()
Dim data(5) As String
Dim conn As New ADODB.Connection '資料庫連線
Dim rs As New ADODB.Recordset '資料集
ConnectionString = "driver={mysql odbc 5.1 driver};database=persondb;server=127.0.0.1;port=3306;uid=root;password=12345678;opt=3;smt=SET NAMES 'gb2312'"
conn.Open ConnectionString
rs.Open q, conn
rs.MoveFirst
Do While Not rs.EOF
data(0) = rs("編號")
data(1) = rs("姓名")
data(2) = rs("血型")
data(3) = rs("學歷")
data(4) = rs("職務")
rs.MoveNext
Loop
rs.Close
conn.Close
qfun1 = data
End Function
呼叫函數;無參數無回傳值
無參數有回傳值
有參數無回傳值
有參數有回傳值
當參數或回傳值
1.純變數
2.一維陣列
3.二維陣列
4.元件
=============================
ex:
Dim qcon As New Qain4
Dim rq '由物件決定
Dim sql As String
Dim idquery As String
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox1.SetFocus
If TextBox1 <> "" Then
On Error GoTo Label1
idquery = TextBox1.Text
sql = "select * from persondata where 編號='" + idquery + "'"
rq = qcon.qfun1(sql) '傳字串參數
TextBox2.Text = rq(1)
TextBox3.Text = rq(2)
TextBox4.Text = rq(3)
TextBox5.Text = rq(4)
Exit Sub
Label1:
MsgBox "查無此筆資料"
TextBox1 = ""
TextBox1.SetFocus
Else
MsgBox "請輸入資料"
TextBox1.SetFocus
End If
End Sub
Private Sub CommandButton2_Click()
Dim com1 As New Ani1
com1.fun2 a:=12, b:=45
End Sub
Private Sub CommandButton3_Click()
Dim com1 As New Ani1
Dim i As Integer
i = com1.fun3
MsgBox i
End Sub
==============================
Public Function qfun1(ByVal q As String) As String()
Dim data(5) As String
Dim conn As New ADODB.Connection '資料庫連線
Dim rs As New ADODB.Recordset '資料集
ConnectionString = "driver={mysql odbc 5.1 driver};database=persondb;server=127.0.0.1;port=3306;uid=root;password=12345678;opt=3;smt=SET NAMES 'gb2312'"
conn.Open ConnectionString
rs.Open q, conn
rs.MoveFirst
Do While Not rs.EOF
data(0) = rs("編號")
data(1) = rs("姓名")
data(2) = rs("血型")
data(3) = rs("學歷")
data(4) = rs("職務")
rs.MoveNext
Loop
rs.Close
conn.Close
qfun1 = data
End Function
沒有留言:
張貼留言