PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
microwave oven strings are incorrect.-VBForums
Results 1 to 21 of 21

Thread: microwave oven strings are incorrect.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    microwave oven strings are incorrect.

    I'm creating a microwave oven and I'm in need of assistance if anyone is out there? I have 2 problems : my buttons dont work and I believe it's because I have two of the same name variable in local and global scope because the local one hides the global one in its scope. You have two variables called timeIs. My output is lblOut, everytime I try to change the names they underline in blue so I can't even check the start button. And also DisplayTime() to print 0 because it deals with its local variable. I'm not sure what to rename these things or what I should do. Please help if you can! I'm very new to VB and I'm I am very week in this programming language! Thanks.
    Code:
    Public Class frmMicrowaveThree
    
        ' contains time entered as a String
        Private timeIs As String = ""
    
        'Dim Time As Entered
        Private timeObject
       
        ' event handler appends 1 to time string  
        Private Sub btn1_Click(ByVal sender As System.Object, _
         ByVal e As System.EventArgs)
    
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            'timeIs &= "1" ' append digit to time input
            timeIs &= "1 "
            'DisplayTime() ' display time input properly  
        End Sub ' oneButton_Click  
    
        ' event handler appends 2 to time string  
        Private Sub btnTwo_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnTwo.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "2" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' twoButton_Click  
    
        ' event handler appends 3 to time string  
    
        Private Sub btnThree_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnThree.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "3" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' threeButton_Click  
    
        ' event handler appends 4 to time string  
        Private Sub btnFour_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnFour.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "4" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' fourButton_Click  
    
        ' event handler appends 5 to time string  
        Private Sub btnFive_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnFive.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "5" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' fiveButton_Click  
    
        ' event handler appends 6 to time string  
        Private Sub btnSix_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSix.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "6" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' sixButton_Click  
    
        ' event handler appends 7 to time string  
        Private Sub btnSeven_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnSeven.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "7" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' sevenButton_Click  
    
        ' event handler appends 8 to time string  
        Private Sub btnEight_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnEight.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "8" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' eightButton_Click  
    
        ' event handler appends 9 to time string  
        Private Sub btn9_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btn9.Click
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
    
            timeIs &= "9" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' nineButton_Click  
    
        ' event handler appends 0 to time string  
        Private Sub zerobtn_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Zerobtn.Click
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            timeIs &= "0" ' append digit to time input  
            'DisplayTime() ' display time input properly  
        End Sub ' zeroButton_Click  
    
        ' event handler starts the microwave oven's cooking process  
        Private Sub btnStart_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnStart.Click
    
            Dim second As Integer
            Dim minute As Integer
    
    
            ' ensure that timeIs has 4 characters  
            timeIs = timeIs.PadLeft(4, "0"c)
    
            ' extract seconds and minutes  
            second = Convert.ToInt32(timeIs.Substring(2))
            minute = Convert.ToInt32(timeIs.Substring(0, 2))
    
            ' create Time object to contain time entered by user  
            timeObject = New Time(minute, second)
            lblOut.Text = String.Format("{0:D2}:{1:D2}",
                                              timeObject.Minute, timeObject.Second)
    
    
            timeIs = "" ' clear timeIs for future input  
            btnTimer.Enabled = True ' start timer  
    
            'windowPanel.BackColor = Color.Yellow ' turn "light" on  
    
        End Sub ' startButton_Click 
    
        ' event handler to clear input  
    
        Private Sub btnClear_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnClear.Click
    
            ' reset each property or variable to its initial setting  
    
            lblOut.Text = "00:00"
            timeIs = ""
            timeObject = Nothing
            btnTimer.Enabled = False
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            'windowPanel.BackColor = Control.DefaultBackColor
    
        End Sub ' clearButton_Click
    
        ' method to display formatted time in timer window  
        Private Sub DisplayTimer()
    
            Dim second As Integer
            Dim minute As Integer
    
            Dim display As String ' String displays current input  
    
    
            ' if too much input entered  
            If timeIs.Length > 4 Then
                timeIs = timeIs.Substring(0, 4)
            End If
    
            display = timeIs.PadLeft(4, "0"c)
    
    
            ' extract seconds and minutes  
            second = Convert.ToInt32(display.Substring(2))
            minute = Convert.ToInt32(display.Substring(0, 2))
    
            ' display number of minutes, ":" and number of seconds  
    
            lblOut.Text = String.Format("{0:D2}:{1:D2}", _
            minute, second)
    
        End Sub ' DisplayTime
    
        Private Sub btnTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimer.Click
            ' event handler displays new time each second  
    
            ' perform countdown, subtract one second  
            If timeObject.Second > 0 Then
                timeObject.Second -= 1
    
                lblOut.Text = String.Format("{0:D2}:{1:D2}", _
      timeObject.Minute, timeObject.Second)
            ElseIf timeObject.Minute > 0 Then
                timeObject.Minute -= 1 ' subtract one minute  
                timeObject.Second = 59 ' reset seconds for new minute  
    
                lblOut.Text = String.Format("{0:D2}:{1:D2}", _
                 timeObject.Minute, timeObject.Second)
            Else ' no more seconds  
                btnTimer.Enabled = False ' stop timer  
                My.Computer.Audio.Play(My.Resources.Done, AudioPlayMode.Background)
                lblOut.Text = "Done!" ' inform user time is finished  
                'windowPanel.BackColor = Control.DefaultBackColor
            End If
    
        End Sub ' clockTimer_Tick
    
    
    End Class

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    you're right about the variables. the local 1 would take precedence.
    do your number buttons have the number as their text? you could probably use much less code.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    Private Sub btnTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimer.Click

    ??? shouldn't that be a timer + not a button?
    add a timer from the components group in your toolbox + set it's interval property to 1000

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: microwave oven strings are incorrect.

    Quote Originally Posted by charyl View Post
    I'm not sure what to rename these things or what I should do.
    It really doesn't matter what you name them, as long as they are not the same. Don't be afraid of using long names. You can use startTimeIs, currentTimeIs, originalStartTimeIs just to give you ideas. And focus on ONE thing at a time. It can be overwhelming, this doesn't work, that doesn';t work, but when you do that you over whelm yourself. Focus on one thing, and if you get stuck, post your code and we can help.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    When I changed it to Tick. It says Tick event can not be found and the -last tick is underlined in blue?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    that's because btnTimer is a button.
    you can't expect a button to behave as a timer.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    k, fixed that, Thank you very much, my next issue is in the numbers area the displayTime() is underlined in blue? Why? Error reads:
    Error 1 'DisplayTime' is not declared. It may be inaccessible due to its protection level. 18 9 MicrowaveThree

    When I change it lblOut Error reads:
    Error 2 Property access must assign to the property or use its value. 27 9 MicrowaveThree
    My output box is called lblOut, but I'm not sure how to declare it? or what to do?

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    you don't have a sub displayTime. you DO have a sub displayTimer though.

    here's some improvements to check. i had to comment out the sounds as i don't have them:
    Attached Files Attached Files

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    beautiful work! What a great brain! I have 4 errors (3 are the same)
    Error 1 'Timer1' is not declared. It may be inaccessible due to its protection level. 48 9 MicrowaveOven
    Tried Dim As int and Dim as String and Private Timer1 as String and none of those worked? Closest I've been in 3 days.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    timer1 was the timer component i used

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    I guess that's why I'm a little confused by the error, I copied your code into my work and I see you even created a sub for it so I don't understand why it would not be declared? I recreated this 3 times so I copied into my second version?

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    to use the timer1_tick event handler + set timer1.enabled, you need to add a timer named timer1 to your form

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    Quote Originally Posted by .paul. View Post
    Private Sub btnTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimer.Click

    ??? shouldn't that be a timer + not a button?
    add a timer from the components group in your toolbox + set it's interval property to 1000
    ohhhh. very cool didnot understand that, have not used that function yet so now my question would be if I put the timer in over the lblOut does it matter? can you place it anywhere? Sorry, I'll get smarter the more I use this stuff, at this point I'm almost understand parts of Greek

    K, put the timer in and now none of my buttons work.
    Last edited by charyl; Oct 16th, 2011 at 04:06 PM.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    go back to the example project i posted + open frmMicrowaveThree.

    below the form (at design time. see attached image) there's a little clock icon that says Timer1 next to it. click the icon + you'll see it's properties in the properties window. doubleclick the icon + it'll open your code editor at the timer1_tick event.

    to add a timer to your form, in your form's design view, open your toolbox + scroll down to the Components group. at the bottom of the group you'll find the timer component + doubleclicking it will add a timer to your form
    Attached Images Attached Images  

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    I'll try it again, maybe I did something wrong the first time. I read an article before I messed with it. but I could have done something wrong. I set the properties to enable as well.

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    My post disappeared? I figured out the button issue...sort of. When I enter a 2 -0 it's fine/ haven't figured out the 1 yet, but. when i go to type in 200 it earases the 2 and put's in a 0. I know it's because of how I have it coded but I'm not sure how to code it to print out 20:00
    Code:
       
     ' event handler appends 2 to time string  
        Private Sub btnTwo_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnTwo.Click
    
    
            My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
            lblOut.Text = "2" 'display it  
    
        End Sub ' twoButton_Click
    Now the timer1: I cut and pasted from the btnTimer to the Timer1, not sure if that is correct, but it I get an exception that says : NullReferenceWas Unhandled. In this line of code: I'll go back and look at your code to make sure I did this right.

    Code:
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            ' perform countdown, subtract one second  
            If timeObject.Second > 0 Then
                timeObject.Second -= 1
    
                lblOut.Text = String.Format("{0:D2}:{1:D2}", _
      timeObject.Minute, timeObject.Second)
            ElseIf timeObject.Minute > 0 Then
                timeObject.Minute -= 1 ' subtract one minute  
                timeObject.Second = 59 ' reset seconds for new minute  
    
                lblOut.Text = String.Format("{0:D2}:{1:D2}", _
                 timeObject.Minute, timeObject.Second)
            Else ' no more seconds  
                btnTimer.Enabled = False ' stop timer  
                My.Computer.Audio.Play(My.Resources.Done, AudioPlayMode.Background)
                lblOut.Text = "Done!" ' inform user time is finished  
                'windowPanel.BackColor = Control.DefaultBackColor
            End If
        End Sub
    End Class

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    I was just playing with your microwave and I can't believe how simplistic the code is and it works so beautifully...Thanks so much this project has taught me so much! I really appreciate your help and the visual. I'm very visual. I hope I can do something nice for you one day. If you ever need help with graphic design or web design or photography give me a shout I would be glad to help you out any way I can! Thanks so much.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    I work a lot in illustrator, photoshop and InDesign.

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Oct 2011
    Posts
    23

    Re: microwave oven strings are incorrect.

    okay, here's a question for you. When you press the start button the background image needs to change. I have it in my resources folder. I tried using this code: But it's wrong...Any suggestions?
    Code:
    My.Computer.BackgroundImage = (my.resources, 72Running.BackgroundImage)

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    you mean the form's backgroundimage or your system wallpaper?

  21. #21
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: microwave oven strings are incorrect.

    vb Code:
    1. Me.BackgroundImage = (my.resources.[resourceName])

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width