Shop OBEX P1 Docs P2 Docs Learn Events
Experimenting with VB code — Parallax Forums

Experimenting with VB code

WildatheartWildatheart Posts: 195
edited 2010-05-20 01:50 in General Discussion
Hello –
I’m trying to compare the Time Of Day Clock (VB8 Express Edition) with variables set from a “Slider” position. Following the code are the 3 Errors I get. Although labels 2 and 10 do work and display the proper time when the If Statement is commented out, I have no clue what it'll take to make the comparison work in the "If Statement".

The area of the errors is between the # and the #. It seems we can't use variables there.

Thanks for your Help.


Dim EventHour As Integer
Dim EventMin As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Label2.Text = System.DateTime.Today.ToLongDateString
Label10.Text = TimeOfDay


If TimeOfDay >= #EventHour:EventMin:00 AM# Then
Label9.Text = "Event passed"
End If
End Sub

Errors
1. Expression Expected
2. Expression is not a Method
3. Syntax Error

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2010-05-20 01:50
    Hi , I'v seen several examples , this is my own attempt and fits what you need.
    [color=#0000ff][color=#0000ff]Dim[/color][/color] Preset_Time [color=#0000ff][color=#0000ff]As[/color][/color] [color=#0000ff][color=#0000ff]New[/color][/color] [color=#0000ff][color=#0000ff]Date[/color][/color](Now.Year, Now.Month, Now.Day, EventHour, EventMin, 0)
    Label1.Text = System.DateTime.Today.ToLongDateString
    Label10.Text = TimeOfDay.ToLongTimeString
    [color=#0000ff][color=#0000ff]If[/color][/color] TimeOfDay.ToLongTimeString >= Preset_Time.ToLongTimeString [color=#0000ff][color=#0000ff]Then[/color][/color]
    Label9.Text = [color=#a31515][color=#a31515]"Event Passed"[/color][/color]
    [color=#0000ff][color=#0000ff]End[/color][/color] [color=#0000ff][color=#0000ff]If[/color][/color]
    
    

    The time is compared as a string value ,·integers EventHour and EventMin·are entered as Military/24 hour time. These variables need to be initialized before the comparison.

    The format # time # is hard coding a constant value .

    Jeff T.
Sign In or Register to comment.