VinnyG3
asked on
Military time converting
I am trying to make a program in VB that will convert military time to standard time. I have a simple GUI that has a place to input military time then another text box to show the standard time, then a button to press to do the conversion. I have no idea how to do the code, can anyone help?
Thank you,
Tyler
Thank you,
Tyler
It is very easy.. You just use the Format function.
Do you mean the 24 hour clock?
You only need to change the Format to display in your chosen style.
This will show in 24 hour format.
TextBox2.Text = Format(CDate(TextBox1.Text ), "hh:mm")
This will show in 12 hour format
TextBox2.Text = Format(CDate(TextBox1.Text , "hh:mm AM/PM"))
You only need to change the Format to display in your chosen style.
This will show in 24 hour format.
TextBox2.Text = Format(CDate(TextBox1.Text
This will show in 12 hour format
TextBox2.Text = Format(CDate(TextBox1.Text
This should give you an idea:
MsgBox(Format("HHmmssa", CDate("23:45:22")))
MsgBox(Format("HHmmssa", CDate("23:45:22")))
Of course replace the "23:25:22", with the string from your textbox...
Example:
txtStdTime.text=Format("HH mmssa", CDate(txtMilTime.Text))
Example:
txtStdTime.text=Format("HH
ASKER
I tried the code below and im getting an error. Am i doing something wrong?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = Format("HHmmssa", CDate(TextBox1.Text))
End Sub
Most of us probably assumed you were using tradidtional VB as opposed to .Net.
What is the error?
What is the error?
ASKER
InvalidCastException was unhandled
Conversion from string "22.35.03" to type 'Date' is not valid.
Yes i am using VB express 2005
Conversion from string "22.35.03" to type 'Date' is not valid.
Yes i am using VB express 2005
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much
You are welcome. I'd also suggest validating user input to allow only numbers 0-9 and two ":" in the proper places before trying to convert it.