永发信息网

VB代码解释

答案:1  悬赏:40  手机版
解决时间 2021-07-27 00:39
  • 提问者网友:太高姿态
  • 2021-07-26 00:36

解释方法:

例:

Private Sub Command1_Click() ' 按钮1的单击事件

解释以下代码:

Private Sub Command1_Click()
Call OpenDouble
Dim i As Double
Dim sSQL As String
Dim sTemp As String
sSQL = "select * from Tasktable " & vbCrLf
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Checked = True Then
sTemp = sTemp & "'" & ListView1.ListItems(i).Text & "',"
End If
Next i
If sTemp <> "" Then
sSQL = sSQL & "where dtext14 in (" & Left(sTemp, Len(sTemp) - 1) & ")"
End If
rs.Open sSQL, cn, 1, 1
Set DataReport1.DataSource = rs
DataReport1.Show
Set rs = Nothing
Set cn = Nothing
End Sub

最佳答案
  • 五星知识达人网友:轻熟杀无赦
  • 2021-07-26 02:05

Private Sub Command1_Click() '单击按钮事件
Call OpenDouble ‘调用 OpenDouble过程
Dim i As Double ’声明 变量为双精度
Dim sSQL As String ‘声明变量为字符
Dim sTemp As String ‘声明变量为字符
sSQL = "select * from Tasktable " & vbCrLf ’为变量赋值
For i = 1 To ListView1.ListItems.Count ‘循环ListView1的总行数
If ListView1.ListItems(i).Checked = True Then ‘如果ListView1的选取状态为真
sTemp = sTemp & "'" & ListView1.ListItems(i).Text & "'," ’为sTemp变量赋值
End If
Next i ’下一次循环
If sTemp <> "" Then ‘如果sTemp变量不为空
sSQL = sSQL & "where dtext14 in (" & Left(sTemp, Len(sTemp) - 1) & ")" ’sSQL重新赋值
End If
rs.Open sSQL, cn, 1, 1 ‘打开数据库
Set DataReport1.DataSource = rs ’设置数据源
DataReport1.Show ‘显示数据
Set rs = Nothing ‘释放RS
Set cn = Nothing '释放CN
End Sub '过程结束

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯