Code:
DO
swapcount = 0
FOR i = 1 TO cardcount - 2
IF deqdata(i).cardtype > deqdata(i + 1).cardtype THEN
SWAP deqdata(i).cardtype, deqdata(i + 1).cardtype
SWAP deqdata(i).cardname, deqdata(i + 1).cardname
SWAP deqdata(i).quant, deqdata(i + 1).quant
swapcount = swapcount + 1
END IF
NEXT i
LOOP UNTIL swapcount = 0
something is wrong with this code. when i run it i get an illegal opperation
Quote:The program tried to execute an invalid instruction
Fault location: 3622-2619
Interrupts in service: None
The error was not part of Qbasic.
When i ran a siimple swaping program
Code:
A = 5: B = 7
PRINT A, B
SWAP A, B
PRINT A,B
it works fine
help will be greatly appreciated
edit: Am i not aloud to swap types or arrays?
Could be related to this bug:
Code:
DOCUMENT:Q39379 23-MAY-1989 [B_QUICKBAS]
TITLE :QB.EXE 4.50 "Binding..." then Hang If SWAP User-TYPE Strings
PRODUCT :Microsoft QuickBASIC Compiler
PROD/VER:4.50
OPER/SYS:MS-DOS
KEYWORDS:buglist4.50 SR# S881206-72
Summary:
SWAPping two string variables that are fields of a user-defined type
can display the "Binding..." message and then hang the QuickBASIC
QB.EXE Version 4.50 editor. Hanging does not happen SWAPping
non-user-defined type strings or other types of variables. The hanging
does not occur in programs compiled with BC.EXE Version 4.50, it is
just a QB.EXE editor problem.
Microsoft has confirmed this to be a problem in Version 4.50. We are
researching this problem and will post new information as it becomes
available.
QB.EXE Versions 4.00 and 4.00b do not have this problem.
More Information:
Putting the TYPE variables in either $DYNAMIC or $STATIC arrays still
hangs. If an INTEGER or DOUBLE appears in the record before the string
field that is being swapped, then you can usually warm reboot,
otherwise it usually requires a cold reboot. Other variables such as
floating point or other TYPES do not prevent the cold reboot. Which
String is swapped (1-5) in the following record makes no difference.
Swapping any non-string type of field in a user-defined record does
not hang the computer. Swapping both variable- and fixed-length
strings as single variables (not in record) also does not hang the
computer.
The following code demonstrates the problem:
TYPE rectype
num1 AS INTEGER
string1 AS STRING * 16
string2 AS STRING * 16
string3 AS STRING * 16
string4 AS STRING * 16
string5 AS STRING * 16
END TYPE
DIM var1 AS rectype, var2 AS rectype
var1.string1 = "String1"
var2.string1 = "String2"
SWAP var1.string1, var2.string1
' The QB.EXE environment will freeze up at this SWAP statement.
To work around the problem, use a standard swapping technique with two
variables and a temporary variable:
String is swapped (1-5) in the following record makes no difference.
Swapping any non-string type of field in a user-defined record does
not hang the computer. Swapping both variable- and fixed-length
strings as single variables (not in record) also does not hang the
computer.
The following code demonstrates the problem:
TYPE rectype
num1 AS INTEGER
string1 AS STRING * 16
string2 AS STRING * 16
string3 AS STRING * 16
string4 AS STRING * 16
string5 AS STRING * 16
END TYPE
DIM var1 AS rectype, var2 AS rectype
var1.string1 = "String1"
var2.string1 = "String2"
SWAP var1.string1, var2.string1
' The QB.EXE environment will freeze up at this SWAP statement.
To work around the problem, use a standard swapping technique with two
variables and a temporary variable:
DIM var1 as rectype, var2 as rectype, temp as rectype
temp.string1 = var1.string1 ' 1. a -> temp
var1.string1 = var2.string1 ' 2. b -> a
var2.string1 = temp.string1 ' 3. temp -> b
=============================================================================
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION
OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1994.
ok. thanks. ill use the temporary variable.