Short, basic VB script works on 2003 Server but not on 2012 R2 server RRS feed

  • Question

  • Hello all,

    Hopefully I'm posting this in the right place. I have a legacy VB script that I need to keep, but I'm having trouble getting it to work on Server 2012 R2.

    The script reads a file called "Test.txt" that contains the following string:


    Part of the VB script is to read this "Test.txt" file and parse this line into 2 separate elements based upon the "|" delimeter:

    On Error Resume Next
    Dim FSI, inputFile, String, f, WshShell,WshNetwork, WshFSO, StringArray
    inputFile = "Test.txt" 
    CONST ForReading = 1, ForWriting = 2, ForAppending = 8 
    Set FSI = CreateObject("Scripting.FileSystemObject") 
    Set f = FSI.OpenTextFile(inputFile, ForReading, True) 
    Set WshShell=WScript.CreateObject("WScript.Shell")
    '********* Read the file ********
    String = f.ReadLine
    msgbox("String: "&string)
    '********* Split the line *******
    StringArray = Split(String,"|", -1, 1)
    msgbox("stringarray(0): "&stringarray(0))
    msgbox("stringarray(1): "&stringarray(1))

    The variables in this script when ran on Server 2003 are:

    string = String1|String2

    stringarray(0) = String1

    stringarray(1) = String2

    So this script parses the String1|String2 line perfectly on Server 2003. However, running this same VB script on Server 2012 R2 results in very strange output:

    The variables in this script when ran on Server 2012 R2 are:

    string = ӱƥt

    stringarray(0) = ӱƥt

    stringarray(1) =

    Is there anything on Server 2012 R2 that I need to install to get this to work in VB, or what is the issue with Server 2012 R2 and visual basic? I'd LOVE to redo this in PowerShell but I need to keep it Visual Basic for legacy reasons for a few more months.

    • Edited by KentYeabower Wednesday, November 12, 2014 7:54 PM
    Wednesday, November 12, 2014 7:44 PM


  • The encoding of the file can cause this.

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by KentYeabower Wednesday, November 12, 2014 8:14 PM
    Wednesday, November 12, 2014 7:52 PM

All replies