Solved

Odd QBASIC error...

Posted on 2002-07-22
10
834 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
parentbit challenge 3 72
Export Table to CSV - Access to CSV - using python 18 94
Device same like our heart 12 73
Modify a small python script 19 94
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
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 …

948 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

18 Experts available now in Live!

Get 1:1 Help Now