VB6.0将日期与Listview子项中的数据进行比较
我正在建立一个系统来检查一个项目是否接近到期日 我仍然使用find方法出错。错误表示,属性值无效VB6.0将日期与Listview子项中的数据进行比较,listview,date,vb6,adodb,Listview,Date,Vb6,Adodb,我正在建立一个系统来检查一个项目是否接近到期日 我仍然使用find方法出错。错误表示,属性值无效 Private Sub Command1_Click() Dim strCurrDate As String strCurrDate = Format(Date, "MM/dd/yyyy") Dim list As ListItem Dim x As Integer ConnectDB rs.Open "Select * from Table1 Order by Expiry
Private Sub Command1_Click()
Dim strCurrDate As String
strCurrDate = Format(Date, "MM/dd/yyyy")
Dim list As ListItem
Dim x As Integer
ConnectDB
rs.Open "Select * from Table1 Order by Expiry ASC", db, 3, 3
Do Until rs.EOF
Set list = ListView1.ListItems.Add(, , rs(0))
For x = 1 To 3
list.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop
Set rs = Nothing
db.Close: Set db = Nothing
ListView1.ListItems.Clear
Set list = Me.ListView1.FindItem(strCurrDate, lvwSubItem, 1, lvwPartial) ' Error here
If Not list Is Nothing Then
'Select the row
list.Selected = True
'Auto scrolling the Scrollbar if we have so much rows
'and not show on ListView
myList.EnsureVisible
MsgBox "Data Found:"
Else
MsgBox "Data not Found"
End If
End Sub
使用FindItem方法: Dim xItem As ListItem Set xItem = ListView1.FindItem("01/01/1900", lvwSubItem, 1, lvwPartial) If Not xItem Is Nothing Then 'Condition when item is not found End If 将xItem设置为列表项 Set xItem=ListView1.FindItem(“01/01/1900”,lvwSubItem,1,lvwPartial) 如果不是,那么xItem什么都不是 '未找到项时的条件 如果结束 这是样本:
Private Sub Form_Load()
With ListView1
.HideSelection = False
End With
With ListView1.ColumnHeaders
.Add , , "ID", 500
.Add , , "Product Name", 1500
.Add , , "Current Stock", 1200
.Add , , "Expiration Date", 1500
End With
'just assume we have 3 records
Dim myList As ListItem
Set myList = Me.ListView1.ListItems.Add(, , "001")
With myList
.SubItems(1) = "Product One"
.SubItems(2) = "10"
.SubItems(3) = "02/01/2014"
End With
Set myList = Me.ListView1.ListItems.Add(, , "002")
With myList
.SubItems(1) = "Product Two"
.SubItems(2) = "11"
.SubItems(3) = "03/27/2014"
End With
Set myList = Me.ListView1.ListItems.Add(, , "003")
With myList
.SubItems(1) = "Product Three"
.SubItems(2) = "12"
.SubItems(3) = "01/28/2014" 'Current date
End With
End Sub
Private Sub Command1_Click()
Dim strCurrDate As String
Dim myList As ListItem
'Formating date to "MM/dd/yyyy", eg. 01/28/2014
strCurrDate = Format(Date, "MM/dd/yyyy")
'Finding item
Set myList = Me.ListView1.FindItem(strCurrDate, lvwSubItem, 1, lvwPartial)
'If we got the item
If Not myList Is Nothing Then
'Select the row
myList.Selected = True
'Auto scrolling the Scrollbar if we have so much rows
'and not show on ListView
myList.EnsureVisible
MsgBox "Data Found: " & vbCrLf & _
"ID: " & myList.Text & vbCrLf & _
"Current Stock: " & myList.SubItems(2) & vbCrLf & _
"Expiration Date: " & myList.SubItems(3)
Else
MsgBox "Data not Found"
End If
End Sub
为什么要清除listview ListView1.ListItems.Clear
请把它取下来我不明白。先生,你能给我解释一下吗?什么是“01/01/1900”和其他?如何将我的整个数据库设置为ListItem?我是否要使用循环将每个数据添加到ListItem?我看到您正在调用一个过程“LoadData”。设置myList=Me.ListView1.FindItem(strCurrDate,lvwSubItem,1,lvwPartial)这是我的问题。我不明白逻辑/我添加了加载数据过程我添加它是因为它将显示的记录翻倍。甚至我也把它拿走了。它仍然说没有找到数据。有什么问题吗??