| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 724 人关注过本帖
标题:求和求平均问题~~~
只看楼主 加入收藏
yaya_zy
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-6
收藏
 问题点数:0 回复次数:4 
求和求平均问题~~~
我又来问了~~上次的问题得到了圆满的解答~~谢谢~~

可是又遇到问题了~~果然是新手呢~~

那个sum 和 avg~~好像是不能运算 varchar类型的~~

可是因为我和OPC连~~数据类型只能定varchar~~

那么在 vb里面能不能求得总和和平均数啊~~
搜索更多相关主题的帖子: 求和 
2008-06-08 00:01
hxfly
Rank: 5Rank: 5
等 级:贵宾
威 望:17
帖 子:5810
专家分:118
注 册:2005-4-7
收藏
得分:0 
强制类型转换

cint(变量),把变量强制转换成整型
CDBL(变量),变量强制转换成浮点型

还有很多呢,自己查下帮助也行

2008-06-08 14:56
yaya_zy
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-6
收藏
得分:0 
改了还是又问题额~~还是说我VARCHAR的问题~~·

下面是我的代码~~好像有点长~~不过毕业设计急~~所以麻烦大家了~~

Private Sub Form_Load()

LSH_T = CInt(LSH_T)

PSH_T = CInt(PSH_T)

HSH_T = CInt(HSH_T)

SA1_T = CInt(SA1_T)

SA2_T = CInt(SA2_T)

SA1_LQ = CInt(SA1_LQ)

SA1_RQ = CInt(SA1_RQ)

SA2_LQ = CInt(SA2_LQ)

SA2_RQ = CInt(SA2_RQ)

sql = "select * from ls"
Adodc1.RecordSource = sql
Set DataGrid1.DataSource = Adodc1
DataGrid1.Caption = ""
Combo1.AddItem "LSH_T"             '在下拉条中添加10个选项名
Combo1.AddItem "PSH_T"
Combo1.AddItem "HSH_T"
Combo1.AddItem "SA1_T"
Combo1.AddItem "SA2_T"
Combo1.AddItem "SA1_LQ"
Combo1.AddItem "SA1_RQ"
Combo1.AddItem "SA2_LQ"
Combo1.AddItem "SA2_RQ"


Combo2.AddItem "最大值"             '
Combo2.AddItem "最小值"
Combo2.AddItem "平均值"
Combo2.AddItem "总和"



End Sub

Private Sub Command2_Click()


If Combo2.Text = "平均值" Then

  sql = "select avg(LSH_T) as LSH_T,avg(PSH_T) as PSH_T,avg(HSH_T) as HSH_T,avg(SA1_T) as SA1_T,avg(SA2_T) as SA2_T,avg(SA1_LQ) as SA1_LQ,avg(SA1_RQ) as SA1_RQ,avg(SA2_LQ) as SA2_LQ,avg(SA2_RQ) as SA2_RQ from ls"
  Adodc1.RecordSource = sql
  Set DataGrid1.DataSource = Adodc1
  Adodc1.Refresh
  DataGrid1.Caption = "平均值"
End If
If Combo2.Text = "总和" Then

  sql = "select sum(LSH_T) as LSH_T,sum(PSH_T) as PSH_T,sum(HSH_T) as HSH_T,sum(SA1_T) as SA1_T,sum(SA2_T) as SA2_T,sum(SA1_LQ) as SA1_LQ,sum(SA1_RQ) as SA1_RQ,sum(SA2_LQ) as SA2_LQ,sum(SA2_RQ) as SA2_RQ from ls"
  Adodc1.RecordSource = sql
  Set DataGrid1.DataSource = Adodc1
  Adodc1.Refresh
  DataGrid1.Caption = "总和"
End If
End Sub
2008-06-08 22:44
yaya_zy
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-6
收藏
得分:0 
问题已经解决了~~我在OPC里改了数据类型~~
2008-06-09 10:59
jxyga111
Rank: 8Rank: 8
来 自:中華人民共和國
等 级:贵宾
威 望:33
帖 子:6015
专家分:895
注 册:2008-3-21
收藏
得分:0 
再加上val
2008-06-10 19:28
快速回复:求和求平均问题~~~
数据加载中...
 
   



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

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