Question Execute a statement only if both expressions are met

chopps

New member
Joined
Feb 13, 2011
Messages
4
Programming Experience
Beginner
Hello,
I am new to VisualBasic and trying to learn it online. For my first assignment I have to make a program that allows someone to input a time in AM/PM and select the time zone and automatically output a picture and three other time zones. I think I have it for the most part but I am having an issue with one part in particular. Since the time is input using AM or PM if the original time is 11:00 AM and I add an hour it should switch to PM. But I'm not quite sure what I'm doing wrong. I basically need to say If the time is equal to 12 and the meridiem is equal to am then it should switch to pm but I keep getting errors inidicating they are trying to switch to a boolean value. I have included the code below if anyone can please help me out it would be very much appreciated:

*******************************************
Public Class Form1
Dim time As String
Dim hour As Integer
Dim minutes As String
Dim curTime As String
Dim est As Integer
Dim cst As Integer
Dim mst As Integer
Dim pst As Integer
Dim meridiem As String
Dim ante As String = "AM"
Dim post As String = "PM"
Private Sub fromPacific()
mst = hour + 1
cst = hour + 2
est = hour + 3
If mst = 12 + meridiem = ante Then
ElseIf mst = 12 + meridiem = post Then
meridiem = ante
meridiem = post
End If
If mst > 12 Then mst -= 12
If cst > 12 Then cst -= 12
If est > 12 Then est -= 12
Label1.Text = "MST: " & mst & minutes & meridiem
Label2.Text = "CST: " & cst & minutes & meridiem
Label3.Text = "EST: " & est & minutes & meridiem
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
time = TextBox1.Text
hour = Microsoft.VisualBasic.Left(time, 2)
minutes = Microsoft.VisualBasic.Right(time, 3)
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
PictureBox1.Image = Image.FromFile("C:\Users\Home\Desktop\EST.jpg")
End Sub
Public Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
PictureBox1.Image = Image.FromFile("C:\Users\Home\Desktop\CST.jpg")
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
PictureBox1.Image = Image.FromFile("C:\Users\Home\Desktop\MST.jpg")
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
fromPacific()
PictureBox1.Image = Image.FromFile("C:\Users\Home\Desktop\PST.jpg")
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
If RadioButton5.Checked Then meridiem = ante
End Sub
Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
If RadioButton6.Checked Then meridiem = post
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End
End Sub
End Class
*******************************************
I only posted one of the function fromPacific() for brevity purposes but the other three functions will be similar.
Thanks!
 
I'm not sure what your requirements are but, in a real application, you'd never do that. You'd create a DateTime value and then call its AddHours method. That will handle the AM/PM switch if required.

If you do need to do it manually then you should work in 24 hour time. Let the user enter a value in 12 hour time and then convert to 24 hour time in code. If you have say 11:30 then you add an hour and get 12:30. The value is 12 or greater so you know it's PM. There's no messing with AM/PM because it's a simple determination at the end: if it's 12 or greater then its PM, otherwise its AM.
 
Back
Top