Upgrading code from VB6 to VB.Net

C

Casper

Hi there.

I've been searching the internet for weeks now trying to find out the
fix to
my problem (below) but I don't seem to be getting anywhere!

I'm using Visual Basic 2005 2005 Express Edition (Beta) and am having
some
problems upgrading code from VB6 to VB.Net.

I'm pretty much a newb when it comes to VB, but I've completed a lot of
my
update program, I'm just having trouble with this final part.

The following module changes some of the binary values in the program,
but
VB is coming up with errors:

=START CODE =
Module Patch

Public Sub Patch()

Open "C:\Program Files\My Program\myprog.exe" For Binary As #1

Put #1, &HDFFE2, "¶"

Close #1

End Sub

Public Sub UnPatch()

Open "C:\Program Files\My Program\myprog.exe" For Binary As #1

Put #1, &HDFFE2, "·"

Close #1

End Sub

End Module

=END CODE=

Also, could someone tell me how to call the functions 'Patch' and
'UnPatch'
from the form.

Thanks in advance for your assistance.

Casper.
 
H

Herfried K. Wagner [MVP]

Casper,

Casper said:
I'm using Visual Basic 2005 2005 Express Edition (Beta) and am having
some problems upgrading code from VB6 to VB.Net.
[...]
Open "C:\Program Files\My Program\myprog.exe" For Binary As #1

Put #1, &HDFFE2, "¶"

Close #1

'Open' -> 'FileOpen'
'Put' -> 'FilePut'
'Close' -> 'FileClose'
....
Also, could someone tell me how to call the functions 'Patch' and
'UnPatch' from the form.

'Patch()' or 'UnPatch()', if the routines are placed in a module...
 
C

Casper

Thanks for that Herfried!

I did all the changes and I thoguht everything was gonna work but when
I run the program it comes up with "Invalid Cast Exception" -
"Conversion from string '1181DB' to type 'Long' is not valid"

Here's what my code currently looks like:

=START CODE=

Module Patch
Public Sub RunPatch()

FileOpen(1, "C:\Program Files\MY Program\myprog.exe",
OpenMode.Binary)
FilePutObject(1, "85", "1181DB")
FileClose(1)
End Sub
End Module

=END=

Yet again, I'm totally lost!
 
H

Herfried K. Wagner [MVP]

Casper,

Casper said:
I did all the changes and I thoguht everything was gonna work but when
I run the program it comes up with "Invalid Cast Exception" -
"Conversion from string '1181DB' to type 'Long' is not valid"
[...]
FileOpen(1, "C:\Program Files\MY Program\myprog.exe",
OpenMode.Binary)
FilePutObject(1, "85", "1181DB")

The last parameter expects a record /number/.
 

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