dbasnett's Profile User Rating: -----

Reputation: 113 Stalwart
Active Posts:
618 (0.25 per day)
01-October 08
Profile Views:
Last Active:
User is offline Today, 05:34 AM

Previous Fields

Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:

Latest Visitors

Icon   dbasnett has not set their status

Posts I've Made

  1. In Topic: Generate Prime Numbers within inputted bounds using For Loop

    Posted 19 May 2015

    View Postblessingtz, on 19 May 2015 - 10:12 AM, said:

    ...Here is the word-for-word job: "The numbers generated from this function for values of x ranging from 1 to 20 are all prime. Write a program that displays each number generated for values from 1 to 20."

    Any help is greatly appreciated!

    According to this the function should use values from 1-20 inclusive. The result of the function will be greater than or equal to 41 by definition.

    Here it is in code:
            For numbers As Integer = 1 To 20
                Debug.WriteLine(((numbers - 1) * numbers) + 41)

    BTW - I factored the formula.
  2. In Topic: Incorrect divide by zero ?

    Posted 5 May 2015

    From Double:
    "Using Floating-Point Numbers

    When performing binary operations, if one of the operands is a Double, then the other operand is required to be an integral type or a floating-point type (Double or Single). Prior to performing the operation, if the other operand is not a Double, it is converted to Double, and the operation is performed using at least Double range and precision. If the operation produces a numeric result, the type of the result is Double.

    The floating-point operators, including the assignment operators, do not throw exceptions. Instead, in exceptional situations the result of a floating-point operation is zero, infinity, or NaN, as described below:
    •If the result of a floating-point operation is too small for the destination format, the result of the operation is zero.

    •If the magnitude of the result of a floating-point operation is too large for the destination format, the result of the operation is PositiveInfinity or NegativeInfinity, as appropriate for the sign of the result.

    •If a floating-point operation is invalid, the result of the operation is NaN.

    •If one or both operands of a floating-point operation are NaN, the result of the operation is NaN."
  3. In Topic: Incorrect divide by zero ?

    Posted 5 May 2015

    View Postdjjeavons, on 05 May 2015 - 06:32 AM, said:

    View Posttargolo, on 05 May 2015 - 04:32 AM, said:

    If you're right, all the other lines should also raise an exception...

    The other statements do not throw an exception as 0 / 0 returns -1.#IND. Whereas, the line:

    Dim c As Decimal = 1
    Console.WriteLine(IIf(b = 0, 0, c / B)/>/>)

    throws the exception because c is 1D and therefore 1D / 0 will throw an exception.

    As mentioned, use a standard If statement.

    I agree. Either use a standard If or use the If Operator. If performance is a concern use the standard If.
  4. In Topic: Finding Date for Next Monday

    Posted 8 Feb 2015

    I made a comment about performance earlier so I create a test to check the three differing versions. Again, performance is only a concern if this function is needed a lot.

    Here is the code used to test:
            Const tries As Integer = 100000
            Dim testdts As New List(Of DateTime) From {#2/1/2015#, #2/2/2015#, #2/3/2015#, #2/4/2015#, #2/5/2015#, #2/6/2015#, #2/7/2015#}
            Dim stpw As New Stopwatch
            For x As Integer = 1 To tries
                For d As Integer = 0 To testdts.Count - 1
                    'uncomment one of the following three Dim statements
                    'Dim nxtMon As DateTime = nextMondayIF(testdts(d))
                    'Dim nxtMon As DateTime = nextMondayOneLine(testdts(d))
                    'Dim nxtMon As DateTime = nextMondayLoop(testdts(d))
                    'for checking results
                    'If x = 1 Then Debug.WriteLine("{0} {1} {2} {3}", d, d.DayOfWeek, nxtMon, nxtMon.DayOfWeek)

    Here are the three next Monday methods:

        Private Function nextMondayIF(d As DateTime) As DateTime
            If d.DayOfWeek >= DayOfWeek.Monday Then 'is it mon - sat?
                Return d.AddDays(8 - d.DayOfWeek)
                Return d.AddDays(1)
            End If
        End Function
        Private Function nextMondayOneLine(d As DateTime) As DateTime
            Return d.AddDays(If(d.DayOfWeek = DayOfWeek.Monday, 7, (7 - d.DayOfWeek + 1) Mod 7))
        End Function
        Private Function nextMondayLoop(d As DateTime) As DateTime
                d = d.AddDays(1)
            Loop Until d.DayOfWeek = DayOfWeek.Monday
            Return d
        End Function

    The simple if and the one liner were close, and the loop took about twice as long as the other two.
  5. In Topic: Finding Date for Next Monday

    Posted 7 Feb 2015

    View Postandrewsw, on 07 February 2015 - 04:30 PM, said:

    It is possible to use DayOfWeek:
    For x As Integer = 0 To 30
    	Dim day = DateTime.Now.AddDays(x)
    	dim mon = day.AddDays((7 - day.DayOfWeek + 1) Mod 7)
    	Debug.Print(day & " " & mon)
    Next x

    This assumes that a Monday will return the same day, not the following Monday.

    So the expression to get the following Monday is:
    Dim mon = day.AddDays((7 - day.DayOfWeek + 1) Mod 7)

    I assumed next Monday was the next Monday even if it was Monday. If on the 9th of this month I told you something was going to happen next Monday I wouldn't mean the 9th. Would you think I did? Of course we don't know what the OP intends.

My Information

Member Title:
D.I.C Addict
Age Unknown
July 29
Years Programming:

Contact Information

Website URL:
Website URL  http://



dbasnett has no profile comments yet. Why not say hello?