|
| 07 Nov 2011 04:24 PM |
I'm making this program that times me on how long I use the computer. When I enter my time into the correct TextBox and click the button to start my time, the form just freezes. Why is this happening? Here is my code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Class Form1 Private word As String Private defTime As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click word = "cows" defTime = 0.1 * 60000 Button1.Text = "Time Started" Threading.Thread.Sleep(1000) Button1.Text = "Start Time" Threading.Thread.Sleep(Minutes.Text * 60000) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False Threading.Thread.Sleep(500) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If wrd.Text = word Then Threading.Thread.Sleep(defTime) Label2.Text = "EXTRA TIME IS UP!!" Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False Threading.Thread.Sleep(500) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False End If End Sub End Class |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 04:49 PM |
First of all, don't name your stuff its class name then a number. That is one of the best ways to become unorganized in large projects, and I learned that the hard way.
Second, you need to use Dim to declare a local variable. For example:
word = "cows" defTime = 0.1 * 60000
should be:
Dim word = "cows" Dim defTime = 0.1 * 60000 |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 05:07 PM |
| Ok, cool. I only made it like that because I googled how to use variables :3 |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 05:38 PM |
Ok, here's new script;
Public Class Form1 Dim word = "cows" Dim defTime = 0.1 * 60000 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Text = "Time Started" Threading.Thread.Sleep(1000) Button1.Text = "Start Time" Threading.Thread.Sleep(Minutes.Text * 60000) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False Threading.Thread.Sleep(500) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If wrd.Text = word Then Threading.Thread.Sleep(defTime) Label2.Text = "EXTRA TIME IS UP!!" Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False Threading.Thread.Sleep(500) Label2.Visible = True Threading.Thread.Sleep(500) Label2.Visible = False End If End Sub End Class |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
| |
|
|
| 07 Nov 2011 06:04 PM |
Does it have to be?
~Death to lazy builders. Remove the CFrame tools. Command bar all the way. -pauljkl |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 06:05 PM |
@DX
I am implying you have not read the first 14 characters of the title. |
|
|
| Report Abuse |
|
|
| |
|
rotototo
|
  |
| Joined: 14 Sep 2008 |
| Total Posts: 2390 |
|
|
| 07 Nov 2011 06:28 PM |
Well done I suppose.
I'm taking a class on VB, but I'm not THAT advanced! |
|
|
| Report Abuse |
|
|
|
| 07 Nov 2011 06:29 PM |
| It's always been a wonder why people post on threads just to state things that nobody care about. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 07 Nov 2011 07:59 PM |
| What's wrong with the new script? |
|
|
| Report Abuse |
|
|