简体   繁体   English

数组数组visual basic

[英]array of arrays visual basic

I'm developing a module for capture Attlogs from a ZKSoftware Fingerprint Biometric and send it to MySQL database using the SDK that came with the CD, so far I manage to connect successfully to the clock, display the logs on a listview, but I got stuck pushing the values on a multidimensional array, i'm sure it's a matter of declaration but I better ask for help... the code is as follows: 我正在开发一个用于从ZKSoftware指纹生物识别中捕获Attlogs的模块,并使用CD附带的SDK将其发送到MySQL数据库,到目前为止,我设法成功连接到时钟,在列表视图上显示日志,但我得到了坚持推动多维数组的值,我确定这是一个声明问题,但我最好寻求帮助......代码如下:

Dim thisLog(1) As String
Dim allLogs()() As String = New String()() {}

afterwards where the iteration (i) load the Attlogs in the listview I got: 之后在迭代中(i)在listview中加载Attlogs我得到了:

            thisLog = {sdwEnrollNumber, idwYear.ToString() & "-" + idwMonth.ToString() & "-" & idwDay.ToString() & " " & idwHour.ToString() & ":" & idwMinute.ToString() & ":" & idwSecond.ToString()}
            allLogs(i) = {thisLog(0), thisLog(1)}

The error I'm getting is related to the size of the array, so the question can be resumed in how can I create a rectangular array (2)(n) with every row of the captured data. 我得到的错误与数组的大小有关,因此可以恢复如何在捕获数据的每一行创建矩形数组(2)(n)的问题。 Thanks in advance 提前致谢

I would highly suggest you create a class to store the data in. Have a List(Of LogEntry) afterward. 我强烈建议你创建一个类来存储数据。之后有一个List(Of LogEntry)。 This would make your code a lot easier to read. 这将使您的代码更容易阅读。

Class LogEntry

    Public Property EnrollNumber As String
    Public Property EntryDate As DateTime

    Public Sub New(ByVal enrollNumber As String, ByVal entryDate As DateTime)

        Me.EnrollNumber = enrollNumber
        Me.EntryDate = entryDate

    End Sub

End Class

For adding a new record, you just need to create an instance of that class and add it to the list. 要添加新记录,您只需创建该类的实例并将其添加到列表中。

    Dim allLogs As New List(Of LogEntry)

    allLogs.Add(New LogEntry(sdwEnrollNumber, New DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond)))

Since you'll now have a valid date instead of a concatenation of string, it'll be easy to do manipulation afterward. 由于您现在将拥有一个有效的日期而不是字符串的串联,因此以后可以轻松进行操作。

    Console.WriteLine(allLogs(0).EnrollNumber)
    Console.WriteLine(allLogs(0).EntryDate.ToString("yyyy-MM-dd HH:mm:ss"))

how can I create a rectangular array (2)(n) with every row of the captured data? 如何用捕获数据的每一行创建一个矩形数组(2)(n)?

Use a List: 使用清单:

Dim allLogs As New List(Of String())()

allLogs.Add(New String(1) {sdwEnrollNumber, _
     String.Format("{0}-{1}-{2} {3}:{4}:{5}", _
     idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond)} )

I might also use the appropriate DateTime constructor and format string to format that 2nd part, depending on how you get those idw variables in the first place. 我也可以使用适当的DateTime构造函数格式字符串来格式化第二部分,具体取决于你如何获得这些idw变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM