truly weird function behaviour
truly weird function behaviour
truly weird function behaviour
truly weird function behaviour
truly weird function behaviour
truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour
truly weird function behaviour truly weird function behaviour
truly weird function behaviour
Go Back  Xtreme Visual Basic Talk > > > truly weird function behaviour


Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2018, 01:11 PM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 310
Default truly weird function behaviour


Just been writing a function that calculates Julian Dates (it's a format used in certain areas of astronomy, think 'star date'!). OK, at the moment it's not behaving terribly well - but that may not be the problem...
What is weird is that when I pass values to the function like so: (in the form)
Code:
Dim fjd As Double
        fjd = Julian(txtYear.Text, txtMonth.Text, txtDay.Text)
and then look at the values in the function in debug mode: (in the module)
Code:
 Julian(theyear As Short, themonth As Short, theday As Short) As Double
        Dim a As Short, b As Short
        a = Fix(theyear / 100)
        b = 2 - a + Fix(a / 4)
        If themonth > 2 Then
            'do nothing
        Else
            theyear = theyear - 1
            themonth = themonth + 2

        End If
I get the wrong values!
On the form, the first value is 2018, the second is 1 and the third is 2 (i.e., todays date, 2018 Jan 2) BUT 'theyear' in the function says 2017 and 'themonth' says 3. Looking farther down the function, these are indeed what those values WILL have when they reach the if statement - but they haven't yet got that far!
The function is returning a wildly incorrect value, so is this why? Or has the function found a way to travel into the future? ;-)
Reply With Quote
  #2  
Old 01-02-2018, 07:14 PM
Kluz's Avatar
Kluztruly weird function behaviour Kluz is offline
Sapience.Aquire

Super Moderator
* Expert *
 
Join Date: Oct 2003
Location: Lake Bluff, Ill., U.S.
Posts: 3,466
Default

Since you aren't manipulating themonth argument at all in your code, something definitely weird is up. Set a break point at the "a = ..." line and determine that your arguments are being passed correctly.
__________________
No the other right mouse click
Reply With Quote
  #3  
Old 01-03-2018, 05:56 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 310
Default

Glad you agree Kluz - thought I was doing something wrong. Your suggestion was one of the things I did, which is how I discovered the problem. The 'wrong' values were actually right at the top, inside the function header, newly sent by the function call!

However... I did notice one thing. In the body of the function (in the else clause) it should actually say 'themonth = themonth + 12" (not 2). Probably a weak key on the KB. Changed that and everything is now proper and accurate - though I still can't explain the other weird behaviour!
Reply With Quote
Reply

Tags
function, themonth, short, values, theyear, form, double, fjd, dim, date, weird, i.e, todays, wrong, jan, found, future, travel, statement, reach, incorrect, farther, returning, wildly, juliantheyear


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
truly weird function behaviour
truly weird function behaviour
truly weird function behaviour truly weird function behaviour
truly weird function behaviour
truly weird function behaviour
truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour truly weird function behaviour
truly weird function behaviour
truly weird function behaviour
 
truly weird function behaviour
truly weird function behaviour
 
-->