Timers

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Timers

Post by Patrickh »

Ok, so I have an internal timer that displays a messagebox in a certain amount of time. How might I display the remaining time in a labelbox (i want it to count down)? Thanks.

Oh, and here's a seperate problem:
Okay, so I loaded all the possible fonts on windows into a combobox, using the following code

Code: Select all

Dim t As New System.Drawing.Text.InstalledFontCollection

        For Each f As FontFamily In t.Families
            ComboBox2.Items.Add(f.Name)
        Next
now how do I make it so that when you select one, it changes the font property of TextBox1.Text to the selected font?

thanks for any help
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Post by LuxuriousMeat »

Heres a example:
And you need to do this:
-Add a timer.
-Make your timers interval to 1000 (it's in milliseconds (1000 milliseconds = 1 second))

Code: Select all

Public Class Form1
    Dim count As Integer = 30
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Not count = 0 Then
            Label1.Text = count
            count -= 1
        Else
            Timer1.Stop()
            MsgBox("Times up!")
        End If
    End Sub
End Class
Image
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

That works, thanks, but I need it to work in minutes, for example:
5:00
4:59
4:58
etc.
Is there a trick for that?
User avatar
[cc]z@nd!




Literarian 500

Posts: 2297
Joined: Tue May 04, 2004 1:52 pm
Location: michigan

Post by [cc]z@nd! »

maybe use two integers? one from 59 to 0, then when it gets negative, it's re-initialized to 59. then the other, for minutes, maybe on a different timer, from whatever number under 60 to 0, like the minutes.
ASPARTAME: in your diet soda and artificial sweeteners. also, it's obviously completely safe. it's not like it will cause tumors or anything. >.>
always remember: guilty until proven innocent
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

[cc]z@nd! wrote:maybe use two integers? one from 59 to 0, then when it gets negative, it's re-initialized to 59. then the other, for minutes, maybe on a different timer, from whatever number under 60 to 0, like the minutes.
That sounds way too complicated, I made it so you type 5 in the textbox and it will count down for 5 five minutes. The only problem is that it counts down from 300. There's probably a simple conversion trick, but I'm not familiar with it. [cc]z@nd!, I'm sure that would work, but I'm going to search for a simpler method before I resort to that.
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

I'll post some timer code from a C# program that I made, you should be able to convert it to VB.net, but if you need to I'll help.

Code: Select all

private void timer1_Tick(object sender, EventArgs e)
        {
            _seconds--;
            Time.Text = GetTime(_seconds); 'Time.Text is the labels text
            ' GetTime returns a string
            if (seconds < 1) // 0 or less
            {
               'do what you want, I assume stop the timer and reset
            }
        }

        private string GetTime(int seconds) // a function that returns a string
        {
            int s = seconds % 60; 'use mod instead of % in vb(get's the remainder of the division)
            int m = seconds / 60;
            string sec = "";
            string min = "";
            if( s < 10 )
            {
                sec = "0";
            }
            if( m < 10 )
            {
                min = "0";
            }
            sec += s.ToString();
            min += m.ToString();
            return min & ":" & sec
        }
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post by Prey »

Or just

Code: Select all

        // Hour: 3600, Minute: 60, Second: 1
        int time = 7200;

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (--time <= 0)
            {
                time = 0;
                timer1.Enabled = false;
            }

            label1.Text = string.Format("{0}:{1}:{2}", 
                (time / 3600).ToString("00"),
                ((time % 3600) / 60).ToString("00"), 
                ((time % 3600) % 60).ToString("00"));
        }
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

I used string.format in my code, but i didn't know if vb.net had that, so i changed some of my code around, notice the &'s in there.
Post Reply