本文介绍了如何从 Visual Basic for PowerPoint 2010 中的文本文件填充数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想定义一个数组,如:
I'd like to define an array like:
sample_array = Array( _
"foo", _
"bar", _
...
"dog", _
"cat" _
)
...在用 VB 编写的用于应用程序的宏(在本例中为 PowerPoint 2010)中,但我需要从一个文本文件中定义数组,该文件的格式如下:
...in a macro written in VB for Applications (PowerPoint 2010 in this case), but I need to define the array from a text file that would just be formatted like:
foo
bar
...
dog
cat
定义文本文件路径并将值(假设它们总是常规的 ascii 字符串)直接读入数组的最简单方法是什么?
What is the simplest way to define a text file path and read the values (assume they are always regular ascii strings) directly into an array?
谢谢!
推荐答案
Dim arr() as String
dim i as Integer
i=0
Open "c:\test.txt" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, arr(i) ' read next line from file and add text to the array
i=i+1
redim preserve arr(i) ' Redim the array for the new element
Loop
Close #1 ' Close file.
这篇关于如何从 Visual Basic for PowerPoint 2010 中的文本文件填充数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!