最近好多事要做啊, 去工设院实验室了, 对硬件感兴趣, 具有一定的编程和学习新知识的能力, 对网络以及串口通信有一定的了解, 这是老师提的要求; wo…… 感觉压力好大啊, 我当初答应老师来, 就是想挑战一下自己, 没有压力, 哪来的进步啊. 话说回来, 这个实验室还是挺好的, 自习的好地方, 设备一应俱全, 还在工设院, 算是比较近了, 终于可以结束这种想自习还得去至善楼的日子了, 加油干!

VB.Net

VB.Net 绝对是Windows下面开发图形化程序强大的语言之一. 微软将VB加入.Net之后就有了VB.Net, Visual Baisc(以下简称VB)是一种由微软公司开发的包含协助开发环境的事件驱动编程语言..Net架构提供应用程序所需的两部分内容: .NET架构类库通用语言运行时, 可以分别类比Java语言中的java类包java运行环境(jre)

注意:VB.Net是不区分大小写的, 系统将全部默认为小写, 但是程序是也编写给人看的(主要是方便自己维护和修改), 普遍采用驼峰命名法, 见名知义。

变量声明

通用格式:

1
[<attrlist>] [{Public|Private|Protected|Friend|Protected Friend|Static}] [Shared] [Shadows] [ReadOnly] Dim [WithEvents] name [(boundlist)] [As [New] type] [ = initexpr ]

关键字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Public Class Form1
Private Sub btnHello_Click(sender As Object, e As EventArgs) Handles btnHello.Click
'申明变量来存储圆的面积、周长以及半径
Dim pi As Double = 3.141592
Dim area As Double
Dim circle As Double
Dim radius As Double
Me.Text = "本程序将计算圆的周长以及面积,其中圆周率取:3.141592"
'调用文本输入框
radius = InputBox("输入圆的半径:")
area = pi * radius * radius
circle = radius * pi * 2
'输出圆的面积和周长
Me.Text = "点击右上角的×关闭本程序"
txtHello.Text = "圆的半径为:" + radius.ToString + "其面积为:" + area.ToString + "周长为:" + circle.ToString
End Sub

End Class

常用排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As MyArray = New MyArray()
a.GetN(InputBox("输入数组中有多少个元素:"))
a.MakeArray()
Dim b As MySort = New MySort
'b.BubbleSort(a.array)
'b.ShellSort(a.array)
b.InsertSort(a.array)
a.ToString()
End
End Sub
End Class

Class MySort
Function ShellSort(ByRef array As Double())
Dim stepE As Integer = array.Length / 2
For index1 As Integer = 0 To 1 Step 0
If stepE <= 0 Then
Exit For
End If
For index2 As Integer = 0 To array.Length - stepE - 1
If array(index2) > array(index2 + stepE) Then
Dim tmp As Double = array(index2)
array(index2) = array(index2 + stepE)
array(index2 + stepE) = tmp
End If
Next index2
stepE /= 2
Next index1
End Function

Function InsertSort(ByRef array As Double())
For index1 As Integer = 1 To array.Length - 1
For index2 As Integer = 0 To index1 - 1
If array(index2) > array(index1) Then
Dim tmp As Double = array(index1)
For index3 As Integer = index1 - 1 To index2 Step -1
array(index3 + 1) = array(index3)
Next index3
array(index2) = tmp
End If
Next index2
Next index1
End Function

Function BubbleSort(ByRef array As Double())
For index1 As Integer = array.Length - 1 To 1 Step -1
For index2 As Integer = 0 To index1 - 1
If array(index2) > array(index2 + 1) Then
Dim tmp As Double = array(index2)
array(index2) = array(index2 + 1)
array(index2 + 1) = tmp
End If
Next index2
Next index1
End Function
End Class

Class MyArray
Private n As Integer
Public array As Double()
Sub GetN(ByVal num As Integer)
n = num
ReDim array(num)
End Sub

Public Function MakeArray() As Double()
Dim index As Integer
Try
For index = 0 To UBound(array)
array(index) = InputBox("输入第" + index.ToString + "的值")
Next index
Catch ex As Exception
index -= 1
End Try

End Function

Public Function ToString() As String
Dim Str As String = ""
For Each index As Double In array
Str += index.ToString + " "
Next index
MsgBox(Str)
Return Str
End Function
End Class