Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert vbscript to vb.net code?

Status
Not open for further replies.

Glowworm27

Programmer
May 30, 2003
587
US
Hello all

I have some vbscript and need to get it into vb.net class.

I have to read IBM file with packed and zoned fields so I can import the file, I found only one solution to do this, but its in vbscript. There was a Time when I was able to deal with vbscript, but the time contraints on this project require me to finish this up ASAP, and I don't have the nessesary time to mess around with this.

I would be greatfull if someone could take a stab at this, and help me convert the vbscript into vb.net so I can work on more important part of this project.

here is the vbscript
Code:
Option Explicit

On Error Resume Next

' Require execution under command-line mode
If InStr(WScript.FullName, "cscript.exe") = 0 Then
  WScript.Echo "This script must be run using cscript.exe!"
  WScript.Quit(100)
End If

' Expect arguments
If WScript.Arguments.Count <> 4 Then
  WScript.Echo "Safety Block Enforced."
  WScript.Echo "Parameters: ! ControlFile SourceDataFile TargetDataFile"
  WScript.Quit(101)
End If

' Enforce safety block
If WScript.Arguments(0) <> "!" Then
  WScript.Echo "Safety Block Enforced."
  WScript.Echo "Parameters: ! ControlFile SourceDataFile TargetDataFile"
  WScript.Quit(102)
End If

Dim ASCII_To_EBCDIC_Table, gaCtlSpec, goFSO, nRecords

' Characterset Translation Table (WEI8ISO8859P1 to WEI8EBCDIC500)
ASCII_To_EBCDIC_Table = Array( _ 
  "00","01","02","03","37","2D","2E","2F","16","05","25","0B","0C","0D","0E","0F", _
  "10","11","12","13","3C","3D","32","26","18","19","3F","27","1C","1D","1E","1F", _
  "40","5A","7F","7B","5B","6C","50","7D","4D","5D","5C","4E","6B","60","4B","61", _
  "F0","F1","F2","F3","F4","F5","F6","F7","F8","F9","7A","5E","4C","7E","6E","6F", _
  "7C","C1","C2","C3","C4","C5","C6","C7","C8","C9","D1","D2","D3","D4","D5","D6", _
  "D7","D8","D9","E2","E3","E4","E5","E6","E7","E8","E9","AD","E0","BD","5F","6D", _
  "79","81","82","83","84","85","86","87","88","89","91","92","93","94","95","96", _
  "97","98","99","A2","A3","A4","A5","A6","A7","A8","A9","C0","4F","D0","A1","07", _
  "20","21","22","23","24","15","06","17","28","29","2A","2B","2C","09","0A","1B", _
  "30","31","1A","33","34","35","36","08","38","39","3A","3B","04","14","3E","E1", _
  "41","42","43","44","45","46","47","48","49","51","52","53","54","55","56","57", _
  "58","59","62","63","64","65","66","67","68","69","70","71","72","73","74","75", _
  "76","77","78","80","8A","8B","8C","8D","8E","8F","90","9A","9B","9C","9D","9E", _
  "9F","A0","AA","AB","AC","4A","AE","AF","B0","B1","B2","B3","B4","B5","B6","B7", _
  "B8","B9","BA","BB","BC","6A","BE","BF","CA","CB","CC","CD","CE","CF","DA","dB", _
  "DC","DD","DE","DF","EA","EB","EC","ED","EE","EF","FA","FB","FC","FD","FE","FF" _
)

Set goFSO = CreateObject("Scripting.FileSystemObject")
gaCtlSpec = LoadControlFile(goFSO, WScript.Arguments(1))
nRecords = TranslateFileData(goFSO, gaCtlSpec, WScript.Arguments(2), WScript.Arguments(3))
Set goFSO = Nothing

Function LoadControlFile(oFSO, sFilespec)
  WScript.Echo "LoadControlFile[in]"
  Dim n, oStm, sLineOfData, aLineOfData, aCtlSpec()
  Set oStm = oFSO.OpenTextFile(sFilespec)
  n = -1
  Do While Not oStm.AtEndOfStream
    n = n + 1
    sLineOfData = oStm.ReadLine
    aLineOfData = Split(sLineOfData, ",")
    ReDim Preserve aCtlSpec(n)
    aCtlSpec(n) = aLineOfData
  Loop
  oStm.Close
  Set oStm = Nothing
  LoadControlFile = aCtlSpec
  WScript.Echo "LoadControlFile[out] - " & n
End Function

Function TranslateFileData(oFSO, aCtlSpec, sSourceFilespec, sTargetFilespec)
  WScript.Echo "TranslateFileData[in]"
  Dim aFields(), oStm, oStm2, n, specField, sLineOfData, nLen, thisField, nScale, nFrom, nCount, nRecords
  Set oStm = oFSO.OpenTextFile(sSourceFilespec)
  Set oStm2 = oFSO.CreateTextFile(sTargetFilespec)
  n = -1
  For Each specField In aCtlSpec
    n = n + 1
    ReDim Preserve aFields(n)
    aFields(n) = specField(0)
  Next
  oStm2.WriteLine Join(aFields, Chr(9))
  nRecords = 0
  Do While Not oStm.AtEndOfStream
    sLineOfData = oStm.Read(aCtlSpec(UBound(aCtlSpec))(2)+2)
    n = -1
    For Each specField In aCtlSpec
      n = n + 1
      ReDim Preserve aFields(n)
      nFrom = specField(1)
      nCount = specField(2) - nFrom+1
      Select Case UBound(specField)
        Case 2
          aFields(n) = Mid(sLineOfData, nFrom, nCount)
        Case 4
          aFields(n) = AsciiUnzone(Mid(sLineOfData, nFrom, nCount), specField(4))
        Case 5
          aFields(n) = AsciiUnpack(Mid(sLineOfData, nFrom, nCount), specField(4))
      End Select
'wscript.echo "From : " & nFrom & "[" & nCount & "] is " & replace(aFields(n)," ",".")
    Next
    oStm2.WriteLine Join(aFields, Chr(9))
    nRecords = nRecords + 1
  Loop
  oStm2.Close
  oStm.Close
  TranslateFileData = nRecords
  WScript.Echo "TranslateFileData[out] - " & nRecords
End Function

Function AsciiUnzone(sZonedAscii, nPrecision)
  Dim nLen, nIndex, sEbcdicHex, sUnzonedAscii, fMult
  nLen = Len(sZonedAscii)
  For nIndex = 1 To nLen
    sEbcdicHex = ASCII_To_EBCDIC_Table( Asc( Mid(sZonedAscii, nIndex, 1) ) )
    sUnzonedAscii = sUnzonedAscii & Right(sEbcdicHex, 1)
  Next
  If Left(sEbcdicHex, 1) = "D" Then
    fMult = -1.0
  Else
    fMult = +1.0
  End If
  AsciiUnzone = CStr(fMult * CDbl(sUnzonedAscii) / (10^nPrecision))
End Function

Function AsciiUnpack(sPackedAscii, nPrecision)
  Dim nLen, nIndex, sPackedEbcdic, fMult
  nLen = Len(sPackedAscii)
  For nIndex = 1 To nLen
    sPackedEbcdic = sPackedEbcdic & ASCII_To_EBCDIC_Table( Asc( Mid(sPackedAscii, nIndex, 1) ) )
  Next
  If Right(sPackedEbcdic, 1) = "D" Then
    fMult = -1.0
  Else
    fMult = +1.0
  End If
  AsciiUnpack = CStr(fMult * CDbl(Left(sPackedEbcdic, Len(sPackedEbcdic) - 1)) / (10^nPrecision))
End Function




Here is a sample control file...

RCDCD,1,2
ACREC,3,3
CMPNR,4,6
DIVNR,7,9
LOCNR,10,12
WHSNR,13,15
ITNBR,16,25
IPACK,26,29,4,0
ISIZE,30,36
BRND1,37,46
ITDSC,47,86
WEGHT,87,93,7,2
CLASS,94,98
WCODE,99,99
TAXCD,100,100
BCSCD,101,101
PBHNR,102,106
BCPER,107,111,5,2
MKTCD,112,112
SLSCS,113,121,9,2
MKTCS,122,130,9,2
ACTCS,131,139,9,2
AVGCS,140,148,9,2
NATCS,149,157,9,2
BUYER,158,160
FDNFD,161,161
ALLQT,162,166,5,0
RCODE,167,167
ABCIT,168,168
SITEM,169,169
SRVCS,170,174,5,0
UNMSR,175,176
ZONE1,177,185,9,2
ZONE2,186,194,9,2
ZONE3,195,203,9,2
ZONE4,204,212,9,2
ZONE5,213,221,9,2
ZONE6,222,230,9,2
ZONE7,231,239,9,2
ZONE8,240,248,9,2
CSQTY,249,253,5,0
BCQTY,254,256,3,0
SPCPR,257,263,7,2
QTYOR,264,268,5,0
ALLAM,269,273,5,2
PDAYS,274,276,3,0
PONBR,277,283,7,0
POEDT,284,291
POEQT,292,296,5,0
CVDFL,297,297
FIL01,298,302
RSTIT,303,303
VNDNR,304,313
UPCNR,314,328
AGEDT,329,336
SUBNR,337,346
SDNBR,347,356
MSTIT,357,366
CHECK,367,367
SSPND,368,368
BRND2,369,373
ITDS1,374,413
ITDS2,414,453
ITDS3,454,493
ITDS4,494,533
ITDS5,534,573
ITDS6,574,613
ITDS7,614,653
UPCVN,654,668
UPCCS,669,683
VNDIT,684,693
ITDSX,694,733
XPDIT,734,743
XPDMF,744,748,5,0
CUBEC,749,753,5,3

Thanks LOADS!!!


George Oakes
Check out this awsome .Net Resource!
 
As far as I know, I don't think you can do this, but then again, I'm a real newbie at VB.NET so don't trust my word. :p ;-)

ComputerCop911
ASP and HTML Programmer
Learning VB.NET and ASP.NET
Can also help with hardware probs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top