Solved

Odd QBASIC error...

Posted on 2002-07-22
10
840 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

738 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