Absolute Beginner and Timer Class

B

Bails

Hi Im an absolute beginner in programming and am using VB.Net Express.

To start my larning I decided to do a "Real World" app instead of
"hello world" and am creating a Poker Countdown clock.

I pretty much have most things under control and have set it up as
follows:

Form 1 Contains a DataGridView where users enter in information
includeing the length of each round, small blind & big blind (its for
Texas Holdem Poker).

This then feeds the round information to Form2 which essential is the
display screen and includes the count down clock.

I can get it to read and run down the clock for the first round, but
am stumped on how I can get it to reset and pick up the infor for the
2nd and subsequant rounds.

I tried putting references back to the Timer1_Tick routine, but I get
an error message that says " argument not specified for parameter 'e'
of Public Sub Timer1_Tick(sender as object, e as System.EventArgs).

I have listed the code (for form2) below and would appreciate any
feedback you can give me.


--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Public Class Form2
'Dim RoundLength As Integer = Form1.RoundLength
Dim RL As Integer = Form1.Round_InformationDataGridView.Item(1,
0).Value
Dim RoundLength As Integer = RL * 600
Dim RoundNumber As Integer = Form1.RoundNumber
Dim SmallBlind As Integer =
Form1.Round_InformationDataGridView.Item(2, 0).Value
Dim BigBlind As Integer =
Form1.Round_InformationDataGridView.Item(3, 0).Value
Dim NextSmall As Integer =
Form1.Round_InformationDataGridView.Item(2, 1).Value
Dim NextBig As Integer =
Form1.Round_InformationDataGridView.Item(3, 1).Value

Private Sub Form2_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Timer1.Enabled = False
Button1.Text = "Start"
Button2.Text = "Pause"
Label1.Text = "0" & RL & ":00"
Label2.Text = "Round " & RoundNumber
Label3.Text = SmallBlind
Label4.Text = BigBlind
Label5.Text = "Next Small Blind " & NextSmall
Label6.Text = "Next Big Blind " & NextBig


End Sub

Private CountDownStart

Private Sub button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

If Not Timer1.Enabled Then

CountDownStart = Microsoft.VisualBasic.DateAndTime.Timer
Timer1.Enabled = True
Button1.Text = "Stop"
Button2.Text = "Pause"
Button2.Enabled = True
Else
Timer1.Enabled = False
'MsgBox("Final Time: " & Label1.Text & vbCrLf & vbCrLf &
"Click OK to reset the clock.")
Label1.Text = "0" & RL & ":00"
Button1.Text = "Start"
Button2.Text = "-----"
Button2.Enabled = False
End If

End Sub
Private Sub Button2_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Static PauseInterval
If Timer1.Enabled Then
PauseInterval = Microsoft.VisualBasic.DateAndTime.Timer -
CountDownStart
Timer1.Enabled = False
Button1.Text = "Restart"
Button2.Text = "Resume"
Else
CountDownStart = Microsoft.VisualBasic.DateAndTime.Timer -
PauseInterval
Timer1.Enabled = True
Button1.Text = "Stop"
Button2.Text = "Pause"
End If
End Sub

Public Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim MinDiff
Dim SecDiff
Dim TenthDiff
Dim TimeDiff
'TimeDiff = (6000) -
Int((Microsoft.VisualBasic.DateAndTime.Timer - CountDownStart) * 10)
TimeDiff = (RoundLength) -
Int((Microsoft.VisualBasic.DateAndTime.Timer - CountDownStart) * 10)
If TimeDiff >= 0 Then
TenthDiff = TimeDiff Mod 10
SecDiff = Int(TimeDiff / 10) Mod 60
MinDiff = Int(TimeDiff / 600)
Label1.Text = Format(MinDiff, "00") & ":" &
Format(SecDiff, "00") '& "." & Format(TenthDiff, "0")

Else
Label1.Text = "00:00"
Timer1.Enabled = False
'MsgBox("!!!TIME!!!")
RoundNumber += 1
Button1.Text = "Start"
Button2.Text = "-----"
Button2.Enabled = False
Timer1_Tick()

End If
Application.DoEvents()
End Sub

End Class

--------------------------------------------------------------------------------------------------------------------------------------------------------------
 
G

Guest

I cant follow where the problem is. What do you mean you cant get it to
"reset". My problem is I dont have form 1 and I cant see what you want to
acheive.

Seems to me the timer1 should fire at the interval you have specified and
then update the label1 with each tick.

You cant easily call a timer sub from vb.net as you have to pass the objects
and the e is a system object of the form System.EventArgs and has the event
info in it so you have to pass that).

Somtimes you can just put "nothing" or an empty object. But if that is what
you want to do then I would make a sub that goes in the timer event sub
called updatetick or something and then call that sub when I want, not the
timer.

Also, be sure to understand what Application.DoEvents does and I always
avoid having this in a timer loop cause you get funny behavior and you cant
step along with the debugger.

Hope this rambling helps point you to something to read about as I cant
understand the problem without spending more time or running in debug.
Someone else smarter prob will soon.

Tom
 
B

Bails

I cant follow where the problem is. What do you mean you cant get it to
"reset". My problem is I dont have form 1 and I cant see what you want to
acheive.

Seems to me the timer1 should fire at the interval you have specified and
then update the label1 with each tick.

You cant easily call a timer sub from vb.net as you have to pass the objects
and the e is a system object of the form System.EventArgs and has the event
info in it so you have to pass that).

Somtimes you can just put "nothing" or an empty object. But if that is what
you want to do then I would make a sub that goes in the timer event sub
called updatetick or something and then call that sub when I want, not the
timer.

Also, be sure to understand what Application.DoEvents does and I always
avoid having this in a timer loop cause you get funny behavior and you cant
step along with the debugger.

Hope this rambling helps point you to something to read about as I cant
understand the problem without spending more time or running in debug.
Someone else smarter prob will soon.

Tom

























- Show quoted text -

Thanks for your fast reply Tom.

Essentially on Form1 I have a datagridview. This has the information
on the various round levels for a Poker Tournament ie

Round Length of Round Small Blind Big Blind
1 10 (minutes) $25 $50
2 8 (minutes) $50 $100

So, I need the display screen (form2) to loop arround the number of
rounds (in this exanple its 2 rounds, however in reality can be any
number say 30 rounds).
So it would start at Round 1 and display the blinds ($25 and $50) once
it had counted down the 10 minutes, it moves down to the next round
(round 2) and starts the timer at 8 minutes and displays the blinds
for Round 2 ($50 and $100) all the way until there are no more
levels(rounds) left.

With the code I posted above I can get it to pickup and display
everything for the first round, then pick up all the info for the next
round, but cant seem to get the timer1_tick routine to start again.

I think you are correct when you say I need to pass it something, the
trouble is I have no idea WHAT to pass it or even HOW to pass it.

I have uploaded the entire project to : www.mediamax.com/ebaypoker if
you want to download it and have a look.

Once again - Thank you for your help.
 
G

Guest

Welp, you have:


I am not seeing how this gets to be zero so the else case where the timer 1
is dis-enabled (and then resets) is never hit? But I gues it does?

And then yes, calling the Timer1_Tick() statement will give you an error
cause your not passing the parameters: ByVal sender As Object, ByVal e As
System.EventArgs. You could maybe do: Call Timer1_Tick(me, nothing) since you
dont use the paramenters.

Tom
 
B

Bails

Welp, you have:


I am not seeing how this gets to be zero so the else case where the timer 1
is dis-enabled (and then resets) is never hit? But I gues it does?

And then yes, calling the Timer1_Tick() statement will give you an error
cause your not passing the parameters: ByVal sender As Object, ByVal e As
System.EventArgs. You could maybe do: Call Timer1_Tick(me, nothing) since you
dont use the paramenters.

Tom

Tom - YOU ARE A GENIUS.

It works Perfectly.

THANKS SO MUCH for your help.

Do you play Poker Yourself - im happy to send you a copy once I get it
running the way I want it too.

Then again, you could probably build one any way.

Either way, let me know and I'll shoot it out to you if you want.

Thanks again

Bails
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top