Convert script to VB.Net
I have a simple script (.vbs) that reads an Access Database and writes records to a text file. Trying to convert to VB, but having problems. Can anyone provide help? What I really need is an example of a VB.Net program that reads the records in an Access database and writes them to a text file. Got some of the code in VB, but cannot get it right.
Thanks
VBS Code:
On Error Resume Next
FileDirARC = WScript.Arguments.Item(0)
FileNameARC = WScript.Arguments.Item(1)
FileDirOut = WScript.Arguments.Item(2)
FileNameOut = WScript.Arguments.Item(3)
FileARC = FileDirArc & FileNameArc
FileOut = FileDirOut & FileNameOut
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Const ForAppending = 8
Const sizeH0 = 20 'Size of FULLSHIPID
Const sizeH1 = 32 'Size of TRACKNO
Const sizeH2 = 14 'Size of WEIGHT
Const sizeH3 = 3 'Size of INCO
Const sizeH4 = 14 'Size of COST
Const sizeH5 = 1 'Size of VOID
Const sizeH6 = 1 'Size of PRINTER
Const sizeH7 = 1 'Size of SATDEL
strOutOpen = "N"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=UPS_IN;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Scans", _
objConnection, adOpenStatic, adLockOptimistic
Do Until objRecordset.EOF
'***** format for out file
strLineUPS = ""
'* Check spaces needed to complete FULLSHIPID
lenH0 = Len(objRecordset("FULLSHIPID"))
diffH0 = sizeH0 - lenH0
spaceH0 = ""
Cnt = 0
Do Until Cnt = diffH0
spaceH0 = spaceH0 + "0"
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete TRACKNO
lenH1 = Len(objRecordset("TRACKNO"))
diffH1 = sizeH1 - lenH1
spaceH1 = ""
Cnt = 0
Do Until Cnt = diffH1
spaceH1 = spaceH1 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete WEIGHT
lenH2 = Len(objRecordset("WEIGHT"))
diffH2 = sizeH2 - lenH2
spaceH2 = ""
Cnt = 0
Do Until Cnt = diffH2
spaceH2 = spaceH2 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete INCO
lenH3 = Len(objRecordset("INCO"))
diffH3 = sizeH3 - lenH3
spaceH3 = ""
Cnt = 0
Do Until Cnt = diffH3
spaceH3 = spaceH3 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete COST
lenH4 = Len(objRecordset("COST"))
diffH4 = sizeH4 - lenH4
spaceH4 = ""
Cnt = 0
Do Until Cnt = diffH4
spaceH4 = spaceH4 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete VOID
lenH5 = Len(objRecordset("VOID"))
diffH5 = sizeH5 - lenH5
spaceH5 = ""
Cnt = 0
Do Until Cnt = diffH5
spaceH5 = spaceH5 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete PRINTER
lenH6 = Len(objRecordset("PRINTER"))
diffH6 = sizeH6 - lenH6
spaceH6 = ""
Cnt = 0
Do Until Cnt = diffH6
spaceH6 = spaceH6 + " "
Cnt = Cnt + 1
Loop
'* Check spaces needed to complete SATDEL
lenH7 = Len(objRecordset("SATDEL"))
diffH7 = sizeH7 - lenH7
spaceH7 = ""
Cnt = 0
Do Until Cnt = diffH7
spaceH7 = spaceH7 + " "
Cnt = Cnt + 1
Loop
strLineUPS = spaceH0 & objRecordset("FULLSHIPID") & objRecordset("TRACKNO") & spaceH1 & objRecordset("WEIGHT") & spaceH2 & objRecordset("INCO") & spaceH3 & objRecordset("COST") & spaceH4 & objRecordset("VOID") & spaceH5 & objRecordset("PRINTER") & spaceH6 & objRecordset("SATDEL") & spaceH7
' WScript.Echo strLineUPS
'**** Write to out file
strFoundNew = "Y"
Set objFileARC = objFSO.OpenTextFile(FileARC, 1)
Do Until objFileARC.AtEndOfStream Or strFoundNew = "N"
strLineARC = objFileARC.ReadLine
If Left(strLineUPS, 52) = Left(strLineARC, 52) Then
strFoundNew = "N"
End If
Loop
If strFoundNew = "Y" Then
If strOutOpen = "N" Then
Set objFileOut = objFSO.OpenTextFile(FileOut, ForAppending, True)
strOutOpen = "Y"
End If
objFileOut.WriteLine(strLineUPS)
End If
objFileARC.Close
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
Wscript.Quit

