Solved

Odd QBASIC error...

Posted on 2002-07-22
10
833 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
Comment Utility
Have you tried making VALUE a long integer (VALUE&)
0
 
LVL 31

Author Comment

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

/RID
0
 
LVL 31

Author Comment

by:rid
Comment Utility
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
 
LVL 24

Accepted Solution

by:
SunBow earned 150 total points
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 24

Expert Comment

by:SunBow
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
Thanks for finalizing rid !

Nic;o)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
linearIn  challenge 23 65
java constructor error 8 86
strDist challenge 35 84
autoit - check if option is checked in another program 2 65
A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now