Results 1 to 5 of 5

Thread: [RESOLVED] Comparison Problem

  1. #1

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    Resolved [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?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    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.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Lively Member Brian M.'s Avatar
    Join Date
    Nov 2006
    Location
    Moberly MO
    Posts
    94

    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
  •  



Click Here to Expand Forum to Full Width