|
-
Jul 14th, 2008, 11:33 AM
#1
Thread Starter
Lively Member
[RESOLVED] Comparison Problem
I am trying to make sure a string reads am or pm before I let the variable be passed to a check routine. I used this but its not working right.
Code:
If alrmampm <> "AM" Or alrmampm <> "PM" Then
MsgBox("Enter a valid time.")
ampmcb.SelectAll()
Exit Sub
End If
But I used the same comparison format here, and it works fine.
Code:
If alrmhours = "" Or alrmhours < 0.ToString Or alrmhours > 12.ToString Then
MsgBox("Enter a valid time.")
hourscb.SelectAll()
Exit Sub
End If
If alrmminutes = "" Or alrmminutes < 0.ToString Or alrmminutes > 59.ToString Then
MsgBox("Enter a valid time.")
minutescb.SelectAll()
Exit Sub
End If
I'm probably going about this the wrong way, but until I learn the vb syntax better I have to work with what I know. So could someone tell me why that expression isn't working?
-
Jul 14th, 2008, 11:38 AM
#2
Re: Comparison Problem
as i mentioned in the other thread, if you use the correct tool i.e. datetimepicker, you will not have the issues you have discussed.
For time only in the dtp you will need:
Code:
DateTimePicker1.Format = DateTimePickerFormat.Time
DateTimePicker1.ShowUpDown = True
"I'm probably going about this the wrong way, but until I learn the vb syntax better I have to work with what I know." Or you could try something new and add it to your skill set.
-
Jul 14th, 2008, 11:47 AM
#3
Thread Starter
Lively Member
Re: Comparison Problem
Ah, ok. So what kind of variable will store the value from the d/t picker? Would it be a time or timespan variable? I'm going to be able to get rid of alot of code now. I didn't know how to format the date/time picker until now. Thanks alot.
-
Jul 14th, 2008, 11:58 AM
#4
Re: Comparison Problem
Code:
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Dim aDT As DateTime = DateTimePicker1.Value
'hint
If aDT > DateTime.Now Then
Stop
Else
Stop
End If
End Sub
-
Jul 14th, 2008, 12:53 PM
#5
Thread Starter
Lively Member
Re: Comparison Problem
Ok. Thanks for the help. I finally got it working right. Here is a link to the solution files.
Tech Alarm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|