| |

VerySource

 Forgot password?
 Register
Search
View: 711|Reply: 1

Why does the get statement return empty string in VBA?

[Copy link]

4

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-3-10 23:00:02
| Show all posts |Read mode
Sub AAA ()
dim filecontent as sting

 Open "d:\aaa\test.doc" For Binary As # 1
    Get # 1,, filecontent
    Close # 1
    

End Sub
_____________________________________
The returned filecontent is empty, but there is meat in test.doc
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-6-10 12:00:02
| Show all posts
Files opened in binary mode cannot be directly read into the string, change it
Dim fileContent As String
Dim b() As Byte
Open "d:\aaa\test.doc" For Binary As #1
    ReDim b(LOF(1)-1)
    Get #1,, b
    Close #1
    fileContent = StrConv(b, vbUnicode)
    Debug.Print Len(fileContent)
But I don’t know what is the use of such reading?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list