我与了以下一个过程,但为什么在emp.txt文件中找不到与条件相符的记录并显示,最终显示出来的还是所有的记录呢?大家帮忙看看!谢谢!Private Sub inigridstyle() '初始化msflexgrid表
Dim intindex As Long
msflxdata.MergeCells = flexMergeFree
msflxdata.Row = 0
For intindex = 1 To msflxdata.Cols - 1
msflxdata.Col = intindex
msflxdata.Text = "员工信息列表"
msflxdata.ColWidth(intindex) = 1350
msflxdata.CellBackColor = &HC0FFFF
Next intindex
msflxdata.MergeRow(0) = Truemsflxdata.Row = 1
msflxdata.Col = 0
msflxdata.Text = "序号"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 1
msflxdata.Text = "员工编号"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 2
msflxdata.Text = "员工姓名"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 3
msflxdata.Text = "员工年龄"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 4
msflxdata.Text = "加入日期"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 5
msflxdata.Text = "员工地址"
msflxdata.CellBackColor = RGB(255, 255, 255)msflxdata.Row = 2
For intindex = 1 To msflxdata.Cols - 1
msflxdata.Col = intindex
msflxdata.Text = " "
Next intindex
msflxdata.MergeRow(2) = True
End SubPrivate Sub LoadDataToGrid() '按条件查找后显示的结果
Dim intindex As Long
Dim strtemp As String
Dim lngfh As Long
Dim temp As Boolean
temp = True
lngfh = FreeFile
intindex = 1
Open "f:\emp.txt" For Input As #lngfhDo While Not EOF(lngfh)
Line Input #lngfh, strtemp
If strtemp = CStr(Trim(frmsearch.Text1.Text)) Then
msflxdata.AddItem Empty
msflxdata.Row = msflxdata.Rows - 1
msflxdata.Col = 0
msflxdata.Text = intindex Line Input #lngfh, strtemp
msflxdata.Col = 1
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 2
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 3
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 4
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 5
msflxdata.Text = Trim(strtemp) intindex = intindex + 1
temp = True
Else
temp = False
End If
Loop
If temp = False Then
MsgBox "找不到相同的记录"
End If
Close #lngfh
End Subemp.txt文件的内容如下:2001
vicki
28
2002年
ShangHai2002
miles
25
2003年
ShanCi1997
steven
32
2004年
Guangdong1998
Celine
25
2001年
BeiJing1999
Rock
28
2002年
ShangHai2005
Lily
27
2002年
XingJiang2003
Lucy
23
2004年
ShanDong2004
Jack
32
2000年
ShiChuan
Dim intindex As Long
msflxdata.MergeCells = flexMergeFree
msflxdata.Row = 0
For intindex = 1 To msflxdata.Cols - 1
msflxdata.Col = intindex
msflxdata.Text = "员工信息列表"
msflxdata.ColWidth(intindex) = 1350
msflxdata.CellBackColor = &HC0FFFF
Next intindex
msflxdata.MergeRow(0) = Truemsflxdata.Row = 1
msflxdata.Col = 0
msflxdata.Text = "序号"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 1
msflxdata.Text = "员工编号"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 2
msflxdata.Text = "员工姓名"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 3
msflxdata.Text = "员工年龄"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 4
msflxdata.Text = "加入日期"
msflxdata.CellBackColor = RGB(255, 255, 255)
msflxdata.Col = 5
msflxdata.Text = "员工地址"
msflxdata.CellBackColor = RGB(255, 255, 255)msflxdata.Row = 2
For intindex = 1 To msflxdata.Cols - 1
msflxdata.Col = intindex
msflxdata.Text = " "
Next intindex
msflxdata.MergeRow(2) = True
End SubPrivate Sub LoadDataToGrid() '按条件查找后显示的结果
Dim intindex As Long
Dim strtemp As String
Dim lngfh As Long
Dim temp As Boolean
temp = True
lngfh = FreeFile
intindex = 1
Open "f:\emp.txt" For Input As #lngfhDo While Not EOF(lngfh)
Line Input #lngfh, strtemp
If strtemp = CStr(Trim(frmsearch.Text1.Text)) Then
msflxdata.AddItem Empty
msflxdata.Row = msflxdata.Rows - 1
msflxdata.Col = 0
msflxdata.Text = intindex Line Input #lngfh, strtemp
msflxdata.Col = 1
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 2
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 3
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 4
msflxdata.Text = Trim(strtemp) Line Input #lngfh, strtemp
msflxdata.Col = 5
msflxdata.Text = Trim(strtemp) intindex = intindex + 1
temp = True
Else
temp = False
End If
Loop
If temp = False Then
MsgBox "找不到相同的记录"
End If
Close #lngfh
End Subemp.txt文件的内容如下:2001
vicki
28
2002年
ShangHai2002
miles
25
2003年
ShanCi1997
steven
32
2004年
Guangdong1998
Celine
25
2001年
BeiJing1999
Rock
28
2002年
ShangHai2005
Lily
27
2002年
XingJiang2003
Lucy
23
2004年
ShanDong2004
Jack
32
2000年
ShiChuan
Else
temp = False
应该不要吧,temp的初值应为False,只要找到一条记录则赋值为True
If strtemp = CStr(Trim(frmsearch.Text1.Text)) Then 'frmsearch是另一个窗体中的text控件
而且控件界面比较好看。交流MSN:[email protected]
建议监视一下CStr(Trim(frmsearch.Text1.Text)) 和strtemp的值
看看是否正确