Solved

Updating Fields

Posted on 2011-03-01
5
327 Views
Last Modified: 2012-05-11
I hav ethe following code:
 Private Sub picSnooze1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSnooze1.MouseDown
        Dim intSnoozeTimer As Integer
        intSnoozeTimer = intSnoozeTime
        Integer.TryParse(lblshowsethours.Text, intShowSetHours)
        Integer.TryParse(lblalarmsetminutes.Text, intalarmSetMinutes)
        Dim intSendHours As Integer
        Dim intSendMinutes As Integer

        If intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours > -1 AndAlso intShowSetHours < 12 AndAlso
            lblampm2.Text = "am" Then
            intShowSetHours = intShowSetHours + 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours = 12 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours > 0 AndAlso intShowSetHours <= 10 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = intShowSetHours + 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours = 11 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = 0
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes < 59 Then
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes

            intSendHours = intShowSetHours
            intSendMinutes = intalarmSetMinutes
            Dim strSendHours As String
            Dim strSendMinutes As String
            strSendHours = intSendHours.ToString
            strSendMinutes = intSendMinutes.ToString

            lblshowsethours.Text = strSendHours
            lblalarmsetminutes.Text = strSendMinutes
        End If
If the last condition evaluates to true then the minutes wll update, but if any of the others do then the hours and minutes will not update. The math may not be precise and the code is ugly, but I'm a severe noob. Thanks, the full code is below along with the exe.
Public Class Form1

    Dim intSnoozeTime As Integer
    Dim intShowSetHours As Integer
    Dim intalarmSetMinutes As Integer


    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

        If TimeOfDay.Hour > 12 AndAlso TimeOfDay.Hour <> 24 Then
            lbltimeofdayhours.Text = (TimeOfDay.Hour - 12)
            lblampm1.Text = "pm"
        ElseIf TimeOfDay.Hour = 12 Then
            lbltimeofdayhours.Text = "12"
            lblampm1.Text = "pm"
        ElseIf TimeOfDay.Hour = "0" Then
            lblampm1.Text = "am"
            lbltimeofdayhours.Text = "0"
        Else
            lbltimeofdayhours.Text = TimeOfDay.Hour
        End If

        If TimeOfDay.Minute = 0 Then
            lbltimeofdayminutes.Text = "00"
        ElseIf TimeOfDay.Minute = 1 Then
            lbltimeofdayminutes.Text = "01"
        ElseIf TimeOfDay.Minute = 2 Then
            lbltimeofdayminutes.Text = "02"
        ElseIf TimeOfDay.Minute = 3 Then
            lbltimeofdayminutes.Text = "03"
        ElseIf TimeOfDay.Minute = 4 Then
            lbltimeofdayminutes.Text = "04"
        ElseIf TimeOfDay.Minute = 5 Then
            lbltimeofdayminutes.Text = "05"
        ElseIf TimeOfDay.Minute = 6 Then
            lbltimeofdayminutes.Text = "06"
        ElseIf TimeOfDay.Minute = 7 Then
            lbltimeofdayminutes.Text = "07"
        ElseIf TimeOfDay.Minute = 8 Then
            lbltimeofdayminutes.Text = "08"
        ElseIf TimeOfDay.Minute = 9 Then
            lbltimeofdayminutes.Text = "09"
        Else
            lbltimeofdayminutes.Text = TimeOfDay.Minute
        End If


        If TimeOfDay.Second = 0 Then
            lbltimeofdayseconds.Text = "00"
        ElseIf TimeOfDay.Second = 1 Then
            lbltimeofdayseconds.Text = "01"
        ElseIf TimeOfDay.Second = 2 Then
            lbltimeofdayseconds.Text = "02"
        ElseIf TimeOfDay.Second = 3 Then
            lbltimeofdayseconds.Text = "03"
        ElseIf TimeOfDay.Second = 4 Then
            lbltimeofdayseconds.Text = "04"
        ElseIf TimeOfDay.Second = 5 Then
            lbltimeofdayseconds.Text = "05"
        ElseIf TimeOfDay.Second = 6 Then
            lbltimeofdayseconds.Text = "06"
        ElseIf TimeOfDay.Second = 7 Then
            lbltimeofdayseconds.Text = "07"
        ElseIf TimeOfDay.Second = 8 Then
            lbltimeofdayseconds.Text = "08"
        ElseIf TimeOfDay.Second = 9 Then
            lbltimeofdayseconds.Text = "09"
        Else
            lbltimeofdayseconds.Text = TimeOfDay.Second
        End If
    End Sub

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


        If TimeOfDay.Hour = lblalarmsethours.Text AndAlso
            TimeOfDay.Minute = lblalarmsetminutes.Text AndAlso
            TimeOfDay.Second = lblalarmsetseconds.Text AndAlso
            lblampm1.Text = lblampm2.Text Then
            AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName.ToString()
            AxWindowsMediaPlayer1.settings.volume = 100
        End If
    End Sub




    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'open the file dialog box to open a file

        OpenFileDialog1.Title = "Please Select a File"
        OpenFileDialog1.InitialDirectory = "C:temp"
        OpenFileDialog1.ShowDialog()
        TextBox6.Text = OpenFileDialog1.FileName.ToString()
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        'swap pic1 and pic2 to create impression of being pressed
        PictureBox1.Visible = False
        PictureBox2.Visible = True

        'show snooze button and label
        picSnooze1.Visible = True
        lblSnooze.Visible = True

        'format user input to system time
        If txtsethours.Text = "1" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "13"
        ElseIf txtsethours.Text = "2" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "14"
        ElseIf txtsethours.Text = "3" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "15"
        ElseIf txtsethours.Text = "4" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "16"
        ElseIf txtsethours.Text = "5" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "17"
        ElseIf txtsethours.Text = "6" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "18"
        ElseIf txtsethours.Text = "7" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "19"
        ElseIf txtsethours.Text = "8" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "20"
        ElseIf txtsethours.Text = "9" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "21"
        ElseIf txtsethours.Text = "10" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "22"
        ElseIf txtsethours.Text = "11" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "23"
        ElseIf txtsethours.Text = "12" Or "00" AndAlso txtampm.Text = "am" Then
            lblalarmsethours.Text = "0"
        ElseIf txtsethours.Text = "12" AndAlso txtampm.Text = "pm" Then
            lblalarmsethours.Text = "12"
        Else
            lblalarmsethours.Text = txtsethours.Text
        End If

        'send user input to the actual alarm counter
        lblalarmsetminutes.Text = txtsetminutes.Text
        lblalarmsetseconds.Text = txtsetseconds.Text
        lblampm2.Text = txtampm.Text
        lblshowsethours.Text = txtsethours.Text

        'start the timer
        Timer1.Start()
    End Sub

  


    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        'swap pic1 and pic2 to create impression of being pressed
        PictureBox2.Visible = False
        PictureBox1.Visible = True

        'turn on alarm operation indication
        picOnPulse.Visible = True

        'show the media player
        AxWindowsMediaPlayer1.Visible = True
    End Sub

    Private Sub PictureBox3_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.MouseDown
        PictureBox3.Visible = False
        PictureBox4.Visible = True

        'hide snooze button and label
        picSnooze1.Visible = False
        lblSnooze.Visible = False

        'hide the media play
        AxWindowsMediaPlayer1.Visible = False

        lblalarmsetminutes.Text = "00"
        lblalarmsetseconds.Text = "00"
        lblampm2.Text = "am"
        lblshowsethours.Text = "00"
    End Sub

    Private Sub PictureBox3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox3.MouseUp
        PictureBox4.Visible = False
        PictureBox3.Visible = True
        picOnPulse.Visible = False
    End Sub


    Private Sub picClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picClose.Click
        Me.Close()
    End Sub

    Private Sub picClose_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles picClose.MouseHover
        lblClose.Visible = True
    End Sub

    Private Sub picClose_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles picClose.MouseLeave
        lblClose.Visible = False
    End Sub

    


    Private Sub txtsethours_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtsethours.KeyPress, txtsetminutes.KeyPress, txtsetseconds.KeyPress
        ' allows only numbers and the Backspace key

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
            AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub



   

    Private Sub AboutToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem1.Click
        'show information about the application
        MessageBox.Show("Coded by Robert Kraft." & vbCrLf & _
                        "This is my first application outside of what I have coded for school." & vbCrLf & _
                        "I hope you enjoy my work!",
                        "About Alarming")
    End Sub

    Private Sub CreditToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreditToolStripMenuItem.Click
        'give credit to those that inspired ideas for this application
        'or images used
        MessageBox.Show("Original idea inspired by 10Iceman01 at http://www.youtube.com/watch?v=C1jVh4SIB7c&NR=1" & vbCrLf & _
                        "Green button image from fbouly at http://fbouly.deviantart.com/art/Round-glossy-green-button-114514061" & vbCrLf & _
                        "Blue button from http://registry.gimp.org/taxonomy/term/312" & vbCrLf & _
                        "Broken clock by FloydT at http://www.dirtyharrysplace.com/dailyheadlines/",
                        "Credit")
    End Sub

    Private Sub BackgroundColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackgroundColorToolStripMenuItem.Click
        ColorDialog1.ShowDialog()
        Me.BackColor = ColorDialog1.Color
        txtsethours.BackColor = ColorDialog1.Color
        txtsetminutes.BackColor = ColorDialog1.Color
        txtsetseconds.BackColor = ColorDialog1.Color
        txtampm.BackColor = ColorDialog1.Color
        TextBox4.BackColor = ColorDialog1.Color
        TextBox5.BackColor = ColorDialog1.Color
    End Sub

    Private Sub TextColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextColorToolStripMenuItem.Click
        'sets the foreground font color of clock and set alarm
        'to the value selected by the user from the menu

        ColorDialog2.ShowDialog()
        lbltimeofdayhours.ForeColor = ColorDialog2.Color
        lbltimeofdayminutes.ForeColor = ColorDialog2.Color
        lbltimeofdayseconds.ForeColor = ColorDialog2.Color
        lblampm1.ForeColor = ColorDialog2.Color
        Label5.ForeColor = ColorDialog2.Color
        Label10.ForeColor = ColorDialog2.Color
        Label6.ForeColor = ColorDialog2.Color
        Label9.ForeColor = ColorDialog2.Color
        lblshowsethours.ForeColor = ColorDialog2.Color
        lblalarmsetminutes.ForeColor = ColorDialog2.Color
        lblalarmsetseconds.ForeColor = ColorDialog2.Color
        lblampm2.ForeColor = ColorDialog2.Color
        txtsethours.ForeColor = ColorDialog2.Color
        txtsetminutes.ForeColor = ColorDialog2.Color
        txtsetseconds.ForeColor = ColorDialog2.Color
        TextBox4.ForeColor = ColorDialog2.Color
        TextBox5.ForeColor = ColorDialog2.Color
        txtampm.ForeColor = ColorDialog2.Color
        lblClose.ForeColor = ColorDialog2.Color
        lblCancel.ForeColor = ColorDialog2.Color
        lblSet.ForeColor = ColorDialog2.Color
        lblSnooze.ForeColor = ColorDialog2.Color
    End Sub

    Private Sub TransparentToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransparentToolStripMenuItem1.Click
        'sets the background to aliceblue
        'then sets aliceblue as transparent
        Me.BackColor = Color.AliceBlue
        Me.TransparencyKey = System.Drawing.Color.AliceBlue

    End Sub

    Private Sub SnoozeTimerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SnoozeTimerToolStripMenuItem.Click
        'declare variables
        Dim strinputString As String
        Dim intinputStringConverter As Integer


        'loop input box while values are less than 1 or more than 60
        Do
            'strinputString holds value from InputBox
            strinputString = InputBox("Please set the snooze interval" & vbCrLf & _
                     "in minutes from 1 to 59.", "Snooze Interval")

            'change string into integer
            Integer.TryParse(strinputString, intinputStringConverter)

            'if integer is less than 1 and more than 59 than loop back to input box
            If intinputStringConverter < 1 Or intinputStringConverter > 59 Then
                MessageBox.Show("Please choose a value between 1 and 59.", _
                                "Invalid Entry",
                                MessageBoxButtons.OK)

                'if integer is between 1 and 59 assign it to the snoozetime variable
            Else
                intSnoozeTime = intinputStringConverter
            End If
        Loop Until intSnoozeTime > 1 And intSnoozeTime < 60
    End Sub

    Private Sub picSnooze1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSnooze1.MouseDown
        Dim intSnoozeTimer As Integer
        intSnoozeTimer = intSnoozeTime
        Integer.TryParse(lblshowsethours.Text, intShowSetHours)
        Integer.TryParse(lblalarmsetminutes.Text, intalarmSetMinutes)
        Dim intSendHours As Integer
        Dim intSendMinutes As Integer

        If intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours > -1 AndAlso intShowSetHours < 12 AndAlso
            lblampm2.Text = "am" Then
            intShowSetHours = intShowSetHours + 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours = 12 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours > 0 AndAlso intShowSetHours <= 10 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = intShowSetHours + 1
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes > 59 AndAlso
            intShowSetHours = 11 AndAlso
            lblampm2.Text = "pm" Then
            intShowSetHours = 0
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes - 60

        ElseIf intSnoozeTimer + intalarmSetMinutes < 59 Then
            intalarmSetMinutes = intSnoozeTimer + intalarmSetMinutes

            intSendHours = intShowSetHours
            intSendMinutes = intalarmSetMinutes
            Dim strSendHours As String
            Dim strSendMinutes As String
            strSendHours = intSendHours.ToString
            strSendMinutes = intSendMinutes.ToString

            lblshowsethours.Text = strSendHours
            lblalarmsetminutes.Text = strSendMinutes
        End If

        'swap picSnooze files to emulate button being pressed
        picSnooze1.Visible = False
        picSnooze2.Visible = True

        'stop the music from playing
        If WMPLib.WMPPlayState.wmppsPlaying Then
            Me.AxWindowsMediaPlayer1.Ctlcontrols.stop()
        End If
    End Sub

    Private Sub picSnooze1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSnooze1.MouseUp
        'swap picSnooze files back to complete button pressing animation
        picSnooze2.Visible = False
        picSnooze1.Visible = True
    End Sub
End Class

Open in new window

WindowsApplication1.exe
0
Comment
Question by:psychokraft
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35015303
Was there a question in there somewhere?
0
 
LVL 2

Author Comment

by:psychokraft
ID: 35015743
At the bottom of the question.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 35015783
If you mean that you want your labels to update regardless of which "If" statetment you hit, then you need to move the following block to a point immediately after the "End If" line:
intSendHours = intShowSetHours
            intSendMinutes = intalarmSetMinutes
            Dim strSendHours As String
            Dim strSendMinutes As String
            strSendHours = intSendHours.ToString
            strSendMinutes = intSendMinutes.ToString

            lblshowsethours.Text = strSendHours
            lblalarmsetminutes.Text = strSendMinutes

Open in new window

0
 
LVL 2

Author Comment

by:psychokraft
ID: 35016570
Thank You, I shall now go beat myself about the head and neck.....
0
 
LVL 2

Author Closing Comment

by:psychokraft
ID: 35016576
Thank You, I shall now go beat myself about the head and neck...
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now