VB6读取文本,并将每行固定的字段赋给变量

    dim nFile as Integer, strTmp as String
    dim arTmp() as String
    nFile = FreeFile
    Open 文本文件全路径名 For Input As #nFile
    Do While Not EOF(nFile)
       Line Input #nFile, strTmp
       arTmp=Split(strTmp,分隔符)  '不知道你分隔符是空格还是TAB?
       分析该数组(arTmp(0)对应第一个字段,依次类推)
    Loop
    Close #nFile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VB ,可以通过以下方式声明和使用变量: 1. 变量声明 在 VB ,可以使用 `Dim` 关键字声明变量,例如: ```vb Dim myString As String Dim myInteger As Integer Dim myDouble As Double ``` 2. 变量赋值 可以使用 `=` 运算符给变量赋值,例如: ```vb myString = "Hello World!" myInteger = 42 myDouble = 3.1415 ``` 3. 文本读写变量使用 在文本读写,可以使用字符串插值的方式将变量的值插入到字符串,例如: ```vb Dim myString As String = "Hello World!" Dim myInteger As Integer = 42 ' 将变量插入到字符串 Dim output As String = $"My string is {myString}, my integer is {myInteger}." ' 输出字符串 Console.WriteLine(output) ``` 在读取文本文件时,可以使用变量来指定文件路径,例如: ```vb Dim filePath As String = "C:\example.txt" ' 打开文件,如果不存在则会抛出异常 Dim file As System.IO.StreamReader file = My.Computer.FileSystem.OpenTextFileReader(filePath) ' 读取文件内容 Dim content As String = file.ReadToEnd() ' 输出文件内容 Console.WriteLine(content) ``` 在写入文本文件时,可以将变量的值写入到文件,例如: ```vb Dim filePath As String = "C:\example.txt" Dim myString As String = "Hello World!" ' 打开文件,如果不存在则会自动创建 Dim file As System.IO.StreamWriter file = My.Computer.FileSystem.OpenTextFileWriter(filePath, True) ' 写入变量的值并关闭文件 file.WriteLine(myString) file.Close() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值