private sub aa()
print "ok"
end sub
调 用
aa()
就可以了
private function aa(a1 as integer) as integer
aa=a1*2
end function
调用
bb=aa(2)
print "ok"
end sub
调 用
aa()
就可以了
private function aa(a1 as integer) as integer
aa=a1*2
end function
调用
bb=aa(2)
调试欢乐多
Dim pubInKeyCode As Integer
Dim pubX As Integer
Dim pubY As Integer
Dim pubKeySet(3) As Integer
Dim pubXStep As Integer
Dim pubYStep As IntegerpubKeySet(0)=77
pubKeySet(1)=75
pubKeySet(2)=80
pubKeySet(3)=72
pubXStep=1
pubYStep=1Do
Do
pubInKeyStr=Inkey$
Loop While pubInKeyStr=""
pubInKeyCode=Inp(&H60)
pubX=DataMoveByKeyCode%(pubX,pubInKeyCode,pubKeySet(0),pubKeySet(1),pubXStep)
pubY=DataMoveByKeyCode%(pubY,pubInKeyCode,pubKeySet(2),pubKeySet(3),pubYStep)
ShowPosition (pubX,pubY)
LoopFunction DataMoveByKeyCode%(pN As Integer,pKeyCode As Integer,pKeyUp As Integer,pKeyDown As Integer,pNStep As Integer)
Dim tOutInt As Integer
If pKeyCode=pKeyUp Then
tOutInt=pN+pNStep
ElseIf pKeyCode=pKeyDown Then
tOutInt=pN-pNStep
Else
tOutInt=pN
End If
DataMoveByKeyCode%=tOutInt
End FunctionSub ShowPosition(pX As Integer,pY As Integer)
Locate 1,1:Print pX
Locate 2,1:Print pY
End Sub1、VB程序。完全移植上面的QB程序到VB中。
Dim pubInKeyStr As String
Dim pubInKeyCode As Integer
Dim pubX As Integer
Dim pubY As Integer
Dim pubKeySet(3) As Integer
Dim pubXStep As Integer
Dim pubYStep As IntegerSub Form_Load()
'初始化变量的值在Form_Load事件里,而不能在外部。
pubKeySet(0)=77
pubKeySet(1)=75
pubKeySet(2)=80
pubKeySet(3)=72
pubXStep=1
pubYStep=1
End Sub'下面是模拟出4个方向键的信号。
Sub CommandUp_Click()
PositionMove 72
End SubSub CommandDown_Click()
PositionMove 80
End SubSub CommandLeft_Click()
PositionMove 75
End SubSub CommandRight_Click()
PositionMove 77
End SubSub PositionMove(pInKeyCode As Integer)
'这段相当于QB程序里的主程序的部分。
pubX=DataMoveByKeyCode%(pubX,pInKeyCode,pubKeySet(0),pubKeySet(1),pubXStep)
pubY=DataMoveByKeyCode%(pubY,pInKeyCode,pubKeySet(2),pubKeySet(3),pubYStep)
ShowPosition (pubX,pubY)
End SubFunction DataMoveByKeyCode(pN As Integer,pKeyCode As Integer,pKeyUp As Integer,pKeyDown As Integer,pNStep As Integer) as Integer
'注意上面的函数声明有区别,QB中不能将函数As Integer,只能加%号。而VB中可以。该函数除这点之外没有一点改动。
Dim tOutInt As Integer
If pKeyCode=pKeyUp Then
tOutInt=pN+pNStep
ElseIf pKeyCode=pKeyDown Then
tOutInt=pN-pNStep
Else
tOutInt=pN
End If
DataMoveByKeyCode=tOutInt
End FunctionSub ShowPosition(pX As Integer,pY As Integer)
'显示坐标数值的部分有变化,VB与字符界面的QB在这点习惯上不同。
Text1.Text=pX
Text2.Text=pY
End Sub
ID As String * 12
Names As String * 12
Tel As String * 20
End TypeQB中不能将函数声明成tpUSER类型,参数列表是唯一通道。所以想对该自定义类型操作只能这样:Sub RecSave(pRec As ANY)
……
End SubSub RecLoad(pRec As ANY)
……
End SubVB中有所改善,可以这样:Sub RecSave(pRec As tpUSER)
……
End SubFunction RecLoad() As tpUSER
……
End Function另外,比如下面这个函数:
Function SaveRec(pFileName As String) As Long
End Function该函数在保存记录到文件后返回记录位置。在QB中必须这样用:
tGetLong=SaveRec(pFileName)但是在VB中可以:SaveRec pFileName你可以把一个Function在一些场合当Sub一样用,不要返回值。所以,我在一些QB中需要SUB的场合,换到VB中改用Function,这样可以选择返回可选的状态值。