Solved

Odd QBASIC error...

Posted on 2002-07-22
10
838 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

This is an explanation of a simple data model to help parse a JSON feed
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

790 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