type student
strname as string *6
number as strint *7
end type我建立了一个随机文件,并且输入了如上自定义类型的数据10条。后来我想通过程序实现查找的功能,可是当我在文本框中输入strname然后进行查找时却无论如何也找不到。我在程序中设置了一些断点后发现,从文件中读出的数据后面带有一些空格,而且这些空格用trim()函数也无法删掉。希望高手能帮助解决,真的非常感谢。
程序如下:
Dim FindName As String '要查找人的姓名
Dim stu As student
FindName = Txt1.Text
Open App.Path & "\student.dat" For Random As #1 Len = Len(stu)
Do While Not EOF(1)
Get #1, , stu
If FindName=trim(stu.strname) Then
msgbox"找到此人了"
Exit Do
End If
Loop Close #1
strname as string *6
number as strint *7
end type我建立了一个随机文件,并且输入了如上自定义类型的数据10条。后来我想通过程序实现查找的功能,可是当我在文本框中输入strname然后进行查找时却无论如何也找不到。我在程序中设置了一些断点后发现,从文件中读出的数据后面带有一些空格,而且这些空格用trim()函数也无法删掉。希望高手能帮助解决,真的非常感谢。
程序如下:
Dim FindName As String '要查找人的姓名
Dim stu As student
FindName = Txt1.Text
Open App.Path & "\student.dat" For Random As #1 Len = Len(stu)
Do While Not EOF(1)
Get #1, , stu
If FindName=trim(stu.strname) Then
msgbox"找到此人了"
Exit Do
End If
Loop Close #1
Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Dim FindName As String '要查找人的姓名
Dim stu As student
FindName = Txt1.Text
Open App.Path & "\student.dat" For Random As #1 Len = lstrlen(stu)
Do While Not EOF(1)
Get #1, , stu
If FindName=trim(stu.strname) Then
msgbox"找到此人了"
Exit Do
End If
Loop Close #1
strname as string *6
number as strint *7
end type
改为:
type student
strname as string
number as strint
end type
replace(strname,mid(strname,len(strname)),"")
或者用API函数读写查INI文件更好些