How to display the text file while clicking the button

前端 未结 4 1579
日久生厌
日久生厌 2020-12-22 12:50

How to display the file(*.txt) while clicking the command button

How to display the content of the file while clicking the button

Data\'s are stored in the t

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 13:05

    Stefan's answer contains a flaw: the code to read a text file into a string isn't very robust. It's a very common mistake - the same flawed code is on some excellent VB6 web sites. His code is

    Open strFilename For Input As #iFile
    strTheData = Input$(LOF(iFile), #iFile)
    Close #iFile  
    

    Unfortunately this throws an error 62 "input past end of file" if the text file contains ASCII zero characters. Also it doesn't work in all countries (it throws an error for most strings in double byte character sets like Chinese or Japanese).

    Perhaps those problems are a bit obscure: but there's better code to do this job in the VB6 manual (here), it's also three lines, and it never fails.

    Open strFilename For Input As #iFile
    strTheData = StrConv(InputB(LOF(iFile), iFile), vbUnicode)
    Close #iFile  
    

    It looks more complicated: but actually the only difference is that the conversion from ANSI to Unicode is explicit rather than implicit. It runs just as fast, and it always works.

提交回复
热议问题