vbs to vb.net

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
 
A

aaron.kempf

sorry bro.. VB 2005 doesn't support translating VBS files or VBA files
or anything other than VB Projects.

RIGHT?

I think that you're hosed you better rewrite it from scratch

-Aaron
 
D

DorkyGrin

If that's true, I think it is crazy. Seems like a guy ought to be able
to drop that VBS stuff into vb.net and with some minor changes, compile
it and have a nice little app.

Any ideas on rewriting the code for VB.net? Perhaps the streamreader
stuff is a good place to start.

anyone?
 
A

aaron.kempf

its' obviously true.

Microsoft doesn't realize that 90% of the VB6 code in the world-- it
never lived in true VB6; it lives in VBA / VBS.

and apparently they don't give a crap.

I just think that a bunch of retarded 3rd graders could have designed a
more effective code translator; or for that matter; language and IDE.

VB.net is a complete failure in the open market.
you should give up and move everything to PHP.

-Aaron
 
A

aaron.kempf

seems to me also

I just don't think that MS has a single brain cell anywhere in their VB
departments

Maybe they think that they've automated everything so much that they
don't need people to deal with marketing / technical problems.

but as it is; vb6 is only about 10% of the VB6 language.. and somehow
those dipshits in Redmond didn't realize

I mean; they already killed off the worlds' most popular language.

If I were you; I would just leave the MS train and go out and use PHP.

-Aaron
 
B

Bruce W. Darby

DorkyGrin,

Go to the MSDN webpage and enter 'Convert vbs to vb.net' in the search box.
Lots of good information there.
 
D

DorkyGrin

Maybe I'm looking in the wrong spot on MSDN. I didn't find much.

Can I just call a VBS file from a VB.net window? I read something like
this should work:

Process.Start("C:\test.vbs")

Or, is there anyone out there that can get me started on vb.net code to
do what the posted vbs code is doing?

Thanks
 
B

Branco Medeiros

DorkyGrin wrote (inline):
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.

Well, just as in VB.Classic, you'd have to disable Option Explicit (and
Option Strict also, in VB.Net) for the sample code to compile.

The particular code you posted seem to compile and run without
glitches, here. Notice, however that a few things might get wrong in
the long term, mainly the memory management of the COM objects you
create (fso and ts).

So, if you want to use the code as-is, I'd recommend you add, at the
end of the Sub:

System.InteropServices.Marshall.ReleaseComObject(ts)
System.InteropServices.Marshall.ReleaseComObject(fso)
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?

I don't know of a good way of converting VB/VBA code to VB.Net, sorry.
Personally, I'd try to recreate it from scratch, as suggested by aaron.
A possible, direct translation (with no error checking, mind you),
could be:

<code>
Sub RenameFiles()
Const PATH_SOURCE As String = "C:\Output\"
Const PATH_DEST As String = "C:\Completed\"
Const FILE_NAMES As String = "C:\Output\NewNames.txt"

Dim OldNames As New List(Of String)
Dim NewNames As New List(Of String)

For Each Line As String _
In System.IO.File.ReadAllLines(FILE_NAMES)
If Line(4) <> "C"c Then
Dim OldName As String = Line.Substring(26, 12)
Dim NewName As String = Line.Substring(1, 8)
OldNames.Add(OldName)
NewNames.Add(NewName & OldName.Substring(8))
End If
Next
For I As Integer = 0 To OldNames.Count - 1
System.IO.File.Move(PATH_SOURCE & OldNames(I), _
PATH_DEST & NewNames(I))
Next
System.IO.File.Delete(FILE_NAMES)
End Sub
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.
<snip>

I don't see why not using VB.Net for what you suggest.

HTH.

Regards,

Branco.
 
D

DorkyGrin

Branco, thanks. I'll mess around with your example code sometime in the
next couple of days.

Thanks again for the reply!
 
A

aaron.kempf

wtf why would be go to msdn to search?

they already screwed up the local help-- it takes 20 seconds to launch
and it goes to the wrong results - ALL THE TIME-- ; why in the world
would we trust ms help??

i go to import project, import code.. and the only files it lets me
import are .BAS and .VBP and .frm.. right?

-aaron
 
B

BogusID

seems to me also

I just don't think that MS has a single brain cell anywhere in their VB
departments

Maybe they think that they've automated everything so much that they
don't need people to deal with marketing / technical problems.

but as it is; vb6 is only about 10% of the VB6 language.. and somehow
those dipshits in Redmond didn't realize

I mean; they already killed off the worlds' most popular language.

If I were you; I would just leave the MS train and go out and use PHP.

-Aaron


Yea, the companies "get it right curve" is just repeating itself yet again.

Back in the 80's we coded using Microsoft Basic and IBM Basic, compiling
tight and fast Exe's that fit on a 5-1/4 diskette.
Then came QuickBasic built on their already polished compiler, which evolved
into the Basic Profession Development System 7, it was sweet with lots of
solid 3rd party tools.

Then they pushed the VB-DOS stuff on us to accustom everyone to the IBM
TopView pseudo-graphical DOS interface using ASCII characters!
There was only 1 version of this, just testing the waters guys...

Then they pushed VB1.0 out the door, what a piece of work that was...
Then around version 3.0 they finally had something stable and usable enough
for people who code for a living to begin porting stuff over to take
advantage of the Windows 3.1 & WFW interface.
The enhancements and fine tuning brought us all the way to VB 6.0 Enterprise
and things were sweet again, with lots of solid 3rd party tools.


Now they are pushing .net...and betting their future on it, touted as a
common core for all development languages.
And they will get away with bundling it for free by saying *any* software
development vendor tools can use it, if they can learn how.

..net 1.0 what a piece of work that was, empty functions with no code, here a
crash there a crash, nice try guys.
..net 1.1 rewrote it and changed lots of the naming, syntax and topology 'so
it made more logical sense' to developers.
..net 2.0 is becoming more stable, and most of the functions have code now,
but it still crashes and runs like a pig.

maybe 3.0 will finally give us something stable and usable...we'll have to
get used to deploying new apps on a CD :)

They will include .net with the OS, so it would not need to ship with
applications, but which version you got depends upon which OS you used.
They will use this to push Vista with .net 3.0 and drop Win2000 and .net 1.1
support almost immediately.



Then in 2010 when its all stable they will push out a new platform called
WinAgent, a natural language OS computer that you wear on your wrist, and it
will learn your individual decision tree patterning to allow you to focus on
more important tasks. The first release will probably get worn by some
generals, and due to a Chinese pirated copy with a hacked language
interface, will cause a language translation protocol syntax bug that sets
off a nuclear war...

So where do I want to go today, straight to Bill's house to punch him right
in the mouth!
 
A

aaron.kempf

I think that the whole 'lets invent Windows XP' thing was a complete
load of CRAP

windows 2000 was the best!!!!


re:
They will include .net with the OS, so it would not need to ship with
applications, but which version you got depends upon which OS you used.

They will use this to push Vista with .net 3.0 and drop Win2000 and
..net 1.1
support almost immediately

even if they DO finally figure out how to get .NET framework on EVERY
DESKTOP EVERYWHERE they still won't give us tools like this:

a) ability to determine which version of the framework is present
b) ability to 'SYNC' libraries-- so that instead of installing SQL
Server you just need to download the SQL Server namespaces.. using a
tool like Windows Update
 
B

BogusID

I think that the whole 'lets invent Windows XP' thing was a complete
load of CRAP

windows 2000 was the best!!!!


re:
They will include .net with the OS, so it would not need to ship with
applications, but which version you got depends upon which OS you used.

They will use this to push Vista with .net 3.0 and drop Win2000 and
.net 1.1
support almost immediately

even if they DO finally figure out how to get .NET framework on EVERY
DESKTOP EVERYWHERE they still won't give us tools like this:

a) ability to determine which version of the framework is present
b) ability to 'SYNC' libraries-- so that instead of installing SQL
Server you just need to download the SQL Server namespaces.. using a
tool like Windows Update

DOS6.22 & WFW3.1, Win95, WinMe, W2K ... all the same deal, 3 versions to
stability, and then lets move everyone on again, progress?
WinXP is just about stable now, so it must be time :)

They would have to listen to developers and users before such sensible
modularization happens, it would be cool though!
Nobody will focus on our needs until the cash flow dries up enough to
prevent hiding the problems within...

IF such things happen, I'd expect to be required to setup a .net passport
account with a credit card definition to pay for these modules like we do
music.
Oh, and lets not forget, we also need to be validated to be sure the
computer is certified 'Genuine' first!
 
A

aaron.kempf

yeah it just pisses me off

they discontinue support for the old stuff.. before the new stuff is
'production ready'

is Windows 2003 even ready yet?

the idea is SP1 = new features.. SP2 = bug fixes

why does Windows Update take a goddamn hour? BECAUSE SOMEWHERE; MS
DECIDED TO STOP MAKING SERVICE PACKS


why does Windows Update take a goddamn hour? BECAUSE SOMEWHERE; MS
DECIDED TO STOP MAKING SERVICE PACKS



WHERE THE FLYING **** IS SP1 FOR VS 2005; YOU STUPID ****ING COMPANY?
WHERE THE FLYING **** IS SP1 FOR VS.NET 2003; YOU STUPID ****ING
COMPANY?
WHERE THE FLYING **** IS NT SP7; YOU STUPID ****ING COMPANY?
WHERE THE FLYING **** IS WINDOWS 2000 SP5; YOU STUPID ****ING COMPANY?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top