PDA

View Full Version : File_Load driving me mad but it shouldn't



Django
23-11-2014, 19:00
Greetings,
I'm using the following script which creates 2 files (HTML and TXT) in my desktop folder which works fine. My problem is with the File_Load. It returns gibberish (for me, it always returns ˙ūC).

=====================================================
' Create file containing list of Windows Hotfixes
' using the Windows Management Instrumentation Command (WMIC)
' command. This can produce and HTML file (cmdh) or a TXT file
' (cmdt).

Uses "OS", "File"

String buffer
String wm = "wmic qfe list full "
String Desktop = OS_GetSpecialFolder(%CSIDL_DESKTOP)
String h1 = "/format:htable > "
String h2 = Desktop & "hotfix.html"

String t1 = "/format:texttablewsys > "
String t2 = Desktop & "hotfix.txt"

String cmdh = wm & h1 & $DQ & h2 & $DQ
String cmdt = wm & t1 & $DQ & t2 & $DQ
String lap = OS_GetSpecialFolder(%CSIDL_LOCAL_APPDATA)

RunCommand(cmdh)
RunCommand(cmdt)

buffer = FILE_Load(t2)
ClipBoard_SetText(buffer)
MsgBox(0,buffer)
MsgBox(0,t2)

Function RunCommand( sCommand As String )
String tempBat = lap + "TEMP\temp.bat"
FILE_Save(tempBat, sCommand)
OS_Shell(tempBat, %OS_WNDSTYLE_HIDE, %OS_SHELL_SYNC)
End Function
=====================================================
What the heck am I doing wrong? The File_Load seems so straight-forward. :confused:

Regards

Petr Schreiber
23-11-2014, 19:54
Hi Django,

believe it or not, file_load works correctly in this case. The problem is the data display. The generated output is in Unicode, MsgBox expects ASCII.

To handle this situation systematically, you can enhance your script with the following:


buffer = FILE_Load(t2)
If IsUnicode(buffer) Then
buffer = Unicode2Ascii(buffer)
End If


Unicode strings are part of my proposals for ThinBASIC 2.x series, we already talked about it with Eros.


Petr

ReneMiner
24-11-2014, 12:05
just some small hint - i think it's still undocumented (except small mentioning under "What's new")
regarding File_Load/File_Save:

If both are the only functions you need of file-module (Uses "File") and if you use at least tB-version 1.9.11 then you can omit the file-module and just use



String sData = Load_File(sFilename)
'or
If Save_File (sFilename, sData) Then
' successfully saved
EndIf


- which are to thinCore built in functions.

It will reduce the final size of your code...

Django
24-11-2014, 15:30
Thank you Petr. I don't think I would have ever thought about something so obscure.

Thanks Rene, I'm still on version 1.8.9.0 but I'll keep your suggestion in mind.

Best regards.