有没有办法简单地使用visual basic将数据写入文件

时间:2013-08-01 02:06:08

标签: vba xaml read-write

我正在使用visual basic和xaml设计一个应用程序,并且想知道是否有一种“简单”的方法来读取/写入文件数据。基本上我的应用程序需要在启动时记住一些变量(最好存储在数组中)。

1 个答案:

答案 0 :(得分:0)

来自microsoft:

Sub OpenExample()
   Dim sFirst, sLast, sAddress, sCity, sState, sZip As String
   '' CREATE DATA FILE
   '' Open file for input.
   Open "Datafile.txt" For Output As #1
   '' Write data to file.
   Write #1, "John", "Doe", "An Address", "A City", "A State", "A Zip"
   '' Close File.
   Close #1
   '' RETRIEVE DATA FROM FILE
   '' Open file for input.
   Open "Datafile.txt" For Input As #1
   '' Loop until the end of file is reached.
   Do While Not EOF(1)
      '' Read data into variables.
      Input #1, sFirst,sLast,sAddress,sCity,sState,sZip
      '' Print data to Debug window.
      Debug.Print sFirst,sLast,sAddress,sCity,sState,sZip
   Loop
   '' Close file.
   Close #1
End Sub

来自http://support.microsoft.com/kb/209231

发现使用谷歌搜索术语“microsoft vba open for output”。