Chinaunix首页 | 论坛 | 博客
  • 博客访问: 45250
  • 博文数量: 61
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 550
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-23 14:08
文章分类

全部博文(61)

文章存档

2025年(3)

2024年(14)

2023年(22)

2022年(22)

我的朋友

分类: Windows平台

2025-01-03 10:21:08

'''MSHFLEXGRID横向统计
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
con.Open "Provider=SQLOLEDB.1;Password=xxx;Persist Security Info=True;User ID=sa;Initial Catalog=abc;Data Source=192.168.0.1,1369"
rs.Open "SELECT item_subno,sale_price from bi_t_item_info where item_subno='" & Trim(txt_barcode.Text) & "' ", con, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Set MSHFlexGrid1.DataSource = rs
MSHFlexGrid1.Visible = True


Dim i As Integer
    Dim j As Integer
    Dim sum As Double
    Dim rowCount As Integer
    Dim colCount As Integer
    
    ' 获取 MSHFlexGrid 的行数和列数
    rowCount = MSHFlexGrid1.Rows - 1
    colCount = MSHFlexGrid1.Cols - 1
    
    ' 确保有足够的列来存储结果
    MSHFlexGrid1.Cols = colCount + 2
    
    ' 设置{BANNED}最佳后一列的标题
    MSHFlexGrid1.TextMatrix(0, colCount + 1) = "总和"


    ' 遍历每一行
    For i = 1 To rowCount
        sum = 0
        ' 遍历当前行的每一列
        For j = 2 To colCount
            ' 尝试将单元格中的内容转换为数字并累加到 sum 中
            If IsNumeric(MSHFlexGrid1.TextMatrix(i, j)) Then
                sum = sum + Val(MSHFlexGrid1.TextMatrix(i, j))
            End If
        Next j
        ' 将结果存储在当前行的{BANNED}最佳后一列
        MSHFlexGrid1.TextMatrix(i, colCount + 1) = sum
   Next i
    
Else
MsgBox "no"
End If
阅读(36) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~