D
DorkyGrin
Hi,
Couple of questions:
1. I need to rename a PDF based on some information inside a text file.
Someone gave me some vbs code (see below) that I'd like to convert into
VB.net. I want GUI and the vb.net app to watch a folder for a file to
show up - I think I have good 'filewatcher' code for that. However, I
tried to use the vbs code logic to make a new vb.net executable with no
success.
What is the best way to convert the code to run in vb.net? Is there a
better way to do this in vb.net?
2. For someone that wants to do occasional file manipulation, is vb.net
the right programming language to use? Would anyone recommend C, Perl,
VB6 or something I'm not even thinking of? I'm willing to learn, take
classes, self study etc.
Thanks for any help or ideas!
************
Sub ReadFiles
' Variables needed to initiate process
Dim fso, f1, ts, s
Dim sIndex, sIndex2, sIndex3, sTemp
Dim sIndexArray(1000)
Dim sIndexArray2(1000)
Dim I, N
Const ForReading = 1
I = 0
Set fso = CreateObject("Scripting.FileSystemObject")
' Read the contents of the file.
Set ts = fso.OpenTextFile("C:\Output\NewNames.txt", ForReading,
False)
' Loop thru Index text records.
Do While ts.AtEndOfStream <> True
' Initialize sIndex variables
sIndex = ""
sIndex2 = ""
sIndex3 = ""
sTemp = ""
' Read Records in Index text file.
s = ts.ReadLine
If Mid(s,5,1) <> "C" Then
sIndex = Mid(s,2,8) ' New Index.
sIndex2 = Mid(s,27,8) ' Old PDF Name.
sIndex3 = Mid(s,27,12) ' Old PDF Name with pdf
extension.
sTemp = Replace(s,sIndex2, sIndex) 'Replaces Old PDF
Name with Index information.
I = I + 1 ' Increment
counter.
sIndexArray(I) = Mid(sTemp,27,12) ' Add new PDF
Name and pdf file to array for moving and renaming.
sIndexArray2(I) = sIndex3 ' Add old PDF Name to
array for moving and renaming
Else
N = N + 1
End If
Loop
' Garbage collection
ts.Close
Do While I => 1
' Move and rename old PDF file to new folder. Rename old PDF
file to new PDF file.
fso.MoveFile "C:\Output\" & sIndexArray2(I) & "",
"C:\completed\" & sIndexArray(I) & " "
I = I - 1
Loop
' Delete output file.
fso.DeleteFile("C:\Output\NewNames.txt")
End Sub
ReadFiles
Couple of questions:
1. I need to rename a PDF based on some information inside a text file.
Someone gave me some vbs code (see below) that I'd like to convert into
VB.net. I want GUI and the vb.net app to watch a folder for a file to
show up - I think I have good 'filewatcher' code for that. However, I
tried to use the vbs code logic to make a new vb.net executable with no
success.
What is the best way to convert the code to run in vb.net? Is there a
better way to do this in vb.net?
2. For someone that wants to do occasional file manipulation, is vb.net
the right programming language to use? Would anyone recommend C, Perl,
VB6 or something I'm not even thinking of? I'm willing to learn, take
classes, self study etc.
Thanks for any help or ideas!
************
Sub ReadFiles
' Variables needed to initiate process
Dim fso, f1, ts, s
Dim sIndex, sIndex2, sIndex3, sTemp
Dim sIndexArray(1000)
Dim sIndexArray2(1000)
Dim I, N
Const ForReading = 1
I = 0
Set fso = CreateObject("Scripting.FileSystemObject")
' Read the contents of the file.
Set ts = fso.OpenTextFile("C:\Output\NewNames.txt", ForReading,
False)
' Loop thru Index text records.
Do While ts.AtEndOfStream <> True
' Initialize sIndex variables
sIndex = ""
sIndex2 = ""
sIndex3 = ""
sTemp = ""
' Read Records in Index text file.
s = ts.ReadLine
If Mid(s,5,1) <> "C" Then
sIndex = Mid(s,2,8) ' New Index.
sIndex2 = Mid(s,27,8) ' Old PDF Name.
sIndex3 = Mid(s,27,12) ' Old PDF Name with pdf
extension.
sTemp = Replace(s,sIndex2, sIndex) 'Replaces Old PDF
Name with Index information.
I = I + 1 ' Increment
counter.
sIndexArray(I) = Mid(sTemp,27,12) ' Add new PDF
Name and pdf file to array for moving and renaming.
sIndexArray2(I) = sIndex3 ' Add old PDF Name to
array for moving and renaming
Else
N = N + 1
End If
Loop
' Garbage collection
ts.Close
Do While I => 1
' Move and rename old PDF file to new folder. Rename old PDF
file to new PDF file.
fso.MoveFile "C:\Output\" & sIndexArray2(I) & "",
"C:\completed\" & sIndexArray(I) & " "
I = I - 1
Loop
' Delete output file.
fso.DeleteFile("C:\Output\NewNames.txt")
End Sub
ReadFiles