none
Scope of Structure Array RRS feed

  • Question

  • Apparently I'm having some problems with the scope of my Structure array. My structure seems to work fine within the module, but the data is missing when i move to another module. I guess I ought to make sure I'm declaring it correctly, first:

    Imports System.IO
    Public Class MainForm
        Public Structure EqStruc            'information for each device
            Public usbAddress As String     'USB resource descriptor. USB address
            Public usrName As String        'alias usrName. Name assigned by user.
            Public usbModel As String       'model derived from USB resource descriptor
            Public eqSerial As String       'serial number derived from USB resource descriptor
            Public cmdGroup As String       'usrName of command list. The usrName assigned to the list of commands for this device
            Public outFilePath As String    'output file path for all measurements
        End Structure
        Public Shared EquipStrucs(0) As EqStruc

    ...........

    I'd like to share EquipStrucs(0) throughout my program. Is this OK? BTW, I'll be expanding the array with Redim Preserve, later on.

    Thanks,

    Dave


    BiggyD


    • Edited by Biggy D Tuesday, November 27, 2018 5:58 PM
    Tuesday, November 27, 2018 1:28 AM

Answers

  • I discovered the problem. The declaration,

    Public Class MainForm
        Public Structure EqStruc            'information for each device
            Public usbAddress As String     'USB resource descriptor. USB address
            Public usrName As String        'alias usrName. Name assigned by user.
            Public usbModel As String       'model derived from USB resource descriptor
            Public eqSerial As String       'serial number derived from USB resource descriptor
            Public cmdGroup As String       'usrName of command list. The usrName assigned to the list of commands for this device
            Public outFilePath As String    'output file path for all measurements
        End Structure
        Public Shared EquipStrucs() As EqStruc

    ............................... , 

    is correct. The error was that I was using Redim without Preserve in another part of the program. This, of course, deleted the contents of the structure. Thanks anyhow for your help.


    BiggyD

    • Marked as answer by Biggy D Friday, November 30, 2018 9:02 PM
    Friday, November 30, 2018 9:02 PM

All replies

  • Hi,

    like this?You can use the list directly.

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim Eq As List(Of MainForm.EqStruc) = New List(Of MainForm.EqStruc)
            MainForm.EquipStrucs(0).usbAddress = "xxx1"
            MainForm.EquipStrucs(0).usrName = "xxx2"
            MainForm.EquipStrucs(0).usbModel = "xxx3"
            MainForm.EquipStrucs(0).eqSerial = "xxx4"
            MainForm.EquipStrucs(0).cmdGroup = "xxx5"
            MainForm.EquipStrucs(0).outFilePath = "xxx6"
            Eq.Add(MainForm.EquipStrucs(0))
    
    
        End Sub
    End Class
    Public Class MainForm
        Public Structure EqStruc            'information for each device
            Public usbAddress As String     'USB resource descriptor. USB address
            Public usrName As String        'alias usrName. Name assigned by user.
            Public usbModel As String       'model derived from USB resource descriptor
            Public eqSerial As String       'serial number derived from USB resource descriptor
            Public cmdGroup As String       'usrName of command list. The usrName assigned to the list of commands for this device
            Public outFilePath As String    'output file path for all measurements
        End Structure
        Public Shared EquipStrucs(0) As EqStruc
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 28, 2018 2:04 AM
  • I discovered the problem. The declaration,

    Public Class MainForm
        Public Structure EqStruc            'information for each device
            Public usbAddress As String     'USB resource descriptor. USB address
            Public usrName As String        'alias usrName. Name assigned by user.
            Public usbModel As String       'model derived from USB resource descriptor
            Public eqSerial As String       'serial number derived from USB resource descriptor
            Public cmdGroup As String       'usrName of command list. The usrName assigned to the list of commands for this device
            Public outFilePath As String    'output file path for all measurements
        End Structure
        Public Shared EquipStrucs() As EqStruc

    ............................... , 

    is correct. The error was that I was using Redim without Preserve in another part of the program. This, of course, deleted the contents of the structure. Thanks anyhow for your help.


    BiggyD

    • Marked as answer by Biggy D Friday, November 30, 2018 9:02 PM
    Friday, November 30, 2018 9:02 PM