您的位置:程序门 -> vb -> 基础类



vb程序设计中遇到的问题急.....


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb程序设计中遇到的问题急.....
发表于:2007-05-06 21:19:06 楼主
for   i   =   0   to   xx  
a   =   split(text9(i),   ", ")  
for   j   =   0   to   ubound(a)  
select   case   i  
case   0:   text1(j).text   =   a(j)  
case   1:   text2(j).text   =   a(j)  
case   2:   text3(j).text   =   a(j)  
case   3:   text4(j).text   =   a(j)  
case   4:   text5(j).text   =   a(j)  
case   5:   text6(j).text   =   a(j)  
case   6:   text7(j).text   =   a(j)  
case   7:   text8(j).text   =   a(j)  

end   select  

next   j  
next   i  
===  
上面的代码有text1(),text2()......text9()等数组,  
我用上面的循环来text9()数组里面输入的内容,分别发送到text1()....text8()数组里面。。  
意思就是说text9()有9个输入框,比如text9(0)输入的内容,按照“/”来分发送到text1()数组里面,  
其他的意思类推。。  
==================================  
问题:  

现在我想在建立一个text10()数组,想text1()各元素的平均值填充到text10(0)里面,text2()各元素的平均值填充到text10(1)里面....text8()各元素的平均值填充到text10(7)里面.  

各位高手帮我实现此功能  

谢谢,写的时候帮忙注释一下...

希望高手解释以下...
发表于:2007-05-06 23:01:001楼 得分:0
不明不白。
--------------------------------------------------------------
现在我想在建立一个text10()数组,
想text1()各元素的平均值填充到text10(0)里面,
text2()各元素的平均值填充到text10(1)里面....text8()各元素的平均值填充到text10(7)里面.  

发表于:2007-05-07 12:28:012楼 得分:0
option   explicit

private   sub   command1_click()
'假如要将   text1()的平均值显示在text2(1)中,则如下调用
mgetvalue   text1,   text2,   1
end   sub

'参数1:要求平均数的text数组;参数2:显示平均数的控件数组;参数3:显示平均数的控件数组中控件的index
private   sub   mgetvalue(byref   mtextbox   as   object,   byref   textp   as   object,   textpindex   as   long)
dim   mindex   as   long
textp(textpindex).text   =   0
for   mindex   =   0   to   mtextbox.ubound
        textp(textpindex).text   =   textp(textpindex).text   +   cdbl(mtextbox(mindex).text)   /   2
next
end   sub
发表于:2007-05-07 12:29:483楼 得分:0
textp(textpindex).text   =   textp(textpindex).text   +   cdbl(mtextbox(mindex).text)   /   2
这句有点问题哈,呵呵,我测试是用2个元素的...lz改成

textp(textpindex).text   =   textp(textpindex).text   +   cdbl(mtextbox(mindex).text)   /   (mtextbox.ubound+1)

即可
发表于:2007-05-07 13:43:314楼 得分:0
对不起,出错误,说类型不配合.13错误
发表于:2007-05-07 13:58:025楼 得分:0
option   explicit

private   sub   command1_click()
'假如要将   text1()的平均值显示在text2(1)中,则如下调用
text2(1)   =   mgetvalue   "text1 "
end   sub

'参数1:要求平均数的text数组名字的字符串,如text1;
private   function   mgetvalue(byval   strtext   as   string)   as   double
        dim   intcount   as   integer
        dim   dblvalue   as   double
        dim   ctrl   as   control
        for   each   ctrl   in   me.controls
                if   ucase(ctrl.name)   =   ucase(strtext)   then
                        intcount   =   intcount   +   1
                        dblvalue   =   dblvalue   +   val(ctrl.text)
                end   if
        next
        mgetvalue   =   dblvalue   /   intcount
end   function
发表于:2007-05-07 13:59:446楼 得分:0
上面

mgetvalue   =   dblvalue   /   intcount
改成以下,以防止出错
if   intcount <> 0   then
          mgetvalue   =   dblvalue   /   intcount
end   if
发表于:2007-05-08 12:35:297楼 得分:0
beal_p()谢谢,怎么说缺少语句?
发表于:2007-05-08 13:37:308楼 得分:0
private   sub   command1_click()
'假如要将   text1()的平均值显示在text2(1)中,则如下调用
text2(1).text   =   mgetvalue( "text1 ")
end   sub
发表于:2007-05-08 14:28:529楼 得分:0
再次谢谢beal_p()  , 还遇到一个问题,你这个函数找平均值出了一点问题,
问题就是:比如说,我的text1()是10个元素组成的,按照你的程序来计算intcount 等于10了,
这样下来,我只输入text1(0).text= "1 ",text1(1).text= "2 ",text1(2).text= "3 ",其他的是空,
用你的程序计算mgetvalue=0.6了? 这个如何解决?
答案应该是2吧?


...谢谢
发表于:2007-05-08 14:37:1710楼 得分:0
你的意思是,   假如某些text是非数值,就不计在内?   那也好办
if   ucase(ctrl.name)   =   ucase(strtext)   then
              if   isnumeric(ctrl.text)   then
                        intcount   =   intcount   +   1
                        dblvalue   =   dblvalue   +   val(ctrl.text)
              end   if
end   if
'如果要求为0即不计算在内哪就改为如下
if   ucase(ctrl.name)   =   ucase(strtext)   then
              if   val(ctrl.text) <> 0   then
                        intcount   =   intcount   +   1
                        dblvalue   =   dblvalue   +   val(ctrl.text)
              end   if
end   if


快速检索

最新资讯
热门点击