
1个回答
展开全部
Private Sub Cmd1_Click()
Dim FileNumber, Num As Long
Dim Str As String,Str1 As String
FileNumber = FreeFile
Open "D:\123.txt" For Input As #FileNumber
While Not EOF(FileNumber)
Line Input #FileNumber, Str
if trim(str)<>"" then str1=str1 & str '结束去掉空行的数据在 str1里面,重新写如文件就可以了
Num = Num + 1
Wend
Close #FileNumber
MsgBox "共" & Num & "行"
End Sub
下面这个函数遍历文件夹的
Function SearchFiles(Path As String, FileType As String)
Dim Files() As String '文件路径
Dim a, b, c As Long
Dim sPath As String
sPath = Dir(Path & FileType) '查找第一个文件
Do While Len(sPath) '循环到没有文件为止
a = a + 1
ReDim Preserve Files(1 To a)
Files(a) = sPath '将文件目录和文件名组合,并存放到数组中
List1.AddItem Files(a) '加入list控件中
sPath = Dir() '查找下一个文件
DoEvents '让出控制权
Loop
End Function
Dim FileNumber, Num As Long
Dim Str As String,Str1 As String
FileNumber = FreeFile
Open "D:\123.txt" For Input As #FileNumber
While Not EOF(FileNumber)
Line Input #FileNumber, Str
if trim(str)<>"" then str1=str1 & str '结束去掉空行的数据在 str1里面,重新写如文件就可以了
Num = Num + 1
Wend
Close #FileNumber
MsgBox "共" & Num & "行"
End Sub
下面这个函数遍历文件夹的
Function SearchFiles(Path As String, FileType As String)
Dim Files() As String '文件路径
Dim a, b, c As Long
Dim sPath As String
sPath = Dir(Path & FileType) '查找第一个文件
Do While Len(sPath) '循环到没有文件为止
a = a + 1
ReDim Preserve Files(1 To a)
Files(a) = sPath '将文件目录和文件名组合,并存放到数组中
List1.AddItem Files(a) '加入list控件中
sPath = Dir() '查找下一个文件
DoEvents '让出控制权
Loop
End Function
更多追问追答
追问
谢谢啦,在问一下,如何判断是否为数字,还有你是怎么学vb的啊,现在的书没看到那么深的啊
追答
IsNumeric 函数
返回 Boolean 值,指出表达式的运算结果是否为数。
语法
IsNumeric(expression)
必要的 expression 参数是一个 Variant,包含数值表达式或字符串表达式。
说明
如果整个expression 的运算结果为数字,则 IsNumeric 返回 True;否则返回 False。
怎么学VB啊?额 ,我接触VB 还不到半年、用多就动了,经常没事就上来知道看看网友有什么问题,然后尝试下去解决,遇到不懂就去搜索,遇到多了就懂了。多看看帮助。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询