乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 98|回复: 1

[编程交流] 读取文件-VBA

[复制链接]

4

主题

10

帖子

6

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 14:13:15 | 显示全部楼层 |阅读模式
你好
 
你能更正我的密码吗?!?
1-我需要打开一个文件。
2-检查第一个数字是否与我的变量相同。
3-是的,请。。。。。
4不,检查下一行
 
我在这个论坛上搜索,发现了一些关于“freefile”的帖子
http://www.cadtutor.net/forum/showthread.php?t=27744
但是我没有找到解决问题的方法。
变量strtext仍然为空,子变量不停止,它是“循环”:嗯:
 
(我暂时删除“如果”部分)
 
 
  1. Sub FindScale(strVpScaleStd As String, strVpScaleCust As String)
  2.    Dim strNomFichier As String
  3.    Dim NomCalque As String
  4.    Dim strTexte As String
  5.    Dim iFichier As Integer
  6.    Dim Position As Integer
  7.    Dim strEchelle As String
  8.    On Error Resume Next
  9.    strNomFichier = "c:\vba\test.txt"
  10.    iFichier = FreeFile
  11.    Open strNomFichier For Input As #iFichier
  12.    If Err Then
  13.        MsgBox "Fichier " & strNomFichier & " introuvable."
  14.        Exit Sub
  15.    End If
  16.    iFichier = FreeFile
  17.    Do While Not EOF(iFichier)
  18.        Line Input #iFichier, strTexte
  19.            strTexte = Left(strTexte, 3)
  20.            'If Left(strTexte, 3) = strVpScaleStd Then
  21.            '    Position = InStr(strTexte, "*")
  22.            '    strEchelle = Mid$(strTexte, Position + 1)
  23.            'Else
  24.            '    strTexte = ""
  25.            'End If
  26.    Loop
  27.    Close #iFichier
  28.    If strEchelle = "" Then
  29.    MsgBox "actual scale = " & strVpScaleCust
  30.    End If
  31. End Sub

 
 
谢谢
回复

使用道具 举报

37

主题

125

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
190
发表于 2022-7-6 15:17:29 | 显示全部楼层
参考ms脚本运行时
 
dim fso作为新的文件系统对象
dim fil作为文本流
 
设置fil=fso。opentextstream
 
当fil。eof==假
 
 
温德
 
编辑:
 
您正在寻找的实际方法是fil。OpenTextFile()
 
这只是psuedo代码,但它应该足以让您继续
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 03:05 , Processed in 0.465025 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表