I have here my code to send SMS:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
count = DataTable1DataGridView.Rows.Count
For i As Integer = count To 1 Step -1
Try
If SerialPort1.IsOpen Then
'dataGridView1()
' TextBox1.Text = Me.dataGridView1.Rows(0).Cells(2).Value.ToString()
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & DataTable1DataGridView.Rows(i - 1).Cells(2).Value.ToString & Chr(34) & vbCrLf)
.Write(ES_MSG.Rows(0).Cells(0).Value.ToString & Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If (i = count) Then
Exit For
Timer1.Enabled = False
Timer1.Stop()
End If
MsgBox("Message Sent!")
Next
Timer1.Enabled = False
Timer1.Stop()
End Sub
I have enabled timer through a button_click. My problem is timer doesn't seem to stop no matter where I put the Timer.Stop() and Timer.Enabled = False. The worse is when there are errors or when the message is sent, the pop-up seems to appear infinitely even if the count from my datagrid is just small. Can anyone share ideas? I really need it. Thanks.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
count = DataTable1DataGridView.Rows.Count
For i As Integer = count To 1 Step -1
Try
If SerialPort1.IsOpen Then
'dataGridView1()
' TextBox1.Text = Me.dataGridView1.Rows(0).Cells(2).Value.ToString()
With SerialPort1
.Write("AT" & vbCrLf)
.Write("AT+CMGF=1" & vbCrLf)
.Write("AT+CMGS=" & Chr(34) & DataTable1DataGridView.Rows(i - 1).Cells(2).Value.ToString & Chr(34) & vbCrLf)
.Write(ES_MSG.Rows(0).Cells(0).Value.ToString & Chr(26))
End With
Else
MsgBox("Error on the port selected")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If (i = count) Then
Exit For
Timer1.Enabled = False
Timer1.Stop()
End If
MsgBox("Message Sent!")
Next
Timer1.Enabled = False
Timer1.Stop()
End Sub
I have enabled timer through a button_click. My problem is timer doesn't seem to stop no matter where I put the Timer.Stop() and Timer.Enabled = False. The worse is when there are errors or when the message is sent, the pop-up seems to appear infinitely even if the count from my datagrid is just small. Can anyone share ideas? I really need it. Thanks.