📄 方法1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form 方法1
Caption = "高斯列主元消去法"
ClientHeight = 7620
ClientLeft = 60
ClientTop = 450
ClientWidth = 10470
LinkTopic = "Form4"
Picture = "方法1.frx":0000
ScaleHeight = 7620
ScaleWidth = 10470
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command4
BackColor = &H0080FF80&
Caption = "返回主窗口"
Height = 735
Left = 8760
Picture = "方法1.frx":25CFB
Style = 1 'Graphical
TabIndex = 7
Top = 6840
Width = 1575
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 1440
Top = 6000
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.Timer Timer1
Interval = 20
Left = 600
Top = 6000
End
Begin VB.TextBox Text1
BackColor = &H8000000D&
BorderStyle = 0 'None
ForeColor = &H80000009&
Height = 2895
Left = 7320
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 4
Top = 1080
Width = 2775
End
Begin VB.CommandButton Command2
BackColor = &H000080FF&
Caption = "解方程组"
Height = 735
Left = 2040
Style = 1 'Graphical
TabIndex = 2
Top = 3840
Width = 1335
End
Begin VB.CommandButton Command1
BackColor = &H0080FF80&
Caption = "打开方程组"
Height = 735
Left = 240
Style = 1 'Graphical
TabIndex = 1
Top = 3840
Width = 1215
End
Begin VB.CommandButton command3
BackColor = &H00FFFF00&
Caption = "清除文本输出内容"
Height = 735
Left = 3960
Style = 1 'Graphical
TabIndex = 0
Top = 3840
Width = 1335
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 3615
Left = 120
TabIndex = 3
Top = 120
Width = 6495
_ExtentX = 11456
_ExtentY = 6376
_Version = 393216
Rows = 15
Cols = 15
FormatString = "^ 序列|^ x1|^ x2|^ x3|^ x4|^ x5|^ x6|^ x7|^ x8|^ x9|^ x10|^ b"
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H8000000D&
BackStyle = 0 'Transparent
Caption = "解线性方程组"
BeginProperty Font
Name = "隶书"
Size = 36
Charset = 134
Weight = 700
Underline = 0 'False
Italic = -1 'True
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 720
Left = 360
TabIndex = 6
Top = 4800
Width = 4530
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "输出结果"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 435
Left = 7680
TabIndex = 5
Top = 360
Width = 1860
End
End
Attribute VB_Name = "方法1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim A(20, 20) As Single, B() As Single, X() As Single
Dim i As Integer, N As Integer, j As Integer
Private Sub Command1_Click()
Dim FileName As String
Dim Astr As String
On Error GoTo errhandle
CommonDialog1.InitDir = App.Path '设置初始路径 数据导入
CommonDialog1.FileName = "" '清除文件名
CommonDialog1.ShowOpen '显示“打开”对话框
FileName = CommonDialog1.FileName '保存文件名
If Len(CommonDialog1.FileName) > 0 Then
'File = FreeFile() '获得可用文件号
Open FileName For Input As #1 '打开文件
End If
i = 0: N = 0: j = 0: Dim Line1 As String
MousePointer = 11
Do While EOF(1) = False
N = N + 1
Line Input #1, Line1
Loop
ReDim B(N): ReDim X(N)
MSFlexGrid1.Cols = N + 2: MSFlexGrid1.Rows = N + 1
Close #1
Dim Forstr As String
Forstr = "序列"
For i = 1 To N
Forstr = Forstr & "|^ x" & i
MSFlexGrid1.TextMatrix(i, 0) = i
Next i
Forstr = Forstr & "|^ b"
MSFlexGrid1.FormatString = Forstr
Open FileName For Input As #2 '打开文件
Do While EOF(2) = False
j = j + 1
For i = 1 To N
Input #2, Astr ' 分别输入各数据
A(j, i) = Astr
MSFlexGrid1.TextMatrix(j, i) = Astr
Next i
Input #2, Astr
B(j) = Astr
MSFlexGrid1.TextMatrix(j, N + 1) = Astr
Loop
Close #2
errhandle:
MousePointer = 0
Exit Sub
MousePointer = 0
End Sub
Private Sub Command2_Click()
Call JieFangCheng(A, B, X)
For i = 1 To N
Text1.Text = Text1.Text & " x" & i & "=" & X(i) & vbCrLf
Next i
End Sub
Private Sub Command3_Click()
Text1.Text = ""
End Sub
Private Sub Command4_Click()
主窗口.Show
方法1.Hide
End Sub
Private Sub Form_Load()
MSFlexGrid1.ColAlignment(0) = 4
For i = 1 To 10
MSFlexGrid1.TextMatrix(i, 0) = i
Next i
End Sub
Private Sub JieFangCheng(A() As Single, B() As Single, X() As Single)
N = UBound(B)
Dim TempA As Single, L As Integer, k As Integer, Kk As Integer
Dim Ii As Integer, ChuShu As Single, Sum As Single
For i = 1 To N
L = 0: Kk = 0
For j = i To N
If A(j, i) = 0 Then L = L + 1
Next j
For j = i To N - L
If A(j, i) = 0 Then
Kk = Kk + 1
For k = i To N
TempA = A(j, k)
A(j, k) = A(N - Kk + 1, k)
A(N - Kk + 1, k) = TempA
Next k
TempA = B(j): B(j) = B(N - Kk + 1): B(N - Kk + 1) = TempA
End If
Next j
For Ii = i To N - L
ChuShu = A(Ii, i)
For j = i To N
A(Ii, j) = A(Ii, j) / ChuShu
Next j
B(Ii) = B(Ii) / ChuShu
Next Ii
For Ii = i + 1 To N - L
For j = i To N
A(Ii, j) = A(Ii, j) - A(i, j)
Next j
B(Ii) = B(Ii) - B(i)
Next Ii
Next i
For i = 1 To N
For j = 1 To i - 1
A(i, j) = 0
Next j
Next i
X(N) = B(N) / A(N, N)
For i = N - 1 To 1 Step -1
Sum = 0
For j = i + 1 To N
Sum = Sum + A(i, j) * X(j)
Next j
X(i) = (B(i) - Sum) / A(i, i)
Next i
End Sub
Private Sub Timer1_Timer()
If Label1.Left > 6000 Then
Label1.Left = 0
Else
Label1.Left = Label1.Left + 50
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -