Problem VB countdown timer help

Discussion in 'Scripting & Programming' started by Timostag, Mar 20, 2010.

  1. Timostag

    Timostag Bit Poster

    45
    0
    9
    Ive had 2 one hour lectures on programming and virtually no experience using any programming language, but I need to build a simple click shoot game using VBA/Excel. The code is abit all over the place at the moment while I try figuring out how to do things, but I'm completely stuck on one thing...

    the game must have a timer and a game over screen, so what ive done is made a text box with 60 typed in and then written a code that -1 every second so it counts down like a timer but I want it to display the game over image I've added when it gets to 0.

    here is the code at the moment (I know its a mess but as I say its work in progress) I'll try to attach the excel file aswell so its easier to read

    '------------ Start screen ------------'

    Private Sub GameOverImg_Click()

    End Sub

    ' when start is clicked the start screen options will no long be visible and the game will start'

    Private Sub StartTxt_Click()
    boolStopPressed = True
    DoEvents
    StartGame
    TimeBox_Change



    End Sub

    Private Sub StartGame()
    ExitTxt.Visible = False
    GameImg.Visible = False
    StartTxt.Visible = False
    Target1.Visible = True
    Target2.Visible = True
    Target3.Visible = True
    Target4.Visible = True
    Target5.Visible = True
    Target6.Visible = True
    Target7.Visible = True
    Target8.Visible = True
    Target9.Visible = True

    End Sub

    '------- GAME CODE ---------'
    Private Sub moving()
    Target1.Left = -30
    sngendtime = DateTime.Timer + 1

    Do While sngendtime > DateTime.Timer

    End Sub





    'target1 is used for testing new codes/effects when perfceted the codes of target 2 - 9 will be changed to match '


    Private Sub Target1_Click()
    boolStopPressed = True
    DoEvents
    Hit1

    End Sub
    Private Sub Hit1()
    Target1.SpecialEffect = fmSpecialEffectSunken
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target1.Visible = False

    End Sub

    ' target 2 onwards will need editing to match the codeing of target 1'

    Private Sub Target2_Click()
    boolStopPressed = True
    DoEvents
    Hit2
    End Sub
    Private Sub Hit2()
    Target2.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target2.Visible = False

    End Sub
    Private Sub Target3_Click()
    boolStopPressed = True
    DoEvents
    Hit3
    End Sub
    Private Sub Hit3()
    Target3.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target3.Visible = False

    End Sub
    Private Sub Target4_Click()
    boolStopPressed = True
    DoEvents
    Hit4
    End Sub
    Private Sub Hit4()
    Target4.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target4.Visible = False

    End Sub
    Private Sub Target5_Click()
    boolStopPressed = True
    DoEvents
    Hit5
    End Sub
    Private Sub Hit5()
    Target5.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target5.Visible = False

    End Sub
    Private Sub Target6_Click()
    boolStopPressed = True
    DoEvents
    Hit6
    End Sub
    Private Sub Hit6()
    Target6.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target6.Visible = False

    End Sub
    Private Sub Target7_Click()
    boolStopPressed = True
    DoEvents
    Hit7
    End Sub
    Private Sub Hit7()
    Target7.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target7.Visible = False

    End Sub
    Private Sub Target8_Click()
    boolStopPressed = True
    DoEvents
    Hit8
    End Sub
    Private Sub Hit8()
    Target8.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target8.Visible = False

    End Sub
    Private Sub Target9_Click()
    boolStopPressed = True
    DoEvents
    Hit9
    End Sub
    Private Sub Hit9()
    Target9.BackColor = &HFF&
    sngendtime = DateTime.Timer + 1
    ScoreBox.Text = ScoreBox.Text + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    Target9.Visible = False

    End Sub

    '---------- game over screen ------------'


    '--------- Timer Code ----------'


    Private Sub TimeBox_Change()
    sngendtime = DateTime.Timer + 1
    Do While sngendtime > DateTime.Timer
    DoEvents
    Loop
    TimeBox.Value = TimeBox.Value - 1
    DoEvent
    If TimeBox.Value = 0 Then
    GameOverImg.Visible = True
    End If


    End Sub






    please help guys I really want to get my head round this programming
     
    Certifications: A+,MTA:Networking, MTA: Server Fundamentals MTA:Operating Systems MTA:Security Fundamentals ITIL Foundation
  2. supernova

    supernova Gigabyte Poster

    1,422
    21
    80
    Why VBA/Excel? .... is this your homework and you been told to use it to lean some methods in VBA/Excel ?

    Personally I would download and use use VB 2008 express edition (yes its free) that would be far easier to develop a game in.

    I would then take a look at the Timer Control that's probably going to be the easiest method for a beginner.

    Loads of examples on the net just make sure you look at the 2008 examples rather than VB 2005 or VB 6 which are slightly different.
     
    Last edited: Mar 21, 2010
    Certifications: Loads
    WIP: Lots
  3. Timostag

    Timostag Bit Poster

    45
    0
    9
    it has to be using excel in the assignment brief, I think the idea is its suppost to be simple.

    I will download vb 2008 express and have a play on that, it cant do any harm , I want to do well with the asignment but its more imprtant to me to learn how to do programming as I want to do a degree in gaming next year, so the more I can learn the better.

    I've had a look online for timers in vb but when I download I don't know what to do with the files is that because they are for vb 2008 express rather than excel?
     
    Certifications: A+,MTA:Networking, MTA: Server Fundamentals MTA:Operating Systems MTA:Security Fundamentals ITIL Foundation
  4. supernova

    supernova Gigabyte Poster

    1,422
    21
    80
    I thought this was the case. I guess the graphics will be made from coloured cells?

    Excel, In that case you need the OnTime VBA method theres some info below, although you can use windows timers apis.

    http://www.cpearson.com/excel/OnTime.aspx

    Another piece of advice, don't for get you can use the macro recorder to record events then look at the equivalent code to learn what is happening.

    do forget to use google and the VBA help files with office
     
    Last edited: Mar 22, 2010
    Certifications: Loads
    WIP: Lots
  5. supernova

    supernova Gigabyte Poster

    1,422
    21
    80
    Last edited: Mar 22, 2010
    Certifications: Loads
    WIP: Lots

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.