Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Getting date/time difference

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Resolved [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

    BOFH Now, BOFH Past, Information on duplicates

    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...

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Getting date/time difference

    You have to use. Date.Now

    ALternatively you can use the TimeSpan

    vb Code:
    1. Dim dateDif As New TimeSpan
    2.         Dim startDate As Date = Date.Now
    3.  
    4.         'Loops and other code
    5.  
    6.         dateDif = Date.Now - startDate
    7.  
    8.         MessageBox.Show(dateDif.Milliseconds.ToString)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: [2005] Getting date/time difference

    Thanks

    BOFH Now, BOFH Past, Information on duplicates

    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
  •  



Click Here to Expand Forum to Full Width