首先新建一個(gè)類庫項(xiàng)目,把你的代碼以類(需要實(shí)例)或模塊(靜態(tài))的形式封裝好,生成過后在輸出目錄(bin/debug或bin/release)里面會有個(gè)項(xiàng)目名.dll文件,就是它了。
目前創(chuàng)新互聯(lián)已為近千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站運(yùn)營、企業(yè)網(wǎng)站設(shè)計(jì)、淮陰網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
在調(diào)用方項(xiàng)目里,右鍵解決方案資源管理器中的引用,添加引用,瀏覽到你的dll文件。接著到你的代碼中,代碼最上面寫:
Imports 項(xiàng)目名
然后調(diào)用這個(gè)類或模塊即可。
根據(jù)你的情況,可能用模塊封裝更適合一些。比如:
Public Module MatrixSolve
Public Function Solve(para1 As Double,para2 As Double) As Double
'一些代碼
Return result
End Function
End Module
調(diào)用起來只要這樣即可:
Dim num As Double = MatrixSolve.Solve(x,y)
注意模塊和函數(shù)的訪問級別都用Public,否則外面無法訪問。
注意:參數(shù)為動態(tài)數(shù)組;
Private Function MyF(ByRef d() As Integer)
ReDim d(4, 13) As Integer
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim MyNum(4) As Integer
For i = 1 To 4
MyNum(i) = 0
Next i
Randomize
For i = 1 To 4
For j = 1 To 13
n = Int(Rnd * 4 + 1)
Do While MyNum(n) = 13
n = Int(Rnd * 4 + 1)
Loop
d(i, j) = n
MyNum(n) = MyNum(n) + 1
Next j
Next i
End Function
refresh是vb的關(guān)鍵詞,你最好不要用這個(gè)名字作為你自定義函數(shù)的名字,當(dāng)然,VB也允許你用Overrides關(guān)鍵詞重載這個(gè)方法。
很簡單,在end select前再多加一種情況case else return "XXXx",因?yàn)槟阒惶峁┝?-9這10種情況
Public Function Zuhe(ByVal qa As String) As String
Select Case qa
Case "0"
Return "1"
Case "1"
Return "3"
Case "2"
Return "4"
Case "3"
Return "6"
Case "4"
Return "2"
Case "5"
Return "8"
Case "6"
Return "9"
Case "7"
Return "7"
Case "8"
Return "5"
Case "9"
Return "0"
Case else
Return "XXXX"
End Select
End Function