📄 module1.bas
字号:
For k = 1 To mapform.Picture2.Tag - 1
Unload mapform.matshow(k)
Unload mapform.matrixname(k)
Next k
End If
mapform.matshow(0).Clear
mapform.matrixname(0).Caption = ""
mapform.Picture2.Tag = 0
Call makebranches
n = nodecounts
b = brcounter
Call maketree
Call makeA
Call makeBC
Call ACanalyse
Call makenodevolt
If nodevoltop = 1 Then
Call printnodeinfo
End If
flag = 1
ElseIf atype = 1 Then
analysistype = 0
Call makebranches
n = nodecounts
b = brcounter
Call maketree
Call makeA
Call makeBC
flag = 1
ElseIf atype = 2 Then
analysistype = 2
Call makebranches
n = nodecounts
b = brcounter
Call maketree
Call makeA
Call makeBC
Call ACanalyse
Call makenodevolt
flag = 1
End If
derror::
If flag = 0 Then
MsgBox ("电路中有错误!请先纠正再运行!")
End If
End Sub
Function checkfrequency() As Integer
errortype = 6
Dim flag, m, k, nn As Integer
If main.tbToolBar.Buttons(25).Enabled = False Then
If multisignal.stype <> 0 Then
ReDim nowfrequency(multisignal.times - 1) As Single
End If
For k = 0 To multisignal.times - 1
nowfrequency(k) = (2 * k + 1) * multisignal.frequency
Next k
m = multisignal.times
End If
For k = 0 To counts - 1
If (mapform.cell(k).celltype = 3 Or mapform.cell(k).celltype = 4) And mapform.cell(k).celltag = 1 Then
If m > 0 Then
For nn = 0 To m - 1
If nowfrequency(nn) = sourcemat(mapform.cell(k).cellvalue).frequency Then
flag = 1
Exit For
End If
Next nn
If flag = 0 Then
ReDim Preserve nowfrequency(m) As Single
nowfrequency(m) = sourcemat(mapform.cell(k).cellvalue).frequency
m = m + 1
End If
Else
m = 1
nowfrequency(0) = sourcemat(mapform.cell(k).cellvalue).frequency
End If
ElseIf (mapform.cell(k).celltype = 3 Or mapform.cell(k).celltype = 4) And mapform.cell(k).celltag = 0 Then
If m > 0 Then
For nn = 0 To m - 1
If nowfrequency(nn) = 0 Then
flag = 1
Exit For
End If
Next nn
If flag = 0 Then
ReDim Preserve nowfrequency(m) As Single
nowfrequency(m) = 0
m = m + 1
End If
Else
m = 1
nowfrequency(0) = 0
End If
End If
Next k
checkfrequency = m
errortype = 5
End Function
Public Function ACanalyse()
errortype = 5
Dim strtry As String
Dim cellcon As Variant
Dim m, k, kk, kkk As Integer
Dim xsmat() As Single
Dim cxsmat() As Single
ReDim xsmat(1 To 2 * b, 1 To 2 * b) As Single
ReDim cbmat(1 To 2 * b) As Single
ReDim cxsmat(1 To 2 * b, 1 To 2 * b) As Single
ReDim ccbmat(1 To 2 * b) As Single
ReDim nowfrequency(0) As Single
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
frequencytype = checkfrequency - 1
'''''''this variable to save the volt info of every node
ReDim nodevinfo(n - 1, frequencytype) As nodevolt
For kk = 0 To frequencytype
omig = nowfrequency(kk) * 4 * pi
'-------------------------------------------
For k = 0 To b - 1
If mapform.cell(branch1(k).cellcon(0)).celltype = 5 Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Select Case mapform.cell(branch1(k).cellcon(0)).celltag
Case 1
xsmat(b + k + 1, b + k + 1) = 1
xsmat(b + k + 1, b + mapform.cell(mapform.cell(branch1(k).cellcon(0)).Tag).cellinbranch + 1) = -mapform.cell(branch1(k).cellcon(0)).cellvalue
Case 2
xsmat(b + k + 1, k + 1) = 1
xsmat(b + k + 1, b + mapform.cell(mapform.cell(branch1(k).cellcon(0)).Tag).cellinbranch + 1) = -mapform.cell(branch1(k).cellcon(0)).cellvalue
Case 3
xsmat(b + k + 1, b + k + 1) = 1
xsmat(b + k + 1, mapform.cell(mapform.cell(branch1(k).cellcon(0)).Tag).cellinbranch + 1) = -mapform.cell(branch1(k).cellcon(0)).cellvalue
Case 4
xsmat(b + k + 1, k + 1) = 1
xsmat(b + k + 1, mapform.cell(mapform.cell(branch1(k).cellcon(0)).Tag).cellinbranch + 1) = -mapform.cell(branch1(k).cellcon(0)).cellvalue
End Select
',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
ElseIf mapform.cell(branch1(k).cellcon(0)).celltype = 6 Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If kk + 1 > multisignal.times Then
xsmat(b + k + 1, b + k + 1) = 1
Else
m = checktype(CInt(k), CInt(kk))
xsmat(b + k + 1, b + k + 1) = 1
cbmat(b + k + 1) = volt
ccbmat(b + k + 1) = cvolt
',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
End If
Else
m = checktype(CInt(k), CInt(kk))
If m >= 0 Then
If mapform.cell(m).celltag = 1 Then
If sourcemat(mapform.cell(m).cellvalue).frequency = nowfrequency(kk) Then
xsmat(b + k + 1, k + 1) = 1
cbmat(b + k + 1) = sourcemat(mapform.cell(m).cellvalue).a * Cos(sourcemat(mapform.cell(m).cellvalue).alpha * pi / 180)
ccbmat(b + k + 1) = sourcemat(mapform.cell(m).cellvalue).a * Sin(sourcemat(mapform.cell(m).cellvalue).alpha * pi / 180)
Else
xsmat(b + k + 1, k + 1) = 1
End If
Else
xsmat(b + k + 1, k + 1) = 1
If omig = 0 Then
cbmat(b + k + 1) = mapform.cell(m).cellvalue
End If
End If
Else
If omig <> 0 Then
If mapform.cell(branch1(k).cellcon(0)).celltype = 3 And mapform.cell(branch1(k).cellcon(0)).celltag = 1 Then
If nowfrequency(kk) = sourcemat(mapform.cell(branch1(k).cellcon(0)).cellvalue).frequency Then
cbmat(b + k + 1) = sourcemat(mapform.cell(branch1(k).cellcon(0)).cellvalue).a * Cos(sourcemat(mapform.cell(branch1(k).cellcon(0)).cellvalue).alpha * pi / 180)
ccbmat(b + k + 1) = sourcemat(mapform.cell(branch1(k).cellcon(0)).cellvalue).a * Sin(sourcemat(mapform.cell(branch1(k).cellcon(0)).cellvalue).alpha * pi / 180)
End If
End If
xsmat(b + k + 1, b + k + 1) = 1
xsmat(b + k + 1, k + 1) = -resist
cxsmat(b + k + 1, k + 1) = -lcresist
ElseIf omig = 0 Then
If mapform.cell(branch1(k).cellcon(0)).celltype = 3 And mapform.cell(branch1(k).cellcon(0)).celltag = 0 Then
cbmat(b + k + 1) = volt
End If
If mapform.cell(branch1(k).cellcon(0)).celltype = 1 Then
xsmat(b + 1 + k, k + 1) = 1
Else
xsmat(b + 1 + k, b + k + 1) = 1
End If
xsmat(b + k + 1, k + 1) = -resist
End If
End If
End If
Next k
'---------以上完成了对支路特性的描述!
'=================以下对A矩阵进行处理
For k = 0 To n - 2
For m = 0 To b - 1
xsmat(k + 1, m + 1) = a(k, m)
Next m
Next k
'=================以下对B矩阵进行处理
For k = 0 To b - n
For m = 0 To b - 1
If m <= n - 2 Then
xsmat(n + k, tree(m) + b + 1) = bb(k, m)
Else
xsmat(k + n, linkbranch(m - n + 1) + b + 1) = bb(k, m)
End If
Next m
Next k
'==================以下显示此矩阵!///////
If analysistype = 0 Then
Call mapform.matshower(1, 2 * b, 2 * b, xsmat, "实系数" + Str(kk))
Call mapform.matshower(1, 2 * b, 2 * b, cxsmat, "虚系数" + Str(kk))
Call mapform.matshower(1, -1, 2 * b, cbmat, "实常数" + Str(kk))
Call mapform.matshower(1, -1, 2 * b, ccbmat, "虚常数" + Str(kk))
End If
If LECpxGauss(2 * b, xsmat, cxsmat, cbmat, ccbmat) = True Then '
'////////////
If analysistype = 0 Then
Call mapform.matshower(1, -1, 2 * b, cbmat, "实电量" + Str(kk))
Call mapform.matshower(1, -1, 2 * b, ccbmat, "虚电量" + Str(kk))
For k = 1 To b
mapform.analysisresult.AddItem (cellname(branch1(k - 1).cellcon(0)) + "U:" + Str(FormatNumber(cbmat(b + k), 5, vbTrue)) + "+j*" + Str(FormatNumber(ccbmat(k), 5, vbTrue)))
mapform.analysisresult.AddItem ("---------I是:" + Str(FormatNumber(cbmat(k), 5, vbTrue)) + "+j*" + Str(FormatNumber(ccbmat(k), 5, vbTrue)))
Next k
End If
End If
'-------------------------------------------
For k = 0 To b - 1
mapform.cell(branch1(k).cellcon(0)).cellcurrent = Sqr((mapform.cell(branch1(k).cellcon(0)).cellcurrent) ^ 2 + CGetA(cbmat(k + 1), ccbmat(k + 1)) ^ 2)
Next k
'=============================This is only one of the circles!
'$$$$$$$$$$$$$$$$ The next are the print options!!!!!!!!!!$$$$$$$$$$$$$$$$$$$$$$$$$$
If analysistype = 0 Then
If kk = 0 Then
notepad.Text1.Text = "元件 电量幅值 相位 "
End If
If cellcurrentop = 1 Then
strtry = "------------频率" + Str(nowfrequency(kk)) + "---------"
If Len(strtry) < 39 Then
For kkk = 0 To 37 - Len(strtry)
strtry = strtry + "-"
Next kkk
strtry = strtry + " "
End If
notepad.Text1.Text = notepad.Text1.Text + strtry
For k = 0 To counts - 1
strtry = Format(k) + " " + Str(FormatNumber(CGetA(cbmat(mapform.cell(k).cellinbranch + 1), ccbmat(mapform.cell(k).cellinbranch + 1)), 8)) + "A " + Str(FormatNumber(CGetalpha(cbmat(mapform.cell(k).cellinbranch + 1), ccbmat(mapform.cell(k).cellinbranch + 1)), 2)) + " "
If Len(strtry) < 39 Then
For kkk = 0 To 39 - Len(strtry)
strtry = strtry + " "
Next kkk
End If
notepad.Text1.Text = notepad.Text1.Text + strtry
Next k
End If
If cellvoltop = 1 Then
If cellcurrentop = 0 Then
strtry = "-----------频率" + Str(nowfrequency(kk)) + "---------"
If Len(strtry) < 39 Then
For kkk = 0 To 37 - Len(strtry)
strtry = strtry + "-"
Next kkk
strtry = strtry + " "
notepad.Text1.Text = notepad.Text1.Text + strtry
End If
End If
For k = 0 To counts - 1
strtry = Format(k) + " " + Str(FormatNumber(CGetA(cbmat(mapform.cell(k).cellinbranch + 1 + b), ccbmat(mapform.cell(k).cellinbranch + 1 + b)), 8)) + "V " + Str(FormatNumber(CGetalpha(cbmat(mapform.cell(k).cellinbranch + 1 + b), ccbmat(mapform.cell(k).cellinbranch + 1) + b), 2)) + " "
If Len(strtry) < 39 Then
For kkk = 0 To 39 - Len(strtry)
strtry = strtry + " "
Next kkk
End If
notepad.Text1.Text = notepad.Text1.Text + strtry
Next k
End If
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
End If
Call readnodeinfo(CInt(kk))
ReDim xsmat(1 To 2 * b, 1 To 2 * b) As Single
ReDim cbmat(1 To 2 * b) As Single
ReDim cxsmat(1 To 2 * b, 1 To 2 * b) As Single
ReDim ccbmat(1 To 2 * b) As Single
Next kk
'===============================================
'要删除一些中间态的变量!比如nowfrequency
''''''''''''''Caution there is a big bug!''''''''''''''
'ReDim nowfrequency(0) As Single
End Function
Sub readnodeinfo(freindex As Integer)
'''''''''''''''''''''''''''''''''''''''''''''''''''
'R mat is cbmat and I is ccbmat they are n*1 matix'
'''''''''''''''''''''''''''''''''''''''''''''''''''
errortype = 8
Dim k As Integer
Dim temp() As Single
Dim ctemp() As Single
Dim ctree_node() As Single
ReDim temp(1 To n) As Single
ReDim ctemp(1 To n) As Single
ReDim ctree_node(n, n) As Single
ReDim tree_node(n, n) As Single
For k = 1 To n - 1
tree_node(k, branch1(tree(k - 1)).bend(0) + 1) = 1
tree_node(k, branch1(tree(k - 1)).bend(1) + 1) = -1
Next k
tree_node(n, zeronode + 1) = 1
For k = 0 To n - 2
temp(k + 1) = cbmat(tree(k) + b + 1)
ctemp(k + 1) = ccbmat(tree(k) + b + 1)
Next k
If LECpxGauss(CInt(n), tree_node(), ctree_node(), temp(), ctemp()) = True Then
For k = 0 To n - 1
nodevinfo(k, freindex).a = CGetA(CSng(temp(k + 1)), CSng(ctemp(k + 1)))
nodevinfo(k, freindex).alpha = CGetalpha(CSng(temp(k + 1)), CSng(ctemp(k + 1)) * pi / 180)
Next k
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Then to write a programme to change its style into another way!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
Function makenodevolt()
Dim k, m As Integer
For k = 0 To nodecounts - 1
For m = 0 To frequencytype
mapform.node(k).Tag = mapform.node(k).Tag + nodevinfo(k, m).a ^ 2
Next m
mapform.node(k).Tag = Sqr(mapform.node(k).Tag)
Next k
End Function
Sub printnodeinfo()
Dim k, kk, kkk As Integer
Dim strtry As String
notepad.Text1.Text = notepad.Text1.Text + "---------------节点信息----------------- "
notepad.Text1.Text = notepad.Text1.Text + "节点 电压幅值 相位 "
For kk = 0 To frequencytype
strtry = "-----------频率" + Str(nowfrequency(kk)) + "--------"
If Len(strtry) < 39 Then
For kkk = 0 To 37 - Len(strtry)
strtry = strtry + "-"
Next kkk
strtry = strtry + " "
notepad.Text1.Text = notepad.Text1.Text + strtry
End If
For k = 0 To nodecounts - 1
strtry = Format(k) + " " + Str(nodevinfo(k, kk).a) + " " + Str(nodevinfo(k, kk).alpha) + " "
If Len(strtry) < 39 Then
For kkk = 0 To 39 - Len(strtry)
strtry = strtry + " "
Next kkk
End If
notepad.Text1.Text = notepad.Text1.Text + strtry
Next k
Next kk
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -