| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3789 人关注过本帖
标题:VB6.0编程 手动输入数据,计算求和,平均值,差值,平方后开方再分类 代码讨 ...
只看楼主 加入收藏
oric2010
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-7-4
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
VB6.0编程 手动输入数据,计算求和,平均值,差值,平方后开方再分类 代码讨论
本人要做一个程序, 交互式窗口,手动输入100个数据,求平均值、平方后再开方和自动分类,
程序功能:1、手动指定录入1-100任意个数据,数据类型double;
2、计算录入的数据个数n;
3、求n个数据的平均值;
4、n个数据每一个与其平均值的差;
5、第4步计算的每一个数据平方再开方,这个值假定代号为X;
6、第5步计算的值分类,分五类:A+类:X≥1.67;A类:1.33≤X<1.67;B类:1.0≤X<1.33;C类:0.67≤X<1.0;D类:X<0.67。
程序界面如图中所示要求,我做到了求和,但不会统计textbox有效数据个数,做不到后面的功能, 求高手指点迷津!!!
程序代码如下:
Private Sub Command1_Click()
Dim t As Double, i As Double, a As Double, b As Double, c As Double, d As Double, e As Double, f As Double, g As Double, h As Double, j As Double, k As Double, l As Double, m As Double, n As Double, p As Double
i = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text)
a = Val(Text8.Text) + Val(Text9.Text) + Val(Text10.Text) + Val(Text11.Text) + Val(Text12.Text) + Val(Text13.Text) + Val(Text14.Text)
b = Val(Text15.Text) + Val(Text16.Text) + Val(Text17.Text) + Val(Text18.Text) + Val(Text19.Text) + Val(Text20.Text) + Val(Text21.Text)
c = Val(Text22.Text) + Val(Text23.Text) + Val(Text24.Text) + Val(Text25.Text) + Val(Text26.Text) + Val(Text27.Text) + Val(Text28.Text)
d = Val(Text29.Text) + Val(Text30.Text) + Val(Text31.Text) + Val(Text32.Text) + Val(Text33.Text) + Val(Text34.Text) + Val(Text35.Text)
e = Val(Text36.Text) + Val(Text37.Text) + Val(Text38.Text) + Val(Text39.Text) + Val(Text40.Text) + Val(Text41.Text) + Val(Text42.Text)
f = Val(Text43.Text) + Val(Text44.Text) + Val(Text45.Text) + Val(Text46.Text) + Val(Text47.Text) + Val(Text48.Text) + Val(Text49.Text)
g = Val(Text50.Text) + Val(Text51.Text) + Val(Text52.Text) + Val(Text53.Text) + Val(Text54.Text) + Val(Text55.Text)
h = Val(Text56.Text) + Val(Text57.Text) + Val(Text58.Text) + Val(Text59.Text) + Val(Text60.Text) + Val(Text61.Text)
j = Val(Text62.Text) + Val(Text63.Text) + Val(Text64.Text) + Val(Text65.Text) + Val(Text66.Text) + Val(Text67.Text) + Val(Text68.Text)
k = Val(Text69.Text) + Val(Text70.Text) + Val(Text71.Text) + Val(Text72.Text) + Val(Text73.Text) + Val(Text74.Text) + Val(Text75.Text)
l = Val(Text76.Text) + Val(Text77.Text) + Val(Text78.Text) + Val(Text79.Text) + Val(Text80.Text) + Val(Text81.Text) + Val(Text82.Text)
m = Val(Text83.Text) + Val(Text84.Text) + Val(Text85.Text) + Val(Text86.Text) + Val(Text87.Text) + Val(Text88.Text) + Val(Text89.Text)
n = Val(Text90.Text) + Val(Text91.Text) + Val(Text92.Text) + Val(Text93.Text) + Val(Text94.Text) + Val(Text95.Text) + Val(Text96.Text)
p = Val(Text97.Text) + Val(Text98.Text) + Val(Text99.Text) + Val(Text100.Text)

t = i + a + b + c + d + e + f + g + h + j + k + l + m + n + p
Picture6.Print t

End Sub

Private Sub Picture6_Click()
Picture6.Cls
End Sub

Private Sub Text1_Change()
Dim Text1 As Double

End Sub

Private Sub Text10_Change()
Dim Text10 As Double
End Sub

Private Sub Text100_Change()
Dim Text100 As Double
End Sub

Private Sub Text101_Change()
Dim text101 As Double
i = text101
End Sub

Private Sub Text11_Change()
Dim Text11 As Double
End Sub

Private Sub Text12_Change()
Dim Text12 As Double
End Sub

Private Sub Text13_Change()
Dim Text13 As Double
End Sub

Private Sub Text14_Change()
Dim Text14 As Double
End Sub

Private Sub Text15_Change()
Dim Text15 As Double
End Sub

Private Sub Text16_Change()
Dim Text16 As Double
End Sub

Private Sub Text17_Change()
Dim Text17 As Double
End Sub

Private Sub Text18_Change()
Dim Text18 As Double
End Sub

Private Sub Text19_Change()
Dim Text19 As Double
End Sub

Private Sub Text2_Change()
Dim Text2 As Double
End Sub

Private Sub Text20_Change()
Dim Text20 As Double
End Sub

Private Sub Text21_Change()
Dim Text21 As Double
End Sub

Private Sub Text22_Change()
Dim Text22 As Double
End Sub

Private Sub Text23_Change()
Dim Text23 As Double
End Sub

Private Sub Text24_Change()
Dim Text24 As Double
End Sub

Private Sub Text25_Change()
Dim Text25 As Double
End Sub

Private Sub Text26_Change()
Dim Text26 As Double
End Sub

Private Sub Text27_Change()
Dim Text27 As Double
End Sub

Private Sub Text28_Change()
Dim Text28 As Double
End Sub

Private Sub Text29_Change()
Dim Text29 As Double
End Sub

Private Sub Text3_Change()
Dim Text3 As Double
End Sub

Private Sub Text30_Change()
Dim Text30 As Double
End Sub

Private Sub Text31_Change()
Dim Text31 As Double
End Sub

Private Sub Text32_Change()
Dim Text32 As Double
End Sub

Private Sub Text33_Change()
Dim Text33 As Double
End Sub

Private Sub Text34_Change()
Dim Text34 As Double
End Sub

Private Sub Text35_Change()
Dim Text35 As Double
End Sub

Private Sub Text36_Change()
Dim Text36 As Double
End Sub

Private Sub Text37_Change()
Dim Text37 As Double
End Sub

Private Sub Text38_Change()
Dim Text38 As Double
End Sub

Private Sub Text39_Change()
Dim Text39 As Double
End Sub

Private Sub Text4_Change()
Dim Text4 As Double
End Sub

Private Sub Text40_Change()
Dim Text40 As Double
End Sub

Private Sub Text41_Change()
Dim Text41 As Double
End Sub

Private Sub Text42_Change()
Dim Text42 As Double
End Sub

Private Sub Text43_Change()
Dim Text43 As Double
End Sub

Private Sub Text44_Change()
Dim Text44 As Double
End Sub

Private Sub Text45_Change()
Dim Text45 As Double
End Sub

Private Sub Text46_Change()
Dim Text46 As Double
End Sub

Private Sub Text47_Change()
Dim Text47 As Double
End Sub

Private Sub Text48_Change()
Dim Text48 As Double
End Sub

Private Sub Text49_Change()
Dim Text49 As Double
End Sub

Private Sub Text5_Change()
Dim Text5 As Double
End Sub

Private Sub Text50_Change()
Dim Text50 As Double
End Sub

Private Sub Text51_Change()
Dim Text51 As Double
End Sub

Private Sub Text52_Change()
Dim Text52 As Double
End Sub

Private Sub Text53_Change()
Dim Text53 As Double
End Sub

Private Sub Text54_Change()
Dim Text54 As Double
End Sub

Private Sub Text55_Change()
Dim Text55 As Double
End Sub

Private Sub Text56_Change()
Dim Text56 As Double
End Sub

Private Sub Text57_Change()
Dim Text57 As Double
End Sub

Private Sub Text58_Change()
Dim Text58 As Double
End Sub

Private Sub Text59_Change()
Dim Text59 As Double
End Sub

Private Sub Text6_Change()
Dim Text6 As Double
End Sub

Private Sub Text60_Change()
Dim Text60 As Double
End Sub

Private Sub Text61_Change()
Dim Text61 As Double
End Sub

Private Sub Text62_Change()
Dim Text62 As Double
End Sub

Private Sub Text63_Change()
Dim Text63 As Double
End Sub

Private Sub Text64_Change()
Dim Text64 As Double
End Sub

Private Sub Text65_Change()
Dim Text65 As Double
End Sub

Private Sub Text66_Change()
Dim Text66 As Double
End Sub

Private Sub Text67_Change()
Dim Text67 As Double
End Sub

Private Sub Text68_Change()
Dim Text68 As Double
End Sub

Private Sub Text69_Change()
Dim Text69 As Double
End Sub

Private Sub Text7_Change()
Dim Text7 As Double
End Sub

Private Sub Text70_Change()
Dim Text70 As Double
End Sub

Private Sub Text71_Change()
Dim Text71 As Double
End Sub

Private Sub Text72_Change()
Dim Text72 As Double
End Sub

Private Sub Text73_Change()
Dim Text73 As Double
End Sub

Private Sub Text74_Change()
Dim Text74 As Double
End Sub

Private Sub Text75_Change()
Dim Text75 As Double
End Sub

Private Sub Text76_Change()
Dim Text76 As Double
End Sub

Private Sub Text77_Change()
Dim Text77 As Double
End Sub

Private Sub Text78_Change()
Dim Text78 As Double
End Sub

Private Sub Text79_Change()
Dim Text79 As Double
End Sub

Private Sub Text8_Change()
Dim Text8 As Double
End Sub

Private Sub Text80_Change()
Dim Text80 As Double
End Sub

Private Sub Text81_Change()
Dim Text81 As Double
End Sub

Private Sub Text82_Change()
Dim Text82 As Double
End Sub

Private Sub Text83_Change()
Dim Text83 As Double
End Sub

Private Sub Text84_Change()
Dim Text84 As Double
End Sub

Private Sub Text85_Change()
Dim Text85 As Double
End Sub

Private Sub Text86_Change()
Dim Text86 As Double
End Sub

Private Sub Text87_Change()
Dim Text87 As Double
End Sub

Private Sub Text88_Change()
Dim Text88 As Double
End Sub

Private Sub Text89_Change()
Dim Text89 As Double
End Sub

Private Sub Text9_Change()
Dim Text9 As Double
End Sub

Private Sub Text90_Change()
Dim Text90 As Double
End Sub

Private Sub Text91_Change()
Dim Text91 As Double
End Sub

Private Sub Text92_Change()
Dim Text92 As Double
End Sub

Private Sub Text93_Change()
Dim Text93 As Double
End Sub

Private Sub Text94_Change()
Dim Text94 As Double
End Sub

Private Sub Text95_Change()
Dim Text95 As Double
End Sub

Private Sub Text96_Change()
Dim Text96 As Double
End Sub

Private Sub Text97_Change()
Dim Text97 As Double
End Sub

Private Sub Text98_Change()
Dim Text98 As Double
End Sub

Private Sub Text99_Change()
Dim Text99 As Double
End Sub

图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: double 平均值 统计 
2016-07-08 17:26
oric2010
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-7-4
收藏
得分:0 
自己顶,求高手指点迷津
2016-07-09 15:22
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:5 
用数组控件可能比较容易实现。
问题2 我的代码是:
 For i = 0 To 99
   If  Text1(i) <> "" Then n = n + 1
 Next i
   MsgBox n
其他的估计你都可以自己写了

调试失败3次后,关机睡觉,当醒来时多有收获。
2016-07-09 21:21
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:941
专家分:5244
注 册:2015-8-10
收藏
得分:5 
建议使用控件数组,或者gird控件。
2016-07-10 09:44
ZHRXJR
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:125
帖 子:1034
专家分:5519
注 册:2016-5-10
收藏
得分:5 
程序代码:
Private Sub Command1_Click()
Dim n As Integer, t As Double, s As Double
For I = 0 To 99
If Val(Text1(I).Text) <> 0 Then
    n = n + 1   '计算录入的数据个数n
    t = t + Val(Text1(I).Text)   '计算数据和
End If
Next I
Label1.Caption = "指标数据录入共" & n & ""
s = t / n      '求n个数据的平均值
Dim a(0 To 99) As Double
For I = 0 To 99
If Val(Text1(I).Text) <> 0 Then
    a(I) = s - Val(Text1(I).Text) 'n个数据每一个与其平均值的差;
End If
Next I
'5、第4步计算的每一个数据平方再开方,这个值假定代号为X;
'估计你是要得到这个数的绝对值吧
Dim X(0 To 99) As Double
For I = 0 To 99
If Val(Text1(I).Text) <> 0 Then
    X(I) = Abs(Val(Text1(I).Text))  ''估计你是要得到这个数的绝对值吧
    '
    X(I) = Sqr(Val(Text1(I).Text) ^ 2)    '计算的每一个数据平方再开方,这个值假定代号为X;
End If
Next I
'设定你的A+类的文本框是TextA,A类的文本框是TextA1,B类的文本框是TextB,C类的文本框是TextC,D类的文本框是TextD。
'这些文本框必须是多行文本框
For I = 0 To 99
    If X(I) >= 1.67 Then
        TextA.Text = TextA.Text & X(I) & Space(3)        'A+类:X≥1.67;
    ElseIf X(I) < 1.67 And X(I) >= 1.33 Then
        TextA1.Text = TextA1.Text & X(I) & Space(3)        'A类:1.33≤X<1.67;
    ElseIf X(I) < 1.33 And X(I) >= 1# Then
        TextB.Text = TextB.Text & X(I) & Space(3)        'B类:1.0≤X<1.33;
    ElseIf X(I) < 1# And X(I) >= 0.67 Then
        TextC.Text = TextC.Text & X(I) & Space(3)        'C类:0.67≤X<1.0;
    ElseIf X(I) < 0.67 Then
        TextD.Text = TextD.Text & X(I) & Space(3)        'D类:X<0.67
    End If
Next I
End Sub

利用数组可以节省大量代码。

请不要选我!!!
2016-07-10 10:31
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:5 
'这样可以对Text控件的文本做判断,true是有效数据,false无效
Private Function NumJudge(str As String) As Boolean
Dim i As Integer: Dim num_dot As Integer: num_dot = 0
Dim digit As String
Dim length As Integer: length = Len(str)
For i = 1 To length
  digit = Mid(str, i, 1)
  Select Case digit
  Case "0":
  Case "1":
  Case "2":
  Case "3":
  Case "4":
  Case "5":
  Case "6":
  Case "7":
  Case "8":
  Case "9":
  Case ".":
      num_dot = num_dot + 1
      If i = 1 Or i = length Then
          NumJudge = False: Exit Function
      End If
  Case Else:
      NumJudge = False: Exit Function
  End Select
  If num_dot > 1 Then
     NumJudge = False: Exit Function
  End If
Next i
NumJudge = True
End Function
2016-07-10 14:18
快速回复:VB6.0编程 手动输入数据,计算求和,平均值,差值,平方后开方再分类 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024320 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved