K8061 Migration from VB6 to VB.net

I meet difficulties to carry out a migration of VB6 to VB.net (visual basic 2005)

I use the program Demo that was written again

I can connect myself to the K 8061
OpenDevice = 0

On the other hand I do not arrive to read the data.

The program lines are:

Dim i As Long
Dim Buffer(0 To 7) As Long

ReadAllAnalog CardAddress, Buffer(0) ' Line 555
For i = 0 To 7
    If Buffer(i) < 0 Then Buffer(i) = 0
    If Buffer(i) > 1023 Then Buffer(i) = 1023
    VScroll2(i).Value = Buffer(i)
    Label4(i).Caption = Buffer(i)
Next i

The error appears with the line 555:
Une exception de première chance de type ‘System.AccessViolationException’ s’est produite dans appli_connect.exe

It is a matter probably of a non compatible declaration VB net

First question:
Have you gott a program, even in version beta, written in net VB?

Second question:
Can you find the origin of this abnormality?

In advance thank you

You are not using parentheses on line 555:
Change to:
ReadAllAnalog(CardAddress, Buffer(0))

In VB 2005 and VB.NET, all functions or subroutine calls require parentheses around the parameter list (even if the parameter list is empty) e.g.: SetAllDigital()

You are using:
Dim Buffer(0 To 7) As Long

Long is 64 bit integer in VB2005 and VB.NET.
“As Integer” is right in this case (32 bit integer).
Change to:
Dim Buffer(0 To 7) As Integer

Here are some useful links you can check for the differences between VB 6.0 and VB 2005.
Visual Basic Language Concepts: msdn2.microsoft.com/en-us/library/2x7h1hfk(VS.80.aspx
What’s New for Visual Basic 6.0 Users: msdn2.microsoft.com/en-us/library/ms172617(VS.80.aspx
Language Changes for Visual Basic 6.0 Users: msdn2.microsoft.com/en-us/library/skw8dhdd(VS.80.aspx

Very important!
Integer Data Type for Visual Basic 6.0 Users: msdn2.microsoft.com/en-us/library/7f5ztkz3(VS.80.aspx

This is important especially when calling DLL functions!
Parameter Passing Mechanism for Visual Basic 6.0 Users: msdn2.microsoft.com/en-us/library/41zywfyc(VS.80.aspx

For example:
Visual Basic 6.0 declaration: “As Long”
should be changed for Visual Basic 2005 to: “As Integer”

Visual Basic 6.0 declaration: “As Integer”
should be changed for Visual Basic 2005 to: “As Short”

In Visual Basic 6.0, if you do not specify ByVal or ByRef for a procedure parameter, the passing mechanism defaults to ByRef. This allows the variable passed into the procedure to be modified in the calling program.

When you declare a procedure in Visual Basic 2005, the passing mechanism defaults to ByVal for every parameter. This protects arguments against modification.

See also:

Array Bounds for Visual Basic 6.0 Users
Array Size Declaration for Visual Basic 6.0 Users
ReDim Statement for Visual Basic 6.0 Users

Data Type Changes for Visual Basic 6.0 Users
Universal Data Type Changes for Visual Basic 6.0 Users

Declaration Syntax for Visual Basic 6.0 Users
String Length Declaration for Visual Basic 6.0 Users
Structure Declaration for Visual Basic 6.0 Users
Variable Scope for Visual Basic 6.0 Users

Function Changes for Visual Basic 6.0 Users

Format Function for Visual Basic 6.0 Users
Date and Time for Visual Basic 6.0 Users
String ($) Function for Visual Basic 6.0 Users

Miscellaneous Language Changes for Visual Basic 6.0 Users

Boolean Operator for Visual Basic 6.0 Users
File Handling for Visual Basic 6.0 Users
Module Changes for Visual Basic 6.0 Users

Procedure Changes for Visual Basic 6.0 Users

Parameter Passing Mechanism for Visual Basic 6.0 Users
Procedure Calling Sequence for Visual Basic 6.0 Users
Procedure Declaration for Visual Basic 6.0 Users

etc…

thanks

I test these modifications

Here you’ll find the function declarations:
vb-magazin.de/forums/forums/post/11344.aspx

Please note: I found this link with Google. Not tested!
[color=green]EDIT:
Should be:
Private Declare Sub ReadAllAnalog Lib “k8061.dll” (ByVal intCardNumber As Integer, ByRef Buffer As Integer)
Private Declare Sub OutputAllAnalog Lib “k8061.dll” (ByVal intCardNumber As Integer, ByRef Buffer As Integer)
In this case use: ReadAllAnalog(CardAddress, Buffer(0))
OutputAllAnalog(CardAddress, Buffer(0)) [/color]

[color=blue]Or:
Private Declare Sub ReadAllAnalog Lib “k8061.dll” (ByVal intCardNumber As Integer, ByVal Buffer() As Integer)
Private Declare Sub OutputAllAnalog Lib “k8061.dll” (ByVal intCardNumber As Integer, ByVal Buffer() As Integer)
In this case use: ReadAllAnalog(CardAddress, Buffer)
OutputAllAnalog(CardAddress, Buffer)[/color]


 Dim Buffer(0 To 7) As Integer
        Dim buff As String
        buff = ""
        Buffer(0) = ReadAnalogChannel(CardAddress, 0)
        Buffer(1) = ReadAnalogChannel(CardAddress, 1)
        Buffer(2) = ReadAnalogChannel(CardAddress, 2)
        Buffer(3) = ReadAnalogChannel(CardAddress, 3)
        Buffer(4) = ReadAnalogChannel(CardAddress, 4)
        Buffer(5) = ReadAnalogChannel(CardAddress, 5)
        Buffer(6) = ReadAnalogChannel(CardAddress, 6)
        Buffer(7) = ReadAnalogChannel(CardAddress, 7)

        '     ReadAllAnalog(0, Buffer(0))
        For i = 0 To 7
            If Buffer(i) < 0 Then Buffer(i) = 0
            If Buffer(i) > 1023 Then Buffer(i) = 1023

            buff += "Entrée " & i & Buffer(i) & "; "

        Next i

That function perfectly

I tested the analogical entries, it remains me to test the digital output.

On the other hand, I a reading entered by entry, is there makes possibility of making a total reading?

Thank you still for quality for the Velleman answers

You are reading the analog channels separately.
Doesn’t this work: ReadAllAnalog(CardAddress, Buffer(0)) ?

See: msdn2.microsoft.com/en-us/library/63y5ksfs(VS.80.aspx

At last

I found all information on the Velleman website in the chapter

"

K8061/VM140: extened USB interface board

k8061_vistapack_2007v1.zip

"
Thank you still

Ok thanks,

Private Declare Sub ReadVersion Lib “k8061.dll” (ByVal CardAddress As Integer, ByVal Buffer As Integer)

This didn’t work. So use the Byref

Private Declare Sub ReadVersion Lib “k8061.dll” (ByVal CardAddress As Integer, ByRef Buffer As Integer)[/b]

Nice that you found solution from this thread!
Anyhow this seems to work too:

Private Declare Sub ReadAllAnalog Lib "k8061.dll" (ByVal intCardNumber As Integer, ByVal Buffer() As Integer) Private Declare Sub OutputAllAnalog Lib "k8061.dll" (ByVal intCardNumber As Integer, ByVal Buffer() As Integer)
In this case use: ReadAllAnalog(CardAddress, Buffer) OutputAllAnalog(CardAddress, Buffer)
Please note the parentheses in the DLL sub declaration: …ByVal Buffercolor=blue[/color] As Integer