Hi, I would like to create a countdown timer using number extracted from the database to use a the time for the countdown. Can anyone help me ?
joeey 0 Newbie Poster
aparnesh 9 Junior Poster
Not really sure what you are looking for, please give more details. You can create a countdown using a loop. If you want to add or subtract a number from a date, use dateadd() function.
debasisdas 580 Posting Genius Featured Poster
can you please explain a bit in detail.
joeey 0 Newbie Poster
Sorry for the long delay. I'll explain about the project I'm doing. I'm trying to create a SMS based reminder application using visual basic and a GSM modem. Currently, the program has the ability to send, extract, receive and store. Now I would like to enable the program to send a reminder using the time stored in the database. For example, if the user sends 10# tower, this would be saved in the database as 10 under the hour column, User's Handphone number would be under Numbers and tower under Message. Once 10 hours are up, the program would send an SMS back to the user.
Below is the code for the program
Public Class Form1
Dim TotalRows As Integer
Dim NextRecord As Integer
Dim ConObject As New OleDb.OleDbConnection
Dim dSet As New DataSet
Dim dAdapter As OleDb.OleDbDataAdapter
Dim Sel As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConObject.ConnectionString = "PROVIDER=MICROSOFT.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Telematics\My Documents\061514U Edmund\lab_3\ProjectDB.mdb"
ConObject.Open()
Sel = "SELECT*FROM Table1"
dAdapter = New OleDb.OleDbDataAdapter(Sel, ConObject)
dAdapter.Fill(dSet, "ProjectDB")
ConObject.Close()
TotalRows = dSet.Tables("ProjectDB").Rows.Count
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call ModemMode()
End Sub
Private Sub ModemMode()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
SerialPort1.WriteLine("AT+CMGF=1" + vbCr)
WaitForm.ShowDialog()
TextBox1.Text = ""
TextBox1.Text = SerialPort1.ReadExisting
If InStr(TextBox1.Text, "OK") <> 0 Then
MessageBox.Show("Successful(CMGF)!")
Else
MessageBox.Show("Try again")
End If
TextBox1.Text = ""
SerialPort1.WriteLine("AT+CNMI=0,1,0,0,0" + vbCr)
WaitForm.ShowDialog()
WaitForm.ShowDialog()
TextBox1.Text = SerialPort1.ReadExisting
If InStr(TextBox1.Text, "OK") <> 0 Then
MessageBox.Show("Successful(CNMI)!")
Else
MessageBox.Show("Try again")
End If
SerialPort1.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call ReadSMS()
End Sub
Private Sub ReadSMS()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
SerialPort1.WriteLine("AT+CMGR=" + TextBox2.Text + vbCr)
System.Threading.Thread.Sleep(500)
TextBox1.Text = ""
TextBox1.Text = SerialPort1.ReadExisting
SerialPort1.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
SerialPort1.WriteLine("AT+CMGD=1,4" + vbCr)
TextBox1.Text = vbNewLine & "...in progress..."
TextBox1.Refresh()
System.Threading.Thread.Sleep(4000)
System.Threading.Thread.Sleep(4000)
System.Threading.Thread.Sleep(4000)
TextBox1.Text = ""
TextBox1.Text = SerialPort1.ReadExisting
SerialPort1.Close()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Call DeleteOneSMS()
End Sub
Private Sub DeleteOneSMS()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
SerialPort1.WriteLine("AT+CMGD=" + TextBox6.Text + vbCr)
TextBox1.Text = vbNewLine & "...in progress..."
TextBox1.Refresh()
System.Threading.Thread.Sleep(1250)
TextBox1.Text = ""
TextBox1.Text = SerialPort1.ReadExisting
SerialPort1.Close()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Call SendSMS()
End Sub
Private Sub SendSMS()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
SerialPort1.WriteLine("AT+CMGS=" + TextBox3.Text + vbCr)
TextBox1.Text = vbNewLine & "...SMS sending in progress..."
TextBox1.Refresh()
System.Threading.Thread.Sleep(750)
SerialPort1.WriteLine(TextBox4.Text)
System.Threading.Thread.Sleep(500)
SerialPort1.WriteLine(Chr(26))
System.Threading.Thread.Sleep(5500)
TextBox1.Text = ""
TextBox1.Text = SerialPort1.ReadExisting
If InStr(TextBox1.Text, "OK") <> 0 Then
TextBox1.Text = "SMS message successfully sent!"
MessageBox.Show("SMS message successfully sent!")
Else
MessageBox.Show("Try again")
End If
SerialPort1.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox5.Text = TextBox4.Text.Length
If TextBox5.Text > 160 Then
Beep()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
End Sub
Private Sub ExtractPhoneNumber()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
Dim str1
Dim str2
Dim Extract As String
str1 = TextBox1.Text
str2 = str1.Split("D")
TextBox7.Text = str2(1)
Extract = TextBox7.Text.Substring(3, 11)
TextBox7.Text = Extract
End Sub
Private Sub ExtractMessage()
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = 115200
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.DataBits = 8
SerialPort1.StopBits = IO.Ports.StopBits.One
SerialPort1.RtsEnable = True
SerialPort1.Open()
Dim str3
Dim str4
Dim Extract2 As String
Dim Extract3 As String
str3 = TextBox1.Text
str4 = str3.Split("#")
TextBox8.Text = str4(1)
Extract2 = TextBox8.Text.Substring(2)
Extract3 = TextBox8.Text.Substring(0, 2)
TextBox8.Text = Extract2
TextBox9.Text = Extract3
End Sub
Private Sub button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button6.Click
Call ExtractMessage()
Call ExtractPhoneNumber()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim cBuilder As New OleDb.OleDbCommandBuilder(dAdapter)
Dim dsNewRow As DataRow
dsNewRow = dSet.Tables("ProjectDB").NewRow()
dsNewRow.Item("Numbers") = TextBox7.Text
dsNewRow.Item("Message") = TextBox8.Text
dsNewRow.Item("Hours") = TextBox9.Text
dSet.Tables("ProjectDB").Rows.Add(dsNewRow)
dAdapter.Update(dSet, "ProjectDB")
dSet.Clear()
dAdapter.Fill(dSet, "ProjectDB")
MsgBox("Data Stored!")
End Sub
End Class
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.