首先在窗体上添加Button1,ListBox1,下面是完整代码
目前创新互联已为近1000家的企业提供了网站建设、域名、网页空间、网站托管、服务器租用、企业网站设计、云安网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
Public Class Form1
Public Sub BubbleSort(ByVal arr() As Integer) '冒泡法排序
Dim temp As Double
Dim i, j As Integer
For i = 0 To arr.GetUpperBound(0) - 1
For j = i + 1 To arr.GetUpperBound(0) - 1
If arr(i) arr(j) Then
temp = arr(j)
arr(j) = arr(i)
arr(i) = temp
End If
Next
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '调用
Dim arr() As Integer = {55, 22, 33, 11, 77, 88}
BubbleSort(arr) '调用排序过程
Me.ListBox1.Items.Clear()
For i = 0 To arr.GetUpperBound(0) - 1 '显示排序后结果
Me.ListBox1.Items.Add(arr(i).ToString)
Next
End Sub
End Class
新建窗口,添加picture控件
利用line()方法画线
line(开始x坐标,开始y坐标)-(结束x坐标,结束y坐标),线的颜色,画线的方式(默认为线,B为矩形无填充,BF为填充的矩形)
For i = 1 To 16
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(255, 0, 0)
Picture1.Line (0, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(255, 0, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), 0), RGB(0, 255, 0)
Picture1.Line (Picture1.Width, Picture1.Height / 2)-(i * (Picture1.Width / 16), Picture1.Height), RGB(0, 255, 0)
Next i
如果要在窗口上画也可以调用窗口的line方法即form.line()
a = Int((2013 - 12 + 1) * Rnd() + 12)
b = Int((2013 - 12 + 1) * Rnd() + 12)
c = Int((2013 - 12 + 1) * Rnd() + 12)
d = Int((2013 - 12 + 1) * Rnd() + 12)
m = Int((2013 - 12 + 1) * Rnd() + 12)
If a b Then t = b: b = a: a = t
If a c Then t = c: c = a: a = t
If a d Then t = d: d = a: a = t
If a m Then t = m: m = a: a = t
If b c Then t = c: c = b: b = t
If b d Then t = d: d = b: b = t
If b m Then t = m: m = b: b = t
If c d Then t = d: d = c: c = t
If c m Then t = m: m = c: c = t
If d m Then t = m: m = d: d = t
text1 =a
text2 =b
text3 =c
text4 =d
text5=m
首先新建一个类库项目,把你的代码以类(需要实例)或模块(静态)的形式封装好,生成过后在输出目录(bin/debug或bin/release)里面会有个项目名.dll文件,就是它了。
在调用方项目里,右键解决方案资源管理器中的引用,添加引用,浏览到你的dll文件。接着到你的代码中,代码最上面写:
Imports 项目名
然后调用这个类或模块即可。
根据你的情况,可能用模块封装更适合一些。比如:
Public Module MatrixSolve
Public Function Solve(para1 As Double,para2 As Double) As Double
'一些代码
Return result
End Function
End Module
调用起来只要这样即可:
Dim num As Double = MatrixSolve.Solve(x,y)
注意模块和函数的访问级别都用Public,否则外面无法访问。