hi, i got a message board kit that connects to the computer (i talked about it here: http://www.daniweb.com/software-development/vbnet/threads/379541)
and now (i hope) its working.
I want to make a code that when i press on a button its will send
the correct hour & date and then its will update when there is a change in the time.
For example:
first time its shows the correct time: 20:00 01-01-2001
and after a change on the time (after a minute) its will automatically update the time to the correct time: 20:01 01-01-2001 Notice: the time method is: HH:MM MM:DD:YYYY
Edit: i want also to change the date method to this: HH:MM DD:MM:YYYY
this is the "base" code that i made:
Private Sub Command8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command8.Click
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(13) & VB.Left(TimeString, 5) & " " & DateString
charcounter = 1
Timer1.Enabled = True
End Sub
its just shows the correct time Hour, without automatic update (i need to press again any time i want to get the correct time).
can you help me with this?
PS: here is the full code:
Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class text_to_RS232
Inherits System.Windows.Forms.Form
Dim flag As Boolean 'flag = false : send ID, flag = true : send data
Dim ID As String 'will contain ID address
Dim messagestring As String 'will contain all messages to transmit
Dim charcounter As Short 'will keep track of the position in messagestring
Dim inputtrigger(10) As String 'will keep track of trigger status (1 or 0)
Dim message(10) As String 'will keep track of message content
Dim inputnumber(10) As String 'will keep track of input #
Dim port As String 'keeps serial port #
Dim trigger(10) As Boolean
Private Sub Combo1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo1.SelectedIndexChanged
If comm.PortOpen = True Then comm.PortOpen = False
port = Combo1.Text
comm.CommPort = Val(Combo1.Text)
comm.Handshaking = IO.Ports.Handshake.None
comm.Settings = "2400,N,8,1"
comm.OutBufferSize = 4096
comm.InputLen = 0
comm.RThreshold = 1
comm.SThreshold = 1
comm.PortOpen = True
End Sub
Private Sub Combo2_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Combo2.SelectedIndexChanged
ID = Combo2.Text
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click 'cursor home
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(8)
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click 'send to LCD
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Text1.Text
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click 'clear LCD
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(13)
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click 'date and time
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(13) & " " & DateString
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub Command5_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command5.Click 'time
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(13) & " " & VB.Left(TimeString, 5)
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub Command6_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command6.Click 'clear textbox
Text1.Text = ""
End Sub
Private Sub Command7_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command7.Click
MsgBox("Make sure K8045 is in 'program mode' (press SW2)")
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = "S" & ID & "QQQQQQ" & Chr(13)
charcounter = 1
Timer1.Enabled = True
End Sub
Private Sub text_to_RS232_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim t As Integer
flag = False
For t = 0 To 9
Combo2.Items.Add((Str(t)))
Next t
Combo2.Text = VB6.GetItemString(Combo2, 0)
ID = "0"
Timer1.Enabled = False
On Error GoTo no_port
comm.CommPort = CShort("1")
comm.PortOpen = True
Combo1.Items.Add("1")
comm.PortOpen = False
comm.CommPort = CShort("2")
comm.PortOpen = True
Combo1.Items.Add("2")
comm.PortOpen = False
comm.CommPort = CShort("3")
comm.PortOpen = True
Combo1.Items.Add("3")
comm.PortOpen = False
comm.CommPort = CShort("4")
comm.PortOpen = True
Combo1.Items.Add("4")
comm.PortOpen = False
Exit Sub
no_port:
Combo1.Text = VB6.GetItemString(Combo1, 0)
Exit Sub
End Sub
Private Sub Form_Terminate_Renamed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If comm.PortOpen = True Then comm.PortOpen = False
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
If flag = False Then GoTo sendID
comm.Output = Mid(messagestring, charcounter, 1)
charcounter = charcounter + 1
If charcounter = Len(messagestring) + 1 Then Timer1.Enabled = False
flag = False
If Timer1.Enabled = False Then Me.Cursor = System.Windows.Forms.Cursors.Default
Exit Sub
sendID:
comm.Output = ID
flag = True
End Sub
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Close()
End Sub
Private Sub Command8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command8.Click
flag = False
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
messagestring = Chr(13) & VB.Left(TimeString, 5) & " " & DateString
charcounter = 1
Timer1.Enabled = True
End Sub
End Class
Thanks, Man1919.