|
-
Apr 4th, 2007, 05:21 AM
#1
Thread Starter
Don't Panic!
[RESOLVED] [2005] Getting date/time difference
Hi,
Trying out VB.Net 2005 (the free one).
Coming from VBA/VB6 environment, things are slightly skewed.
Can someone please tell me where I am going wrong with the following code?
Code:
Private Sub btnTry1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTry1.Click
' prime numbers - to be divisable only by themselves and 1
Dim lngLoop As Long, lngMax As Long, lngInnerLoop As Long
Dim blnPrime As Boolean
Dim dblPerc As Double
Dim dteS As Date, dteCalc As Date
If txtMax.Text.Length = 0 Then txtMax.Text = "100"
If CLng(txtMax.Text) > 2000000 Then txtMax.Text = "2000000"
lngMax = CLng(txtMax.Text)
dteS = Now
Me.Cursor = Cursors.WaitCursor
For lngLoop = 1 To lngMax
blnPrime = True
If chkVisual.CheckState = CheckState.Checked Then
dblPerc = CDbl(lngLoop) / CDbl(lngMax)
pbarOuter.Value = dblPerc * 100
lblPBar2.Text = Format(dblPerc, "#0%")
End If
If lngLoop > 2 Then
For lngInnerLoop = 2 To (lngLoop - 1)
If chkVisual.CheckState = CheckState.Checked Then
dblPerc = CDbl(lngInnerLoop) / CDbl(lngLoop)
pbarInner.Value = dblPerc * 100
lblPbar1.Text = Format(dblPerc, "#0%")
'Debug.Print(Format(dblPerc, "#0%"))
End If
If lngLoop Mod lngInnerLoop = 0 Then
blnPrime = False
Exit For
End If
Next
End If
'---- add to list
If blnPrime Then
lstPrimes.Items.Add(lngLoop.ToString)
End If
If chkVisual.CheckState = CheckState.Checked Then
lblPbar1.Refresh()
lblPBar2.Refresh()
'Me.Refresh()
End If
Next
pbarInner.Value = 0
pbarOuter.Value = 0
lblPbar1.Text = ""
lblPBar2.Text = ""
lblPbar1.Refresh()
lblPBar2.Refresh()
'---- \\// \\// \\//
'dtecalc = now - dtes
'lblTimeTaken.Text = "Time Taken : " & dteCalc.Hour & ":" & dteCalc.Minute & ":" & dteCalc.Second & "::" & dteCalc.Ticks
'---- //\\ //\\
Me.Cursor = Cursors.Arrow
End Sub
The bit just above... plus any other immediate problems.
I am self taught / from book so I know I have made loads of mistakes...
Thanks in advance
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Apr 4th, 2007, 05:30 AM
#2
Re: [2005] Getting date/time difference
You have to use. Date.Now
ALternatively you can use the TimeSpan
vb Code:
Dim dateDif As New TimeSpan
Dim startDate As Date = Date.Now
'Loops and other code
dateDif = Date.Now - startDate
MessageBox.Show(dateDif.Milliseconds.ToString)
-
Apr 5th, 2007, 03:33 AM
#3
Thread Starter
Don't Panic!
Re: [2005] Getting date/time difference
Thanks
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|