原文:
巧用VB6的DataGrid实现通用电子表格
http://www2.ccw.com.cn/tips/9908/080502_11.asp摘要:
方法一:直接使用记录集。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_1
(adoRecordsetX As ADODB.Recordset,
iColX As Integer, iRowX As Integer) As Variant
If iColX < = adoRecordsetX.Fields.Count
- 1 And iRowX < =
adoRecordsetX.RecordCount - 1 Then
adoRecordsetX.Move iRowX, adBookFirst
If IsNull(adoRecordsetX.Fields(iColX).Value) Then
vMyCell_1 = "Null"
Else
vMyCell_1 = adoRecordsetX.Fields(iColX).Value
End If
Else
vMyCell_1 = "下标越界"
End If
End Function---- 方法二:使用记录集数组。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_2
(adoRecordsetX As ADODB.Recordset,
iColX As Integer, iRowX As Integer) As Variant
Dim V As Variant
'将 Recordset 对象的多个记录恢复到数组中
V = adoRecordsetX.GetRows(adoRecordsetX.RecordCount,
adBookFirst)
If iColX < = UBound(V, 1)
And iRowX < = UBound(V, 2) Then
If IsNull(V(iColX, iRowX)) Then
vMyCell_2 = "Null"
Else
vMyCell_2 = V(iColX, iRowX)
End If
Else
vMyCell_2 = "下标越界"
End If
End Function
---- 方法三:使用DataGrid.Text属性返回。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_3
(DataGridX As DataGrid, adoRecordsetX As
ADODB.Recordset, iColX As Integer,
iRowX As Integer) As Variant
If iColX < = DataGridX.Columns.Count
- 1 And iRowX < =
adoRecordsetX.RecordCount - 1 Then
DataGridX.Col = iColX
DataGridX.Row = iRowX
vMyCell_3 = DataGridX.Text
Else
vMyCell_3 = "下标越界"
End If
End Function
巧用VB6的DataGrid实现通用电子表格
http://www2.ccw.com.cn/tips/9908/080502_11.asp摘要:
方法一:直接使用记录集。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_1
(adoRecordsetX As ADODB.Recordset,
iColX As Integer, iRowX As Integer) As Variant
If iColX < = adoRecordsetX.Fields.Count
- 1 And iRowX < =
adoRecordsetX.RecordCount - 1 Then
adoRecordsetX.Move iRowX, adBookFirst
If IsNull(adoRecordsetX.Fields(iColX).Value) Then
vMyCell_1 = "Null"
Else
vMyCell_1 = adoRecordsetX.Fields(iColX).Value
End If
Else
vMyCell_1 = "下标越界"
End If
End Function---- 方法二:使用记录集数组。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_2
(adoRecordsetX As ADODB.Recordset,
iColX As Integer, iRowX As Integer) As Variant
Dim V As Variant
'将 Recordset 对象的多个记录恢复到数组中
V = adoRecordsetX.GetRows(adoRecordsetX.RecordCount,
adBookFirst)
If iColX < = UBound(V, 1)
And iRowX < = UBound(V, 2) Then
If IsNull(V(iColX, iRowX)) Then
vMyCell_2 = "Null"
Else
vMyCell_2 = V(iColX, iRowX)
End If
Else
vMyCell_2 = "下标越界"
End If
End Function
---- 方法三:使用DataGrid.Text属性返回。 ---- 创建如下函数返回某单元格内容: Private Function vMyCell_3
(DataGridX As DataGrid, adoRecordsetX As
ADODB.Recordset, iColX As Integer,
iRowX As Integer) As Variant
If iColX < = DataGridX.Columns.Count
- 1 And iRowX < =
adoRecordsetX.RecordCount - 1 Then
DataGridX.Col = iColX
DataGridX.Row = iRowX
vMyCell_3 = DataGridX.Text
Else
vMyCell_3 = "下标越界"
End If
End Function
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货