VB程序设计中遇到的问题急
我设计了一个模拟实验程序~现在遇到问题是:
程序CODE
===================================================================
Dim si(20), mi(20), a1(20), a2(20), a3(20) As Single
Dim s, l, m As String
Dim y, n, w, p, up, boyi, boyi2, i, j As Integer
Private Sub Command1_Click()
'输入s 的值
Dim b1() As String
y = Text4
n = 0
w = 9
p = Text5
up = Text6
CurrentX = 0
CurrentY = 540
Print Tab(28); "ρ="; p; " Kg/m"
CurrentX = 0
CurrentY = 4200
Print Tab(4); "u(ρ)="; up; " Kg/m"
For i = 1 To y
b1 = Split(Text1, "/")
a1(i) = Val(b1(i))
CurrentX = 0
CurrentY = 1000
Print Tab(w); " 数据"; i;
CurrentX = 0
CurrentY = 1350
Print Tab(4); "s"; Tab(w); a1(i)
w = w + 9
Next i
' 输入L的值
Dim b2() As String
y = Text4
n = 0
w = 10
For i = 1 To y
b2 = Split(Text2, "/")
a2(i) = Val(b2(i))
CurrentX = 0
CurrentY = 1850
Print Tab(4); "L(m)"; Tab(w); Format$(a2(i), "0.00")
'n = n + 300
w = w + 9
Next i
'输入m的值
Dim b3() As String
y = Text4
n = 0
w = 10
For i = 1 To y
b3 = Split(Text3, "/")
a3(i) = Val(b3(i))
CurrentX = 0
CurrentY = 2350
Print Tab(4); "M(kg)"; Tab(w); Format$(a3(i), "0.00")
w = w + 9
Next i
End Sub
Private Sub Command2_Click()
'弦的振动数据处理
Dim l(20), pju, u(20), uhj, t4(20), xdu, pchu, abqddu, bbqddu, zbqddu, z, d, pchu1(20), l2, t, pjl, t1, mgtl(20), pjtl, pchu2 As Single
y = Text4
uhj = 0
p = Val(Text5)
up = Val(Text6)
w = 10
pjdu1 = 0
For j = 1 To y '计算半波长和拉力 T ,音叉频率
t1 = 0
l1 = 0
pchu2 = 0
l(j) = Int((a2(j) / a1(j)) * 100) / 100 '计算 l 半波长
t4(j) = Int((a3(j) * 9.8) * 100) / 100 '计算 T 拉力
CurrentX = 0
CurrentY = 2800
Print Tab(4); "l(m)"; Tab(w); Format$(l(j), "0.00") '输出 l
l1 = l1 + l(j) '计算 l 的合计
u(j) = (1 / (2 * l(j))) * Sqr(t4(j) / (p)) '计算音叉频率
uhj = uhj + u(j) '计算音叉频率合计
CurrentX = 0
CurrentY = 3250
Print Tab(4); "T(N)"; Tab(w); Format$(t4(j), "0.00") '输出 T
t1 = t1 + t4(j) '计算 T 的合计
CurrentX = 0
CurrentY = 3700
Print Tab(3); "υ(Hz)"; Tab(w); Format$(u(j), "0.00") '输出频率值
w = w + 9
Next j
pjl = Int((l1 / y) * 100) / 100 '计算 l 的平均
t = Int((t1 / y) * 100) / 100 '计算 T 的平均
pju = Int((uhj / y) * 100) / 100 '计算频率平均值
CurrentX = 0
CurrentY = 4600
Print Tab(8); "音叉频率平均值 = "; Format$(pju, "0.00"); " Hz" '输出频率平均值
pjtl = (Sqr(t) / pjl) ^ 2 '计算(((T)^1/2)/l)^2
w = 8
For i = 1 To y
mgtl(i) = (Sqr(t4(i)) / l(i)) ^ 2 '计算 (((Ti)^1/2)/li)^2
pchu1(i) = Int((pjtl - mgtl(i)) * 100) / 100 '计算(((T)^1/2)/l)^2-(((Ti)^1/2)/li)^2
pchu2 = pchu2 + pchu1(i) '计算(((T)^1/2)/l)^2-(((Ti)^1/2)/li)^2 的合计
w = w + 9
pjdu1 = pjdu1 + Abs(pju - u(i))
Next i
pjdu = (1 / y) * pjdu1
CurrentX = 0
CurrentY = 5500
'Print Tab(8); "音叉频率(绝对误差)"; Format$(pjdu, "0.000"); "Hz"
pchu = Int(((1 / (p)) * (1 / (y * (y - 1))) * pchu2) * 100) / 100
'(t / (pjl ^ 2)) ^ 2
zbqddu = Int(((((1 / 2) * Sqr(pchu + ((1 / 4) * (t / (pjl ^ 2)))) * (((up) ^ 2) / (p) ^ 3)))) * 100) / 100
CurrentX = 0
CurrentY = 4900
xdbqddu = zbqddu / pju
Print Tab(8); "合成标准不确定度 = "; Format$(zbqddu, "0.00"); " 相对不确定度 = "; Format$(xdbqddu, "0.00%")
CurrentX = 0
CurrentY = 5200
Print Tab(8); "结果表示 = "; "( "; Format$(pju, "0.00"); " ± "; Format$(zbqddu, "0.00"); " )"; " Hz"
End Sub
Private Sub Command3_Click()
'弦的振动数据刷新
Form1.Cls
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Text4_Click()
y = Text4
End Sub
Private Sub 打印_Click()
PrintForm
End Sub
Private Sub 数据计算_Click()
'弦的振动数据处理
Dim l(20), pju, u(20), uhj, t4(20), xdu, pchu, abqddu, bbqddu, zbqddu, z, d, pchu1(20), l2, t, pjl, t1, mgtl(20), pjtl, pchu2 As Single
y = Text4
uhj = 0
p = Val(Text5)
up = Val(Text6)
w = 10
pjdu1 = 0
For j = 1 To y '计算半波长和拉力 T ,音叉频率
t1 = 0
l1 = 0
pchu2 = 0
l(j) = Int((a2(j) / a1(j)) * 100) / 100 '计算 l 半波长
t4(j) = Int((a3(j) * 9.8) * 100) / 100 '计算 T 拉力
CurrentX = 0
CurrentY = 2800
Print Tab(4); "l(m)"; Tab(w); Format$(l(j), "0.00") '输出 l
l1 = l1 + l(j) '计算 l 的合计
u(j) = (1 / (2 * l(j))) * Sqr(t4(j) / (p)) '计算音叉频率
uhj = uhj + u(j) '计算音叉频率合计
CurrentX = 0
CurrentY = 3250
Print Tab(4); "T(N)"; Tab(w); Format$(t4(j), "0.00") '输出 T
t1 = t1 + t4(j) '计算 T 的合计
CurrentX = 0
CurrentY = 3700
Print Tab(3); "υ(Hz)"; Tab(w); Format$(u(j), "0.00") '输出频率值
w = w + 9
Next j
pjl = Int((l1 / y) * 100) / 100 '计算 l 的平均
t = Int((t1 / y) * 100) / 100 '计算 T 的平均
pju = Int((uhj / y) * 100) / 100 '计算频率平均值
CurrentX = 0
CurrentY = 4600
Print Tab(8); "音叉频率平均值 = "; Format$(pju, "0.00"); " Hz" '输出频率平均值
pjtl = (Sqr(t) / pjl) ^ 2 '计算(((T)^1/2)/l)^2
w = 8
For i = 1 To y
mgtl(i) = (Sqr(t4(i)) / l(i)) ^ 2 '计算 (((Ti)^1/2)/li)^2
pchu1(i) = Int((pjtl - mgtl(i)) * 100) / 100 '计算(((T)^1/2)/l)^2-(((Ti)^1/2)/li)^2
pchu2 = pchu2 + pchu1(i) '计算(((T)^1/2)/l)^2-(((Ti)^1/2)/li)^2 的合计
w = w + 9
pjdu1 = pjdu1 + Abs(pju - u(i))
Next i
pjdu = (1 / y) * pjdu1
CurrentX = 0
CurrentY = 5500
'Print Tab(8); "音叉频率(绝对误差)"; Format$(pjdu, "0.000"); "Hz"
pchu = Int(((1 / (p)) * (1 / (y * (y - 1))) * pchu2) * 100) / 100
zbqddu = Int(((((1 / 2) * Sqr(pchu + ((1 / 4) * (t / (pjl ^ 2)))) * (((up) ^ 2) / (p) ^ 3)))) * 100) / 100
CurrentX = 0
CurrentY = 4900
xdbqddu = zbqddu / pju
Print Tab(8); "合成标准不确定度 = "; Format$(zbqddu, "0.00"); " 相对不确定度 = "; Format$(xdbqddu, "0.00%")
CurrentX = 0
CurrentY = 5200
Print Tab(8); "结果表示 = "; "( "; Format$(pju, "0.00"); " ± "; Format$(zbqddu, "0.00"); " )"; " Hz"
End Sub
Private Sub 数据输入_Click()
'输入s 的值
Dim b1() As String
y = Text4
n = 0
w = 9
p = Text5
up = Text6
CurrentX = 0
CurrentY = 540
Print Tab(28); "ρ="; p; " Kg/m"
CurrentX = 0
CurrentY = 4200
Print Tab(4); "u(ρ)="; up; " Kg/m"
For i = 1 To y
b1 = Split(Text1, "/")
a1(i) = Val(b1(i))
CurrentX = 0
CurrentY = 1000
Print Tab(w); " 数据"; i;
CurrentX = 0
CurrentY = 1350
Print Tab(4); "s"; Tab(w); a1(i)
w = w + 9
Next i
' 输入L的值
Dim b2() As String
y = Text4
n = 0
w = 10
For i = 1 To y
b2 = Split(Text2, "/")
a2(i) = Val(b2(i))
CurrentX = 0
CurrentY = 1850
Print Tab(4); "L(m)"; Tab(w); Format$(a2(i), "0.00")
'n = n + 300
w = w + 9
Next i
'输入m的值
Dim b3() As String
y = Text4
n = 0
w = 10
For i = 1 To y
b3 = Split(Text3, "/")
a3(i) = Val(b3(i))
CurrentX = 0
CurrentY = 2350
Print Tab(4); "M(kg)"; Tab(w); Format$(a3(i), "0.00")
w = w + 9
Next i
End Sub
Private Sub 刷新_Click()
Form1.Cls
End Sub
Private Sub 退出_Click()
End
End Sub
=====================================
1.我想输入的和计算出来的结果用XLS格式保存,以后在可以导入到此程序内.这个如何实现?
2.按照输入的内容用EXCEL的图表打开另一个FORM画出图表.这个如何实现?
3.这个程序上我把表格用直线画出来的,况且输入的用"/"分开写的,自己觉的这样并不太好,如何优化此程序最好,
谢谢高手..
为了方便
程序留了源码下载地址
http://www.32to.com/soft/zp.rar --------------------编程问答-------------------- 楼主去看一下CSV格式,系统默认是用EXCEL打开的.
CSV就是一个文本文件,文件中的一行就是EXCEL中的一行,CSV文件一行中的不同字段用逗号隔开,在EXCEL中就会在同一行自动分隔.
因为本质上就是文本格式,你的程序要读取也非常容易 --------------------编程问答-------------------- 这个你把你输入的数据和输出的数据保存在一张临时表中,在通过VB写程序转EXCEL如过是开发过程序的话转EXCel是比较简单的 --------------------编程问答-------------------- 另外,楼主的代码,实在是问题多多:
Dim si(20), mi(20), a1(20), a2(20), a3(20) As Single
Dim s, l, m As String
Dim y, n, w, p, up, boyi, boyi2, i, j As Integer
只有a3(20),m,j指定了类型,前面的都无类型,容易出现数据转换错误,很难调试
y = Text4
p = Text5
up = Text6
...
最好写成:Text4.Text,不要省略属性
估计楼主是从C转过来的吧,变量名都还是习惯用小写的,VB变量名大小写不敏感的。
建议改成复杂点的有意义的单词吧,首位大写,这样的话,通过VB的自动拼写检查会很容易看出你输入错误了。
补充:VB , 基础类