neophyte 发表于 2022-7-6 14:13:15

读取文件-VBA

你好
 
你能更正我的密码吗?!?
1-我需要打开一个文件。
2-检查第一个数字是否与我的变量相同。
3-是的,请。。。。。
4不,检查下一行
 
我在这个论坛上搜索,发现了一些关于“freefile”的帖子
http://www.cadtutor.net/forum/showthread.php?t=27744
但是我没有找到解决问题的方法。
变量strtext仍然为空,子变量不停止,它是“循环”:嗯:
 
(我暂时删除“如果”部分)
 
 

Sub FindScale(strVpScaleStd As String, strVpScaleCust As String)
   Dim strNomFichier As String
   Dim NomCalque As String
   Dim strTexte As String
   Dim iFichier As Integer
   Dim Position As Integer
   Dim strEchelle As String


   On Error Resume Next
   strNomFichier = "c:\vba\test.txt"

   iFichier = FreeFile
   Open strNomFichier For Input As #iFichier
   If Err Then
       MsgBox "Fichier " & strNomFichier & " introuvable."
       Exit Sub
   End If

   iFichier = FreeFile
   Do While Not EOF(iFichier)
       Line Input #iFichier, strTexte
         strTexte = Left(strTexte, 3)
         'If Left(strTexte, 3) = strVpScaleStd Then
         '    Position = InStr(strTexte, "*")
         '    strEchelle = Mid$(strTexte, Position + 1)
         'Else
         '    strTexte = ""
         'End If
   Loop
   Close #iFichier

   If strEchelle = "" Then
   MsgBox "actual scale = " & strVpScaleCust
   End If

End Sub
 
 
谢谢

ollie 发表于 2022-7-6 15:17:29

参考ms脚本运行时
 
dim fso作为新的文件系统对象
dim fil作为文本流
 
设置fil=fso。opentextstream
 
当fil。eof==假
 
 
温德
 
编辑:
 
您正在寻找的实际方法是fil。OpenTextFile()
 
这只是psuedo代码,但它应该足以让您继续
页: [1]
查看完整版本: 读取文件-VBA