VB6.0编程基础

软件所用版本:Windows Server 2012 R2、VB6简体精简版.exe
目录
第1章 VB6.0数值计算
1.1数值积分
1.2行列式
1.3复数运算
1.3.1 复数乘法
1.3.2 复数次幂
1.3.3 实数次幂
1.3.4 复数对数
第2章 Visual Basic语言知识点
2.1 调用Windows API
2.2 循环语句例子——生成循环群C_n的凯莱表Cn.exe
实现下列群论小工具的VB6.0版本:
1、实现一个复数字符串解析的函数,函数原型为vector atodc(const string &s),复数字符串非法就返回空容器,否则就返回实部和虚部。
2、实现一个矩阵字符串解析的函数,函数原型为vector> atomtx(const char* strMtx);和vector IsLegalMtx(const vector> &mtx)矩阵字符串非法就返回-1,否则就返回0,行数,列数。
3、输入两个有限群的凯莱表D4.txt,C2.txt,输出它们直积群的凯莱表D4C2.txt。
4、输入一个有限群的凯莱表D4C2.txt,输出它的结构分析D4C2_ElementToOrder.txt。

Private Sub Command1_Click()
On Error Resume Next
n! = InputBox("请输入n:")
For i = 0 To n - 1
For j = i To i + n - 1
s = s & (j Mod n + 1) & " "
Next j
s = s & Chr(13) & Chr(10)
Next i
Text1.Text = s
End Sub

Private Sub Form_Load()
'Text1.MultiLine = True只读属性
Command1.Caption = "Cn"
End Sub

Function nitrapzd(a As Double, b As Double, eps As Double) As Double
Dim n As Integer, k As Integer
Dim fa As Double, fb As Double, h As Double, t1 As Double, p As Double, s As Double, x As Double, t As Double
fa = func(a): fb = func(b)
n = 1: h = b - a: t1 = h * (fa + fb) / 2#
p = eps + 1#
While (p >= eps)
s = 0#
For k = 0 To n - 1
x = a + (k + 0.5) * h
s = s + func(x)
Next k
t = (t1 + h * s) / 2#
p = Abs(t1 - t)
t1 = t
n = n + n
h = h / 2#
Wend
nitrapzd = t
End Function

Function func(x As Double) As Double
func = Exp(-x * x)
End Function


Private Sub Command1_Click()
Dim a As Double, b As Double, eps As Double, v As Double
a = 0#
b = 1#
eps = 0.000001
v = nitrapzd(a, b, eps)
MsgBox "积分值 =" & v '.746823898920947
Text1.Text = v
End Sub

Function mdetgauss(n As Integer, mtxa() As Double) As Double
Dim I As Integer, j As Integer, k As Integer, nis As Integer, njs As Integer
Dim f As Double, det As Double, q As Double, d As Double
f = 1#
det = 1#
For k = 1 To n - 1
q = 0#
For I = k To n
For j = k To n
d = Abs(mtxa(I, j))
If (d > q) Then
q = d
nis = I
njs = j
End If
Next j
Next I
If (q + 1# = 1#) Then
mdetgauss = 0
Exit Function
End If
If (nis <> k) Then
f = -f
For j = k To n
d = mtxa(k, j)
mtxa(k, j) = mtxa(nis, j)
mtxa(nis, j) = d
Next j
End If
If (njs <> k) Then
f = -f
For I = k To n
d = mtxa(I, njs)
mtxa(I, njs) = mtxa(I, k)
mtxa(I, k) = d
Next I
End If
det = det * mtxa(k, k)
For I = k + 1 To n
d = mtxa(I, k) / mtxa(k, k)
For j = k + 1 To n
mtxa(I, j) = mtxa(I, j) - d * mtxa(k, j)
Next j
Next I
Next k
det = f * det * mtxa(n, n)
mdetgauss = det
End Function


Private Sub Command2_Click()
Dim mtxa(4, 4) As Double
Dim dbldeta As Double
mtxa(1, 1) = 1: mtxa(1, 2) = 2: mtxa(1, 3) = 3: mtxa(1, 4) = 4
mtxa(2, 1) = 5: mtxa(2, 2) = 6: mtxa(2, 3) = 7: mtxa(2, 4) = 8
mtxa(3, 1) = 9: mtxa(3, 2) = 10: mtxa(3, 3) = 11: mtxa(3, 4) = 12
mtxa(4, 1) = 13: mtxa(4, 2) = 14: mtxa(4, 3) = 15: mtxa(4, 4) = 16
dbldeta = mdetgauss(4, mtxa)
MsgBox "det(a)=" & dbldeta
End Sub

'Option Explicit
Private Type complex
x As Double
y As Double
End Type
Private Function cmu1(cpxz1 As complex, cpxz2 As complex) As complex
cmu1.x = cpxz1.x * cpxz2.x - cpxz1.y * cpxz2.y
cmu1.y = cpxz1.x * cpxz2.y + cpxz1.y * cpxz2.x
End Function

Private Sub Command1_Click()
Dim cpxz As complex
Dim scomplex As String, smsg As String
Dim cpxz1 As complex, cpxz2 As complex
Dim scomplex1 As String, scomplex2 As String
cpxz1.x = 9
cpxz1.y = 11
cpxz2.x = 56
cpxz2.y = 3
scomplex1 = "复数" & cpxz1.x & "+" & cpxz1.y & "j"
scomplex2 = "复数" & cpxz2.x & "+" & cpxz2.y & "j"
cpxz = cmu1(cpxz1, cpxz2)
scomplex = "复数" & cpxz.x & "+" & cpxz.y & "j"
smsg = scomplex1 & "乘以" & scomplex2 & "的积为" & scomplex
MsgBox smsg
Text1 = smsg '复数9+11j乘以复数56+3j的积为复数471+643j
End Sub
Const pi As Double = 3.14159265
Private Function ccpow(cpxz As complex, cpxn As complex, n As Integer) As complex
Dim ar As Double, s As Double, u As Double, v As Double
If cpxz.x = 0 Then
If cpxz.y = 0 Then
ccpow.x = 0: ccpow.y = 0
Exit Function
End If
s = 1.5707963268 * (Abs(cpxz.y) / cpxz.y + 4 * n)
Else
s = 2 * pi * n + Atn(cpxz.y / cpxz.x)
If cpxz.x < 0 Then
If cpxz.y > 0 Then
s = s + pi
Else
s = s - pi
End If
End If
End If
r = 0.5 * Log(cpxz.x * cpxz.x + cpxz.y * cpxz.y)
v = cpxn.y * r + cpxn.x * s
u = Exp(cpxn.x * r - cpxn.y * s)
ccpow.x = u * Cos(v)
ccpow.y = u * Sin(v)
End Function

Private Sub Command2_Click()
Dim cpxz As complex
Dim scomplex As String, smsg As String
cpxz.x = 1
cpxz.y = 1
scomplex = "复数" & cpxz.x & "+" & cpxz.y & "j"
Dim cpxcpow As complex
Dim cpxn As complex
cpxn.x = 1: cpxn.y = 1
cpxcpow = ccpow(cpxz, cpxn, 0)
smsg = scomplex & "的" & cpxn.x & "+" & cpxn.y & "j" & "次幂为:" & cpxcpow.x & "+" & cpxcpow.y & "j"
MsgBox smsg
Text1 = smsg '复数1+1j的1+1j次幂为:.273957253830121+.583700758758615j
End Sub


Private Function cpow(cpxz As complex, w As Double) As complex
Dim r As Double, t As Double
If cpxz.x = 0 And cpxz.y = 0 Then
cpow.x = 0: cpow.y = 0
Exit Function
End If
If cpxz.x = 0 Then
If cpxz.y > 0 Then
t = 1.5707963268
Else
t = -1.5707963268
End If
Else
If cpxz.x > 0 Then
t = Atn(cpxz.y / cpxz.x)
Else
If cpxz.y >= 0 Then
t = Atn(cpxz.y / cpxz.x) + pi
Else
t = Atn(cpxz.y / cpxz.x) - pi
End If
End If
End If
r = Exp(w * Log(Sqr(cpxz.x * cpxz.x + cpxz.y * cpxz.y)))
cpow.x = r * Cos(w * t)
cpow.y = r * Sin(w * t)
End Function


Private Sub Command3_Click()
Dim cpxz As complex
Dim n As Integer
Dim scomplex As String, smsg As String
cpxz.x = 16
cpxz.y = 81
scomplex = "复数" & cpxz.x & "+" & cpxz.y & "j"
Dim cpxpow As complex
n = 4
cpxpow = cpow(cpxz, 3)
smsg = scomplex & "的" & n & "次幂为:" & cpxpow.x & "+" & cpxpow.y & "j"
MsgBox smsg
Text1 = smsg '复数16+81j的4次幂为:-310832+-469232.999999999j
End Sub


Private Function cln(cpxz As complex) As complex
Dim e As Double, f As Double
If cpxz.x = 0 And cpxz.y = 0 Then
cln.x = 0
cln.y = 0
Exit Function
End If
If Abs(cpxz.x) < 1 And cpxz.y = 0 Then
cln.x = Abs(cpxz.x + cpxz.x) + Abs(cpxz.y + cpxz.y)
cln.y = 8 * cpxz.x / cln.x * cpxz.x + 8 * cpxz.y / cln.x * cpxz.y
Else
e = 0.5 * cpxz.x
f = 0.5 * cpxz.y
cln.x = Abs(0.5 * e) + Abs(0.5 * f)
cln.y = 0.5 * e / cln.x * e + 0.5 * f / cln.x * f
cln.x = 0.5 * (Log(cln.x) + Log(cln.y)) + 1.03972077084
End If
If cpxz.x <> 0 And Abs(cpxz.y) >= Abs(cpxz.y) Then
If cpxz.x >= 0 Then
cln.y = Atn(cpxz.y / cpxz.x)
Else
If cpxz.y >= 0 Then
cln.y = Atn(cpxz.y / cpxz.x) + pi
Else
cln.y = Atn(cpxz.y / cpxz.x) - pi
End If
End If
Else
cln.y = -Atn(cpxz.x / cpxz.y) + pi / 2 * cpxz.y / Abs(cpxz.y)
End If
End Function

Private Sub Command4_Click()
Dim cpxz As complex
Dim scomplex As String, smsg As String
cpxz.x = 3
cpxz.y = 2
scomplex = "复数" & cpxz.x & "+" & cpxz.y & "j"
Dim cpxln As complex
cpxln = cln(cpxz)
smsg = scomplex & "的自然对数为:" & cpxln.x & "+" & cpxln.y & "j"
MsgBox smsg
Text1 = smsg '复数3+2j的自然对数为:1.28247467873085+.588002603547568j
’874     泰语
'932     日语
'936     中文 (简体)
'949     朝鲜语
'950     中文 (台湾和香港繁体)
'1200     Unicode
'1250     东欧语言
'1251     西里尔语
'1252     美国和西欧语言
'1253     希腊语
'1254     土耳其语
'1255     希伯来语
'1256     阿拉伯语
'1257     波罗的语
Private Declare Function GetACP Lib "kernel32" () As Long
Private Sub Command1_Click()
ret = GetACP()
MsgBox ret '936
End Sub
End Sub

你可能感兴趣的:(VB6.0怀旧)