Home  |  Index  |  Dotnet4all Snippets  |  Submit resources
About  |  Mail us  
Dotnet4all Logo

  VERY weird variable behavior (Tuesday, December 21, 2004)




Found the following interesting discussion in the Newsgroups:

VERY weird variable behavior
by:petdoc

Hi Folks,

I am trying to find the most perplexing bug I have had in a vb.net app to
date.

Here is some code:

Dim Data as Short

Data = Me.ReadPMAPDigits(pmOffsets.APIAS)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": Raw IAS: " &
Data.ToString, "Data")

'Mask off everything but lowest 10 bits - we only need values below 511 and
no negative values
Data = Data And CShort(&H3FF)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": IAS: " &
Data.ToString, "Masked Data")

'Trap outliers
If Data > CShort(511) Then
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": E-IAS: " &
Data.ToString, "Error")
Me.GlobalErrorCount += 1
Exit Function
End If

The function this code comes from resides in a "super loop" (called via
nonthreaded delegate invocation every 60ms), reads airspeed from a flight
simulator (via interprocess communication) and returns a short value that
typically is in the range of 0-400 and for the following data was fixed at
120. Here is a snippet of logged data that repeated for about 5 minutes:

Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120

So far so good. But then...

Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072
Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072

Now can somebody tell me 1) How can the variable "Data" change from the 2nd
Trace.writeline to the third Trace.writeline (all I did was compare it to a
constant in between) *and* 2)How it got stuffed with decimal 131,072 - a
value too large to be represented by a short???? How might I stop this?

Help! I'm losing my mind over this and even with error trapping it's
ruining my program.

Scott




 Reply:
by:petdoc

 Turns out I *had* solved the bug - in THIS function. Unfortunately a
similar function that checked a different source for airspeed *also* had an
error trace identical to the one in question - and it was *that* function
that was generating the "ghost" error.

<blush> Sorry!

Scott








0 Comments:

Post a Comment

 
Previous Posts
    - non-shared member of a class
    - Visual Studio Hangs when New Project invoked
    - Expandable Menus
    - Having problems using the GetProcesses from a remo...
    - CheckedListBox
    - Datagrid delete problem
    - Distributed application programming
    - content files
    - A little overwhelmed with the number of options......
    - VB.Net Windows App Data Grid

Archives
    - 10/03/2004 - 10/10/2004
    - 10/10/2004 - 10/17/2004
    - 10/17/2004 - 10/24/2004
    - 10/24/2004 - 10/31/2004
    - 10/31/2004 - 11/07/2004
    - 11/21/2004 - 11/28/2004
    - 11/28/2004 - 12/05/2004
    - 12/05/2004 - 12/12/2004
    - 12/12/2004 - 12/19/2004
    - 12/19/2004 - 12/26/2004
    - 12/26/2004 - 01/02/2005
    - 01/23/2005 - 01/30/2005
    - 01/01/2006 - 01/08/2006
    - 09/24/2006 - 10/01/2006

Disclaimer & Terms of Use  | DotNet4All.Com concept & © 2004 - 2007 by  Zelders²  - Holland