Vb6 来自资源文件的文本文件

Vb6 来自资源文件的文本文件,vb6,text-files,embedded-resource,Vb6,Text Files,Embedded Resource,我有一个文本文件,我想包含在我的项目的资源文件中 现在我已经通过“添加自定义资源”包含了文本文件 当我运行项目时,我从资源文件中读取文件并将其保存到临时文件中 LoadDataIntoFile "TXT", App.Path & "\temp.txt" 这将使用以下函数 Public Sub LoadDataIntoFile(DataName As String, FileName As String) Dim myArray() As Byte Dim myFile As L

我有一个文本文件,我想包含在我的项目的资源文件中

现在我已经通过“添加自定义资源”包含了文本文件

当我运行项目时,我从资源文件中读取文件并将其保存到临时文件中

LoadDataIntoFile "TXT", App.Path & "\temp.txt"
这将使用以下函数

Public Sub LoadDataIntoFile(DataName As String, FileName As String)
  Dim myArray() As Byte
  Dim myFile As Long
  If Dir(FileName) = "" Then
    myArray = LoadResData(DataName, "CUSTOM")
    myFile = FreeFile
    Open FileName For Binary Access Write As #myFile
    Put #myFile, , myArray
    Close #myFile
  End If
End Sub
接下来,当我需要临时文件中读取的文本文件数据时

'read complete text file
intFile = FreeFile
Open strFile For Input As #intFile
  strData = Input(LOF(intFile), #intFile)
Close #intFile
然后我就可以毫无问题地使用文本文件中的数据了

不过,首先读取数据,然后保存到文件,然后从文件中读取数据似乎有点尴尬

有没有办法在资源文件中插入文本文件,并在需要时将其直接读入字符串变量?

我找到了一个解决方案

从资源文件读取文本文件将返回一个字节数组

要将此字节数组转换为字符串,我使用:

strData = StrConv(myArray, vbUnicode)
我不确定这是否是最好的方法,但它确实有效:)