Solved

Odd QBASIC error...

Posted on 2002-07-22
10
839 Views
Last Modified: 2010-05-18
I'd really like to get some suggestions about this:

I wrote a small data acquisition program. The setup involves a 16-bit A/D converter card and a 3-axis geophone. The program gets the values from the 3 active channels, plots 3 curves and stores the values in a file in a comma-delimited text format. I used Z-Basic for this, a real oldie (end of the 80's) and it works quite OK. I figured QBASIC could give better graphics, so I adjusted the program for QB (a few small adjustments). One thing will not work:

ZBASIC
VALUE = INP(&H225)*256 + INP(&H224)
This gets the 16 bit output fromt he card for further handling.

QBASIC
VALUE = (INP(&H225)*256) + INP(&H224)
This gives an "Overflow" error. Syntax adjustments (moving or deleting parenthesis) does not help. If I read only the low byte ( INP(&H224) ) it works, but the function is crippled.

This line works (no Overflow), but with odd behaviour:
VALUE = (INP(&H225)*256 AND &HF) + INP(&H224)
... and I cannot understand why.


Any input would be appreciated. I am not an experienced programmer - I just follow the manual - so don't hesitate to point out the obvious!

Cheers
/RID
0
Comment
Question by:rid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 20

Expert Comment

by:hes
ID: 7170209
Have you tried making VALUE a long integer (VALUE&)
0
 
LVL 31

Author Comment

by:rid
ID: 7170547
Project is resting presently (nighttime here), but I'll check this and get back here forthwith.

/RID
0
 
LVL 31

Author Comment

by:rid
ID: 7171058
It doesn't work. It's not like the value is beyond limits, but the program errors out as soon as the line is read, highlighting the variable name and saying "Overflow".

Regards
/RID
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Accepted Solution

by:
SunBow earned 150 total points
ID: 7178076
done?
Without doing math or numbers or logic, since this may be over already, I suspect a something beyond limits anyway (if only presumed).

Another workaround to save on development time is to segregate the two operands where the overflow occurs. You know, make more variables, then add them together. You may later need to revisit this for speed in real time system, but it should resolve the error.

Also, since error is on the *256 operation, (a magic number) there could be a number of other workarounds. Maybe swapping operands (order) as well, if this is done Polish in one language and not in other.

Used to be that shifting the bits would help increase the speed
0
 
LVL 31

Author Comment

by:rid
ID: 7178306
I'll try the thing about breaking it down and creating more variables. It'll take a few days to get back with this, but I hope for your patient approach.

Regards
/RID
0
 
LVL 24

Expert Comment

by:SunBow
ID: 7178968
I'm not sure I could add much, assuming you know what I refer to. But another thought is that this is a problem very similar to handling of IP addresses, in terms of succeeding with hex conversions, decimal, and overflows. In that there may be similar treatments to problem searching handlers for that. Overflow can happen on RHS of equation without examining LHS due to nature of compiler in both assumptions made and in whether math goes left to right or from right to left (which is why adding more and more parens don't help resolve)

I am certain that you can resolve on own with variables now. But another issue that could crop is speed, since the variables will likely slow it down, ever so little, but you want real time access (fast) as well as drawing of graphs (slower, slower). While this ought to work out, its handling may maintain interest.
0
 
LVL 31

Author Comment

by:rid
ID: 7179402
Valid comments, thank you.

As I don't need sample rate higher than 100S/s, I think it should work out OK, even with more variables/steps. As soon as I get access to the machine I'll try it out and get back here.

/RID
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7515263

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
 - Answered by: Hes (50) rid (50) SunBow (50)
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 31

Author Comment

by:rid
ID: 7515312
Sorry... forgot all bout this. Making several variables was a working solution. However, the problem seems to be machine-specific (original prog works on one machine, not on another) so I was submerged in trial runs and forgot about closing the Q.

Cheers
/RID
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7515328
Thanks for finalizing rid !

Nic;o)
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question