vb求助,请各位帮忙看看
本帖最后由 bcrun 于 2012-11-18 12:27:52 编辑 这是txt文件
20
2
30
0.00001‘可以自己设定
0.00001’可以自己设定
500
240
25500 , 1.06,9.2
210000 ,195,195
12.5,6000,1
37.5, 1256,2
62.5, 6000, 1
87.5, 6000, 1
112.5,6000, 1
137.5, 6000, 1
162.5, 6000, 1
187.5,6000, 1
212.5, 6000,1
237.5,6000, 1
262.5,6000, 1
287.5,6000, 1
312.5, 6000, 1
337.5, 6000,1
362.5, 6000,1
387.5,6000,1
412.5,6000, 1
437.5,6000, 1
462.5,6000,1
487.5, 6000,1
下面是我编的程序
'主控函数
Private Sub Command1_Click()
Dim c() As String, n As Integer
Open "f:\data.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, s
n = n + 1
Select Case n
Case 1
N_Strip = Val(s)
Case 2
N_Mat = Val(s)
Case 3
Nstep = Val(s)
Case 4
Fai0 = Val(s)
Case 5
DeltFai = Val(s)
Case 6
SecH = Val(s)
Case 7
SecW = Val(s)
Case 8, 9
c = Split(s, ",")
If UBound(c) >= 2 Then
For i = 0 To 2
MatInfo(n - 8, i) = Val(c(i))
Next i
End If
Case Else
c = Split(s, ",")
If UBound(c) >= 2 Then
For i = 0 To 2
StripInfo(n - 10, i) = Val(c(i))
Next i
End If
End Select
Loop
Close #1
For i = 0 To Nstep - 1
For j = 0 To 2
Resu(i, j) = 0
Next j
Next i
CurFai = Fai0
For i = 0 To Nstep - 1
curcent = CalCentroid(CurFai)
Resu(i, 0) = CurFai
Resu(i, 1) = curcent
Resu(i, 2) = CalMoment(i, curcent, CurFai)
CurFai = CurFai + DeltFai
Next i
Open "f:\1.txt" For Output As #2
For i = 0 To Nstep - 1
For j = 0 To 2
Print #2, Resu(i, j);
Next j
Next i
Close #2
End Sub
'二分法查找中性轴函数
Function CalCentroid(cfai As Double)
Dim y1 As Double, y2 As Double, y3 As Double
Dim F1 As Double, F2 As Double, F3 As Double
y1 = 0
y2 = SecH
y3 = (y1 + y2) / 2
Do
F1 = CalAxialForce(y1, cfai)
F2 = CalAxialForce(y2, cfai)
F3 = CalAxialForce(y3, cfai)
If F1 * F3 >= 0 And F2 * F3 <= 0 Then
y1 = y3
y3 = (y1 + y2) / 2
ElseIf F1 * F3 <= 0 And F2 * F3 >= 0 Then
y2 = y3
y3 = (y1 + y2) / 2
Else
i = MsgBox("输入数据错误!", vbCancel + vbExclamation, "输入数据")
End
End If
Loop While Abs(y1 - y2) / SecH > 0.001
CalCentroid = y3
End Function
'计算轴力函数
Function CalAxialForce(cy As Double, fai As Double)
For i = 0 To N_Strip - 1
StripStrain = (cy - StripInfo(i, 0)) * fai / 1000
StripStress = CalStress(StripStrain, StripInfo(i, 2))
StripForce = StripStress * StripInfo(i, 1)
CurF = CurF + StripForce
Next i
CalAxialForce = CurF
End Function
'计算应力函数
Function CalStress(Strain As Double, MatNo As Double)
If MatNo = 1 Then
stress = Strain * MatInfo(MatNo - 1, 0)
If stress >= MatInfo(MatNo - 1, 1) Then stress = 0
If stress <= -MatInfo(MatNo - 1, 2) Then stress = MatInfo(MatNo - 1, 1)
End If
If MatNo = 2 Then
stress = Strain * MatInfo(MatNo - 1, 0)
If stress >= MatInfo(MatNo - 1, 1) Then stress = MatInfo(MatNo - 1, 1)
End If
CalStress = stress
End Function
'计算弯矩函数
Function CalMoment(CStep As Integer, cy As Double, cfai As Double)
For i = 0 To N_Strip - 1
StripStrain = (cy - StripInfo(i, 0)) * cfai / 1000
StripStress = CalStress(StripStrain, StripInfo(i, 2))
StripForce = StripStress * StripInfo(i, 1)
CurM = CurM + StripForce * (cy - StripInfo(i, 0))
Next i
CalMoment = CurM
End Function