Flexgrid 中的 Vb6 分组值
Vb6 Grouping Values in Flexgrid
我有一个 Flexgrid(vb6 不是 .Net)与任何 Db 断开连接,有一些行如下:
135,00 4
218,00 4
100,00 10
6,00 4
15,00 22
我无法创建一个循环来获取我在网格上有多少个不同的组(按增值税)并计算相对数量
3 组(在本例中为 4 / 10 / 22)
4 = 359,00 10 = 100 22 = 15,00
我不想使用带有 select 分组依据的数据库,而是预先计算数量并在 n 文本框中可视化。
这是我试过的代码
Dim A, b, c, d
if A = "" Then
A = xNum
ElseIf A <> "" Then
If A <> xNum Then
If b = "" Then
b = xNum
ElseIf b <> "" Then
If b <> xNum Then
If c = "" Then
c = xNum
ElseIf c <> "" Then
If c <> xNum Then
If d = "" Then
d = xNum
ElseIf d <> "" Then [etc...]
感谢您的帮助。
我假设您使用的是 Microsoft FlexGrid 控件,其中第一列是数量,第二列是增值税。
以下代码将产生文本框中显示的结果:
Option Explicit
Private Sub cmdCalc_Click()
On Error Resume Next
Dim c As Collection
Dim i As Integer
Dim g As Group
Dim data As String
'calculate groups
Set c = New Collection
For i = 1 To MSFlexGrid1.Rows - 1
Set g = New Group
g.VAT = CInt(MSFlexGrid1.TextMatrix(i, 2))
g.Qty = CDbl(MSFlexGrid1.TextMatrix(i, 1))
Err.Clear
c.Add g, CStr(g.VAT)
If Err.Number > 0 Then c(CStr(g.VAT)).Qty = c(CStr(g.VAT)).Qty + g.Qty
Next
'and visualize the data
For Each g In c
data = data & g.VAT & vbTab & g.Qty & vbCrLf
Next
Text1.Text = data
End Sub
此代码的基本思想是构建一组对象的集合,网格中的每一行对应一个组。随着组被添加到集合中,错误捕获用于检测重复项并在这些情况下增加数量。
这里是上面代码使用的Group
class:
Option Explicit
Private m_VAT As Integer
Private m_Qty As Double
Public Property Get VAT() As Integer
VAT = m_VAT
End Property
Public Property Let VAT(ByVal Value As Integer)
m_VAT = Value
End Property
Public Property Get Qty() As Double
Qty = m_Qty
End Property
Public Property Let Qty(ByVal Value As Double)
m_Qty = Value
End Property
我有一个 Flexgrid(vb6 不是 .Net)与任何 Db 断开连接,有一些行如下:
135,00 4
218,00 4
100,00 10
6,00 4
15,00 22
我无法创建一个循环来获取我在网格上有多少个不同的组(按增值税)并计算相对数量 3 组(在本例中为 4 / 10 / 22) 4 = 359,00 10 = 100 22 = 15,00 我不想使用带有 select 分组依据的数据库,而是预先计算数量并在 n 文本框中可视化。
这是我试过的代码
Dim A, b, c, d
if A = "" Then
A = xNum
ElseIf A <> "" Then
If A <> xNum Then
If b = "" Then
b = xNum
ElseIf b <> "" Then
If b <> xNum Then
If c = "" Then
c = xNum
ElseIf c <> "" Then
If c <> xNum Then
If d = "" Then
d = xNum
ElseIf d <> "" Then [etc...]
感谢您的帮助。
我假设您使用的是 Microsoft FlexGrid 控件,其中第一列是数量,第二列是增值税。
以下代码将产生文本框中显示的结果:
Option Explicit
Private Sub cmdCalc_Click()
On Error Resume Next
Dim c As Collection
Dim i As Integer
Dim g As Group
Dim data As String
'calculate groups
Set c = New Collection
For i = 1 To MSFlexGrid1.Rows - 1
Set g = New Group
g.VAT = CInt(MSFlexGrid1.TextMatrix(i, 2))
g.Qty = CDbl(MSFlexGrid1.TextMatrix(i, 1))
Err.Clear
c.Add g, CStr(g.VAT)
If Err.Number > 0 Then c(CStr(g.VAT)).Qty = c(CStr(g.VAT)).Qty + g.Qty
Next
'and visualize the data
For Each g In c
data = data & g.VAT & vbTab & g.Qty & vbCrLf
Next
Text1.Text = data
End Sub
此代码的基本思想是构建一组对象的集合,网格中的每一行对应一个组。随着组被添加到集合中,错误捕获用于检测重复项并在这些情况下增加数量。
这里是上面代码使用的Group
class:
Option Explicit
Private m_VAT As Integer
Private m_Qty As Double
Public Property Get VAT() As Integer
VAT = m_VAT
End Property
Public Property Let VAT(ByVal Value As Integer)
m_VAT = Value
End Property
Public Property Get Qty() As Double
Qty = m_Qty
End Property
Public Property Let Qty(ByVal Value As Double)
m_Qty = Value
End Property