课件20张PPT。VB常用算法进制转换 (十进制数转换为其它进制)25D=11001BFunction tran(x As Integer, r As Integer) As String Dim s As String Dim c As Integer Do While x<> 0 c = x Mod r If c >= 10 Then s = Chr(Asc("A") + c - 10) + s Else s = Str(c) + s End If x = x r Loop tran = s End Function aa = "0123456789ABCDEF" Do While x <> 0 c = x Mod r s = Mid(aa, c + 1, 1)+s x = x r Loop二进制运算Private Sub Command1_Click() Dim c(1 To 10) As Integer Dim x1, y1 As Integer Dim s As String x = Text1.Text y = Text2.Text For i = 1 To Len(x) x1 = Val(Mid(x, Len(x) - i + 1, 1)) y1 = Val(Mid(y, Len(y) - i + 1, 1)) c(i) = x1 + y1 + t If c(i) >= 2 Then c(i) = c(i) Mod 2 : t = 1 Else t = 0 Next i For i = 1 To Len(x) s = Str(c(i)) + s Next i If t = 1 Then s = Str(t) + s Text3.Text = s End SubPrivate Sub Command1_Click() s = "a red car" s1 = "nice " i = 3 s = Mid(s, 1, i - 1) + s1 + Mid(s, i, Len(s) - i + 1) Text1.Text = s End Sub 字符串的插入Private Sub Command2_Click() s = "a red car" s1 = "red " i = 3 s = Mid(s, 1, i - 1) + Mid(s, i + Len(s1), Len(s) - Len(s1)-i+1) Text1.Text = s End Sub字符串的删除表示一个字符是字母: a>=“A” and a<=“Z” or a>=“a” and a<=“z” 表示一个字符是非字母: a<“A” or a>“Z” and a<“a” or a>“z” 或 Not (a>=“A” and a<=“Z” or a>=“a” and a<=“z”) 数组元素的删除Dim a(1 to 10) as integer X=val(text1.text) For i=1 to 10 If x=a(i) then exit for Next i For j= i+1 to 10 a(j-1)=a(j) Next i数组元素的插入Dim a(1 to 10) as integer X=val(text1.text) For i=1 to 9 If x
= 10 Then c(i) = e - 10: t = 1 Else c(i) = e: t = 0 Next i For i = 1 To alen s = Str(c(i)) + s Next i If t = 1 Then s = Str(t) + s Text3.Text = s End Sub加法运算Private Sub Command1_Click() Dim c(1 To 50) As Integer a = Text1.Text : b = Text2.Text alen = Len(a) : blen = Len(b) jie = 1 For i = 1 To alen If i <= blen Then ad = Val(Mid(a, alen - i + 1, 1)) bd = Val(Mid(b, blen - i + 1, 1)) e = ad + 10 - bd - 1 + jie Else ad = Val(Mid(a, alen - i + 1, 1)) e = ad + 10 + jie - 1 End If c(i) = e Mod 10 jie = e 10 Next i For i = 1 To alen - 1 s = Str(c(i)) + s Next i If c(alen) <> 0 Then s = Str(c(alen)) + s Text3.Text = s End Sub 减法运算前序表达式 运算符放在两个运算对象的前面,所有的计算按运算符出现的顺序,严格从右向左进行,不考虑运算符的优先规则 + 9 ? + * - 3 ? 1 ??3 ?/ 10 ?2 ??+ 9 ? + * - 3 ? 1 ??3 5 ?+ 9 ? + * 2 ?3 5 ?+ 9 ? + 6 5 ?+ 9 ? 1120算式9 +(3-1)*3+10/2?Private Sub Command2_Click() Dim a(1 To 11) As String t = n i = t Do While t >= 3 ch2 = a(i): ch1 = a(i - 1): ch3 = a(i - 2) flag ... ...