开发者

I want to dump the contents of a .csv file into a string in Visual Basic 6. What's wrong with my code?

Here is my code. The file abc.csv exists and is full of data.

    Dim strContent As String
    Dim int As Integer      

    Open "C:\abc.csv" For Input As #int 

        strContent = 开发者_如何学JAVAInput(LOF(int), int)

    Close #int

The error that I get is that the code proceeds as if the file never existed...but it does exist in the C:\ drive directory. I made extra sure of it. C:\abc.csv is there....What am I missing?


Try

int = FreeFile
Open "C:\abc.csv" For Input As #int 


I don't have a VB6 environment to test this in, but I think you want to try it like this:

Dim strContent As String
Dim int As Integer      
int = FreeFile
Open "C:\abc.csv" For Input As #int 
strContent = Input(LOF(int), #int) '<-- make sure to put the # on the 2nd param
Close #int

See here for more info (under Using the Open method in Classic VB):
http://www.vbknowledgebase.com/?Id=23&Desc=Read-Text-File-into-string-VB6

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜