Home All Groups Group Topic Archive Search About

vb 6.0 naar vb.net 2005

Author
6 Oct 2006 8:03 AM
klenne
Hallo,

Ik probeer een programma, gemaakt in vb 6.0 te openen in vb.net 2005.
Bij het runnen zijn er enkele problemen opgetreden. Ik denk dat het
probleem bij geheugens ligt, declaratie van variabelen die bij het
omzetten naar .net zijn verandert of iets is fout gelopen. Kan het zijn
dat ik internal pointers of zo moet gebruiken? Wie kent hier iets van?
Hoe kan ik een vb 6.0 applicatie laten werken in .net 2005?

Greetz klenne

Author
6 Oct 2006 9:15 AM
Peter Proost
Hi Klenne,

although Cor, opa vito, Pieter, me and some other people are able to read
your post, you probably will get more response when posting in english.

Greetz,

Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

Show quoteHide quote
"klenne" <basvanh***@gmail.com> schreef in bericht
news:1160121794.469602.48450@i3g2000cwc.googlegroups.com...
> Hallo,
>
> Ik probeer een programma, gemaakt in vb 6.0 te openen in vb.net 2005.
> Bij het runnen zijn er enkele problemen opgetreden. Ik denk dat het
> probleem bij geheugens ligt, declaratie van variabelen die bij het
> omzetten naar .net zijn verandert of iets is fout gelopen. Kan het zijn
> dat ik internal pointers of zo moet gebruiken? Wie kent hier iets van?
> Hoe kan ik een vb 6.0 applicatie laten werken in .net 2005?
>
> Greetz klenne
>
Author
6 Oct 2006 10:20 AM
Phill W.
klenne wrote:

(Translation attempted by BabelFish.AltaVista.com)
> I try a programme, made in vb 6.0 to open in vb.net 2005. at
> managing some problems have appeared. I think that the problem lies
> at geheugens, claim of variables which are at converting to net
> change or something error has run. Can it be that I internal must
> use pointers or this way? Who know of this does something?
> How can I leave a vb 6.0 application work in net 2005?

"I try a programme, made in vb 6.0 to open in vb.net 2005"
Another failed "upgrade" attempt.

"How can I leave a vb 6.0 application work in net 2005?"
You can't.
Whilst they may share "Basic" in their names, these are two totally
separate products with radically different ways of doing things.
To get a VB2005 application that works anywhere /near/ as well as its VB
"Proper" predecessor, you are looking at rewriting it.

Regards,
    Phill  W.
Author
6 Oct 2006 12:40 PM
klenne
Hallo,

I'm trying to open a program which is originally written in vb6.0, in
vb.net 2005.
When i try to run the program an error occurs. My guess is that the
problem lies in the fact that the type of adressing the memory is
changed. Therefor the translation to vb.net of the declaration of the
variables isn't correct.

perhaps its best that I will explain my program a liltle bit.

I am supposed to write a vb.net 2005 application that allows
communication between a PC (master) and a plc (slave) true the modbus
protocol with a rs232 cable.

The PC has to be able to read- write data to the plc and show it in the
program. Since the read and write error are the same I will explain the
read error.

So the basic idea is: From my main form ( where i can enter the mode
(read or write), the starting adres, number of registers i want to
read) a module is being called up (i send the mode, number of register,
starting register and such also to the module).

In this module a DLL is being called up (and again the mode, number of
register, starting register and such is send to the dll aswell) the dll
is in the system32 directory. The dll will then use the data from the
starting register, number of register to form a good modbus protocol
message.

code to enter the module with the appropriat declarations:

Private Sub ReadShort_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles ReadShort.Click
        Dim BusState As Integer ' Een aantal shorts van de HPC lezen
        Dim handle, j As Integer
        Dim Ready As Boolean
        Dim Address As TBusAddress
        Dim Data As TShortData

        MBRead( handle, j, 1,
mbShort,CShort(Startadress.Text),Short(numberofRegisters.Text) )

This will call up the module and go to the function MBread

Declare Function MBRead Lib "Modbus" Alias "VBMBReadRequest" (ByRef
handle As Integer, ByVal UserData As Integer, ByVal NodeNr As Short,
ByVal VarType As Short, ByVal StartAddress As Short, ByVal Count As
Short) As Short

This function forms the request that is send to the PLC, so far so
good.

Now the plc send a message back (which he actually sends, so that aint
the problem) which I will catch with the function

Ready = MBGetShorts(handle, j, BusState, Address, Data)  <= is in the
main form

Again the module is being called up.

Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults"
(ByVal MBHandle As Long, ByRef UserData As Long, ByRef BusState As
Integer, ByRef Address As TBusAddress, ByRef Data As TShortData) As
Boolean

The function MBgetShorts catches the response from the plc and puts the
register data in the DATA aray. But from here it goes bad.

At the  line "Ready = MBGetShorts(handle, j, BusState, Address, Data)"
the program stops and shows the error.

FATALEXECUTIONERROR:
error may be a bug in the CLR or in the unsafe or non-verifiable
portions of user code. Common sources of this bug include user
marshaling errors for COM-interop or PInvoke, which may corrupt the
stack.

The program works correct in VB6.0, you fill in the correct registers,
starting adres and mode and then the module and DLL form the request
which is send to the PLC, the plc sends a message back and the DLL and
module collect the DATA from the registers and shows it on the computer
screen.


Someone told me that it might get fixed if i used internal pointers.
Anyone knows if this will solve my problem or any other ideas???

Thx
Klenne


ps: if you dont understand me cause of my bad english phrases please
ask and ill try to reform the phrase.
Author
6 Oct 2006 1:27 PM
Chris Dunaway
klenne wrote:
> Again the module is being called up.
>
> Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults"
> (ByVal MBHandle As Long, ByRef UserData As Long, ByRef BusState As
> Integer, ByRef Address As TBusAddress, ByRef Data As TShortData) As
> Boolean
>

Is this the declaration you used in VB6?  If so, then it is probably
incorrect for VB.Net.  Integers are now 32 bit and Longs are 64 bit.
You may wish to change them to Short and Integer respectively.
Author
6 Oct 2006 1:33 PM
klenne
Chris Dunaway schreef:

> klenne wrote:
> > Again the module is being called up.
> >
> > Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults"
> > (ByVal MBHandle As Long, ByRef UserData As Long, ByRef BusState As
> > Integer, ByRef Address As TBusAddress, ByRef Data As TShortData) As
> > Boolean
> >
>
> Is this the declaration you used in VB6?  If so, then it is probably
> incorrect for VB.Net.  Integers are now 32 bit and Longs are 64 bit.
> You may wish to change them to Short and Integer respectively.

This is the declaration of VB.net,

the declarations for the VB6.0 are
Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults" _
                 (ByVal MBHandle As Long, _
                 ByRef UserData As Long, _
                 ByRef BusState As Integer, _
                 ByRef Address As TBusAddress, _
                 ByRef Data As TShortData) As Boolean

So this should be correct
Author
6 Oct 2006 5:33 PM
Chris Dunaway
klenne wrote:
Show quoteHide quote
> Chris Dunaway schreef:
>
> > klenne wrote:
> > > Again the module is being called up.
> > >
> > > Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults"
> > > (ByVal MBHandle As Long, ByRef UserData As Long, ByRef BusState As
> > > Integer, ByRef Address As TBusAddress, ByRef Data As TShortData) As
> > > Boolean
> > >
> >
> > Is this the declaration you used in VB6?  If so, then it is probably
> > incorrect for VB.Net.  Integers are now 32 bit and Longs are 64 bit.
> > You may wish to change them to Short and Integer respectively.
>
> This is the declaration of VB.net,
>
> the declarations for the VB6.0 are
> Declare Function MBGetShorts Lib "Modbus" Alias "VBMBGetShortResults" _
>                  (ByVal MBHandle As Long, _
>                  ByRef UserData As Long, _
>                  ByRef BusState As Integer, _
>                  ByRef Address As TBusAddress, _
>                  ByRef Data As TShortData) As Boolean
>
> So this should be correct

If that is the VB6 declaration, then your VB.Net declaration is wrong.
MBHandle should be Integer in VB.Net or even IntPtr,  UserData should
be Integer,  BusState should be Short.  Not sure about TBusAddress and
TShortData.
Author
9 Oct 2006 7:02 AM
klenne
>   Not sure about TBusAddress and TShortData.


I declared TBusAdress and TShortData like this

Structure TBusAddress
        Dim NodeNr As Short
    Dim VarType As Short ' mbE, mbA, mbAE, mbAA, mbMerk, mbChar, mbShort
of
        mbLong
    Dim StartAddress As Short
    Dim VarCount As Short
End Structure

Structure TShortData
         <VBFixedArray(63)> Dim ShortData() As Short               '
-32..  -> +32.. , 2 bytes
         Dim ShortData() As Short
       ' -32..  -> +32.. , 2 bytes

    Public Sub Initialize()
            ReDim ShortData(63)
        End Sub
End Structure

About the vbfixedArray i aint sure if thats correct

Greetz,
Klenne