vb.net get_unit_info Option Strict ON

Post your .Net discussions here
Post Reply
TimOster
Newbie
Posts: 0
Joined: Mon Dec 01, 2014 5:36 pm

vb.net get_unit_info Option Strict ON

Post by TimOster » Tue Jun 19, 2018 6:02 pm

In my company I am forced to keep Option Strict ON for all projects. That is causing an error in ps2000_get_unit_info().

I have a class named Pico2205A with all the original declares stored.

Pico2205A.ps2000_get_unit_info(handle, infoStr, CShort(infoStr.Length), i), you can't see it, but Visual Studio is complaining about the "i" at the end. Option strict disallows implicit conversion from Integer to Pico2205A.Info.

It wants me to type cast it as follows: Ctype(i, Info)), however when I do that I get nothing back. I'll drop the whole thing here:

Code: Select all

 Sub getDeviceInfo(ByVal handle As Short)

        Dim infoText(7) As String
        Dim infoStr As String
        'Dim i As UInteger

        infoText(0) = "Driver Version:    "
        infoText(1) = "USB Version:       "
        infoText(2) = "Hardware Version:  "
        infoText(3) = "Variant:           "
        infoText(4) = "Batch / Serial:    "
        infoText(5) = "Cal Date:          "
        infoText(6) = "Error code:        "
        infoText(7) = "Kernel Driver Ver: "

        For i As Integer = 0 To infoText.Length - 1
            If i <> 6 Then
                infoStr = "                    "
                pico.UnitInfo(infoStr, CShort(infoStr.Length), CType(i, Info))
                infoText(i) += infoStr
                tbUnitInfo.AppendText(infoText(i))
                tbUnitInfo.AppendText(vbNewLine)
            End If
        Next i
        Console.WriteLine(vbNewLine)
    End Sub
You will also notice I have to comment out dim i =, otherwise VS gives and error saying that variable i hides a variable in an enclosing block.

What am I missing?

Hitesh
PICO STAFF
PICO STAFF
Posts: 2855
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: vb.net get_unit_info Option Strict ON

Post by Hitesh » Thu Jun 21, 2018 10:08 am

Hi Tim,

It's possible that something else was not cast correctly.

Below is code that I have tested after modification:

Code: Select all

Sub getDeviceInfo(ByVal handle As Short)

        Dim infoText(7) As String
        Dim infoStr As String
        Dim i As UInteger

        infoText(0) = "Driver Ver:        "
        infoText(1) = "USB Ver:           "
        infoText(2) = "Hardware Ver:      "
        infoText(3) = "Variant:           "
        infoText(4) = "Batch / Serial:    "
        infoText(5) = "Cal Date:          "
        infoText(6) = "Error code:        "
        infoText(7) = "Kernel Driver Ver: "

        For i = 0 To CUInt(infoText.Length - 1)

            If i <> 6 Then

                infoStr = "                    "
                ps2000_get_unit_info(handle, infoStr, CShort(infoStr.Length), CType(i, Info))
                infoText(CInt(i)) += infoStr
                Console.WriteLine(infoText(CInt(i)) & vbTab)

            End If

        Next i

        Console.WriteLine(vbNewLine)

    End Sub
You might find that you have to make modifications later on in the code as well as a result of using this switch.

Regards,
Hitesh

Software Dev. Engineer

TimOster
Newbie
Posts: 0
Joined: Mon Dec 01, 2014 5:36 pm

Re: vb.net get_unit_info Option Strict ON

Post by TimOster » Fri Jun 29, 2018 4:19 pm

Thanks. I made a small change to send the data to my form and a temp variable to hold the returned string. I get the device info now.

Post Reply