I have this code working properly. i can able to connect & call the number of log from the device but cant able to read Enroll number. when ever the code reaches mesagbox(“2”) & after display it cant able to see mesagebox(“2.5”). it keeps error message “Conversion from string”” to type ‘Integer’ is not valid.”.
when i put this code
“If String.IsNullOrEmpty(dwEnrollNumber) Then
MessageBox.Show(“Error: Empty or invalid User ID”)
Else”
it shows me where it have issue but i cant able to escape this “” value.
Below is the code in general.
I think i make this question clear.
**Imports zkemkeeper
Public Class Form1
Dim axCZKEM1 As New zkemkeeper.CZKEM
Dim dt As New DataTable()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Add columns to the DataTable for displaying in DataGridView
' Set up DataTable columns for the DataGridView
dt.Columns.Add("User ID")
dt.Columns.Add("Check-in Time")
dt.Columns.Add("Check-out Time")
dt.Columns.Add("Verification Method")
dt.Columns.Add("Device ID")
DataGridView1.DataSource = dt
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox("OK")
Dim ip As String = TextBox1.Text ' Replace with your device's IP
Dim port As Integer = 4370 ' Default ZKTeco port
If axCZKEM1.Connect_Net(ip, port) Then
MessageBox.Show("Connection successful!")
Else
MessageBox.Show("Failed to connect.")
End If
Dim isConnected As Boolean = axCZKEM1.Connect_Net(ip, port)
If Not isConnected Then
MessageBox.Show("Failed to reconnect to the device.")
Return
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim ip As String = TextBox1.Text
Dim port As Integer = 4370
Dim dwMachineNumber As Integer = 101 ' Your machine number
' Connect to the device
If axCZKEM1.Connect_Net(ip, port) Then
MessageBox.Show("Connection successful!")
' Clear any old data
dt.Rows.Clear()
' Get the log count from the device
Dim logCount As Integer = 0
If axCZKEM1.GetDeviceStatus(dwMachineNumber, 6, logCount) Then
MessageBox.Show("Log Count: " & logCount.ToString())
' Ensure there's at least one log to read
If logCount > 0 Then
MsgBox("0")
' Enable the device to read logs
If axCZKEM1.ReadAllGLogData(dwMachineNumber) Then
MsgBox("1")
' Loop to read logs
Dim dwEnrollNumber As String = ""
Dim dwVerifyMode As Integer = 0
Dim dwInOutMode As Integer = 0
Dim dwYear As Integer = 0
Dim dwMonth As Integer = 0
Dim dwDay As Integer = 0
Dim dwHour As Integer = 0
Dim dwMinute As Integer = 0
Dim dwSecond As Integer = 0
Dim dwWorkCode As Integer = 0
MsgBox("2")
' Attempt to read the first log entry
Dim isSuccess As Boolean = axCZKEM1.GetGeneralLogData(dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkCode)
MsgBox("2.5")
' Check if the initial read was successful
If Not isSuccess Then
MessageBox.Show("Failed to retrieve the first log data. Ensure valid logs are available.")
Exit Sub
End If
' Loop to read all log entries
While isSuccess
MsgBox("3")
' Check if EnrollNumber is valid
If Not String.IsNullOrWhiteSpace(dwEnrollNumber) AndAlso IsNumeric(dwEnrollNumber) Then
MsgBox("4")
Try
MsgBox("5")
' Create a new row for the DataTable
Dim row As DataRow = dt.NewRow()
' Fill the row with log details
row("User ID") = dwEnrollNumber
row("Verification Method") = dwVerifyMode.ToString()
row("Device ID") = dwMachineNumber.ToString()
' Format the log time
Dim logTime As String = New DateTime(dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond).ToString("yyyy-MM-dd HH:mm:ss")
If dwInOutMode = 0 Then
row("Check-in Time") = logTime
ElseIf dwInOutMode = 1 Then
row("Check-out Time") = logTime
End If
' Add the row to the DataTable
dt.Rows.Add(row)
Catch ex As Exception
MessageBox.Show("Error processing log data: " & ex.Message)
End Try
Else
' Log or skip invalid or empty EnrollNumber
MsgBox("Skipped log entry with invalid EnrollNumber: " & dwEnrollNumber)
End If
' Attempt to read the next log entry
isSuccess = axCZKEM1.GetGeneralLogData(dwMachineNumber, dwEnrollNumber, dwVerifyMode, dwInOutMode, dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond, dwWorkCode)
' If the next read was unsuccessful, show a message
If Not isSuccess Then
MessageBox.Show("Failed to retrieve subsequent log data. Check if there are more logs to read.")
Exit While
End If
End While
' Bind the data to DataGridView
DataGridView1.DataSource = dt
Else
MessageBox.Show("Failed to read logs from the device.")
End If
Else
MessageBox.Show("No logs available to read.")
End If
Else
MessageBox.Show("Failed to retrieve log count.")
End If
Else
MessageBox.Show("Failed to connect to the device.")
End If
End Sub
End Class**
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.