You are viewing our Forum Archives. To view or take place in current topics click here.
Is this alright?[VB.Net]
Posted:

Is this alright?[VB.Net]Posted:

Extazc
  • TTG Senior
Status: Offline
Joined: Aug 17, 201113Year Member
Posts: 1,444
Reputation Power: 75
Status: Offline
Joined: Aug 17, 201113Year Member
Posts: 1,444
Reputation Power: 75
i Made this countdown timer and was wondering if there is any excess code ...

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Label1.Text = TextBox1.Text
        Timer1.Interval = 1000
        Me.Name = Label1.Text
    End Sub
    Function countdown()
        Dim counting As Integer
        Dim i As Integer
        i = 1
        counting = (Label1.Text - i)
        Label1.Text = counting
        Return Label1.Text
    End Function
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        countdown()
        If Label1.Text = 0 Then
            MessageBox.Show("All Done", "Stopwatch", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Timer1.Stop()
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "Hello"
    End Sub
End Class


Last edited by Extazc ; edited 1 time in total
#2. Posted:
dazza2012
  • New Member
Status: Offline
Joined: Jan 28, 201212Year Member
Posts: 9
Reputation Power: 0
Status: Offline
Joined: Jan 28, 201212Year Member
Posts: 9
Reputation Power: 0
Your link seems to be down, just post the code here.
#3. Posted:
Minato-Krunch
  • TTG Addict
Status: Offline
Joined: Jun 20, 201014Year Member
Posts: 2,704
Reputation Power: 111
Status: Offline
Joined: Jun 20, 201014Year Member
Posts: 2,704
Reputation Power: 111
when posting the link, make a space between the url

because this just links you to a none created account here in ttg
#4. Posted:
RDCA
  • TTG Contender
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
Status: Offline
Joined: Jul 12, 201014Year Member
Posts: 3,612
Reputation Power: 173
Nothing wasn't needed, but there was room for shortening, which I did below.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Label1.Text = TextBox1.Text
        Timer1.Interval = 1000
        Me.Name = Label1.Text
    End Sub
    Function countdown()
         Label1.Text -= 1
        Label1.Text = counting
        Return Label1.Text
    End Function
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        countdown()
        If Label1.Text = 0 Then
            MessageBox.Show("All Done", "Stopwatch", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Timer1.Stop()
        End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "Hello"
    End Sub
End Class
#5. Posted:
Extazc
  • TTG Senior
Status: Offline
Joined: Aug 17, 201113Year Member
Posts: 1,444
Reputation Power: 75
Status: Offline
Joined: Aug 17, 201113Year Member
Posts: 1,444
Reputation Power: 75
RDCA wrote Nothing wasn't needed, but there was room for shortening, which I did below.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Label1.Text = TextBox1.Text
        Timer1.Interval = 1000
        Me.Name = Label1.Text
    End Sub
    Function countdown()
         Label1.Text -= 1
        Label1.Text = counting
        Return Label1.Text
    End Function
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        countdown()
        If Label1.Text = 0 Then
            MessageBox.Show("All Done", "Stopwatch", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Timer1.Stop()
        End If
    End Sub
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "Hello"
    End Sub
End Class


ok nice thanks for that i just compared them and its only like 2 lines
#6. Posted:
Z61
  • TTG Fanatic
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Only thing I see is over done, is that you have your interval written out when you can just do it in the designer. (All I did was a quick skim.)
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.