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
VinnyG3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
It is very easy..  You just use the Format function.  
0
GrahamSkanRetiredCommented:
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"))
0
SStoryCommented:
This should give you an idea:

        MsgBox(Format("HHmmssa", CDate("23:45:22")))
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SStoryCommented:
Of course replace the "23:25:22", with the string from your textbox...

Example:
txtStdTime.text=Format("HHmmssa", CDate(txtMilTime.Text))
0
VinnyG3Author Commented:
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

Open in new window

0
GrahamSkanRetiredCommented:
Most of us probably assumed you were using tradidtional VB as opposed to .Net.

What is the error?
0
VinnyG3Author Commented:
InvalidCastException was unhandled
Conversion from string "22.35.03" to type 'Date' is not valid.

Yes i am using VB express 2005
0
SStoryCommented:
try using 22:35:03 instead

if you must use periods then write a routine to replace all periods with ":" because that is what Format expects.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VinnyG3Author Commented:
Thank you very much
0
SStoryCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.