Search code examples
vbscripthebrewinputbox

vbscript output in Hebrew


I have this VBS file:

Dim retval 
retval = InputBox("חיפוש - הכנס את מילת החיפוש","Setting Membership Club") 

If IsEmpty(retval) Then 
    'cancelled 
    WScript.Echo ("EXITSP1") 
Else 
    'something has entered even zero-length 
    WScript.Echo retVal 
End If 

and here is how I call it:

cscript //nologo D:\inputbox.vbs > D:\outputbox.txt

But the outputbox.txt file will take me to Gibrish

I want it to come out in Hebrew

input box screenshot showing Hebrew

result file screnshot showing garbage


Solution

  • Don't use shell redirection to write the output file. You can make it work, but it depends on too many factors that your program can't control to work reliably, and therefore it will cause all kinds of headaches.

    Use the FileSystemObject and tell it to write a Unicode file.

    Dim FSO, retval, outFile
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    '                 CreateTextFile(filename, [overwrite, [unicode]])
    Set outFile = FSO.CreateTextFile("outputbox.txt", True, True)
    
    retval = InputBox("חיפוש - הכנס את מילת החיפוש", "Setting Membership Club") 
    If IsEmpty(retval) Then
        outFile.Write "EXITSP1"
    Else
        outFile.Write retval
    End If
    
    outfile.Close
    

    Documentation for the FileSystemObject (and the CreateFile method): https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method