Hi guys. Fraid I need a bit of help with some code of mine... actually, it's
a little bit more than my code, it's part of my thesis (Civil eng).
I'm getting a subscript out of range error when I run this at one stage
If you bother to run it, choose enter shape, then from co-ordinates,
and choose any number of points, and you'll see what I mean... it's giving me
the shits and my advisor is no help at all
Any help would be appreciated.
Doug
-=-
Douglas Inwood
BE(Civil), University of Wollongong, Australia
+61 42 215170
"Why, anything:
An honourable {*filter*}er if you will;
For nought I did in hate, but all in honour"
- Shakepeare "Othello"
-=-
'>>>>>>>>>>>>>>>>>>>>> Begin area.bas <<<<<<<<<<<<<<<<<<<<<<<<<<<
DECLARE FUNCTION ixy! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE FUNCTION iyy! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE FUNCTION ixx! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE FUNCTION areaxo! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE FUNCTION areayo! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE FUNCTION small! (x1 AS SINGLE, x2 AS SINGLE)
DECLARE FUNCTION shapearea! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE SUB changeshape ()
DECLARE SUB loadshape (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE SUB intro ()
DECLARE SUB mainmenu (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE SUB shapeinput (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE SUB displayshape ()
DECLARE SUB displayresults ()
DECLARE SUB saveresults ()
DECLARE SUB printresults ()
DECLARE SUB saveprint ()
DECLARE SUB exitprog ()
DECLARE SUB helpmain ()
DECLARE SUB readfile (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DECLARE SUB enterdata (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
'-------------------------------------------------------
' CIVL401 THESIS
' "PC Graphics Analysis of Structural Shapes and Sections"
'
' Douglas Inwood 9256245
' University of Wollongong, Australia
' Department Of Civil and Mining Engineering
' 1996
'-------------------------------------------------------
COMMON SHARED hlp
COMMON SHARED x() AS SINGLE, y() AS SINGLE, code() AS INTEGER
SCREEN 9
CALL intro
mainmenu x(), y(), code()
END
FUNCTION areaxo! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
END FUNCTION
FUNCTION areayo! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
END FUNCTION
SUB changeshape
END SUB
SUB displayresults
END SUB
SUB displayshape
END SUB
SUB enterdata (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
'--------------------------------------------------------------------------
' This is the subroutine that allows the user to enter the data for the
' points, co-ordinate by co-ordinate.
'--------------------------------------------------------------------------
CLS
DIM npoints AS INTEGER, i AS INTEGER
PRINT
PRINT "Please note that the x and y co-ordinates range from the origin"
PRINT "at 0,0 to 100,100. Please ensure that your shape falls within"
PRINT "these ranges."
PRINT : PRINT
PRINT "For each co-ordinate, please enter the data in the form of:": PRINT
PRINT "x,y,code. Code is either 1 for solid, -1 for void."
PRINT "Please enter the total number of vertices (Note: The final"
INPUT "point must be the same as the first point"; npoints
REDIM x(npoints) AS SINGLE, y(npoints) AS SINGLE, code(npoints) AS INTEGER
FOR i = 1 TO npoints
PRINT "Co-ordinate no."; i; ":";
INPUT x(i), y(i), code(i)
10 'check to see whether the co-ordinates fall within the set limits
IF x(i) < 0 OR x(i) > 100 THEN
PRINT "Your x value is not within the program parameters. Please re-enter.";
INPUT x(i)
GOTO 10
END IF
IF y(i) < 0 OR y(i) > 100 THEN
PRINT "Your y value is not within the program parameters. Please re-enter.";
INPUT y(i)
GOTO 10
END IF
IF code(i) <> 1 OR code(i) <> -1 THEN
PRINT "Your code is not recognised. Please re-enter it now.";
INPUT code(i)
GOTO 10
END IF
NEXT i
END SUB
SUB exitprog
END SUB
SUB helpmain
END SUB
SUB intro
'--------------------------------------------------------------------------
' This subroutine is simply the introduction screen for the program
'--------------------------------------------------------------------------
COLOR 15
VIEW SCREEN (1, 2)-(638, 319)
CLS
' Addition of a border around the screen
LINE (1, 2)-(638, 319), 9, B
COLOR 12
LOCATE 5, 25: PRINT "Sectional Analysis Program"
LINE (191, 70)-(400, 70)
'--------------------------------------------------------------------------
'Addition of graphic in center of screen, namely an I-section
'--------------------------------------------------------------------------
DRAW "c11"
DRAW "bl160bd20r100d20l40d80r40d20l100u20r40u80l40u20"
DRAW "bh10"
COLOR 11
LINE (350, 90)-(400, 90)
LINE (350, 210)-(400, 210)
LINE (390, 90)-(390, 210)
LINE (385, 95)-(395, 85)
LINE (385, 215)-(395, 205)
LINE (240, 240)-(340, 240)
LINE (240, 247)-(240, 220)
LINE (340, 247)-(340, 220)
LINE (235, 247)-(245, 237)
LINE (335, 247)-(345, 237)
LOCATE 11, 51: PRINT "H"
LOCATE 19, 37: PRINT "B"
COLOR 15
LOCATE 22, 26: PRINT "Press any key to continue"
con$ = INPUT$(1)
END SUB
FUNCTION ixx! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DIM inertia1 AS SINGLE, inertia2 AS SINGLE, amoment AS SINGLE
DIM tempy AS SINGLE, tempy2 AS SINGLE, i AS INTEGER
FOR i = 1 TO UBOUND(x) - 1
IF code(i) = code(i + 1) THEN
tempy = small(y(i), y(i + 1))
tempy2 = ABS(y(i + 1) - y(i))
inertia1 = (tempy ^ 3 * (x(i) - x(i))) / 12
inertia1 = inertia1 + (tempy * .5) ^ 2 * (tempy * (x(i + 1) - x(i)))
inertia2 = (tempy2 ^ 3 * (x(i + 1) - x(i)) * .5) / 36
inertia2 = inertia2 + (tempy + tempy2 / 3) ^ 2 * (tempy2 * (x(i + 1) - x(i)) * .5)
amoment = amoment + (inerti1 + inertia2) * code(i)
END IF
NEXT i
ixx! = amoment - (shapearea!(x(), y(), code()) * (areayo!(x(), y(), code())) ^ 2)
END FUNCTION
FUNCTION ixy! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
END FUNCTION
FUNCTION iyy! (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
DIM inertia1 AS SINGLE, inertia2 AS SINGLE, amoment AS SINGLE
DIM tempz AS SINGLE, tempz2 AS SINGLE, i AS INTEGER
FOR i = 1 TO UBOUND(x) - 1
IF code(i) = code(i + 1) THEN
tempz = small!(x(i), x(i + 1))
tempz2 = ABS((x(i) + 1 - x(i)))
inertia1 = (tempz ^ 3) * (y(i) - y(i + 1)) / 12
inertia1 = inertia1 + (tempz * .5) ^ 2 * (tempz * (y(i) - y(i + 1)))
inertia2 = (tempz2 ^ 2) * (y(i) - y(i + 1)) / 36
inertia2 = inertia2 + (tempz + tempz2 / 3) ^ 2 * (tempz2 * (y(i) - y(i + 1)) * .5)
amoment = amoment + (inertia1 + inertia2) * code(i)
END IF
NEXT i
iyy! = amoment - (shapearea!(x(), y(), code()) * (areaxo!(x(), y(), code())) ^ 2)
END FUNCTION
SUB loadshape (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
'----------------------------------------------------------------------------
' This subroutine is that which calculates all of the relevant things required
' for the program. It is further broken down into functions for ease of
' viewing/writing of the code. The functions are placed at the start of the
' code, then the relevant results calculated.
'----------------------------------------------------------------------------
DEFINT A-Z
END SUB
SUB mainmenu (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
CLS
LINE (1, 2)-(638, 319), 9, B
hlp = 1
DO WHILE (1)
COLOR 4
LOCATE 5, 27: PRINT "PROGRAM FUNCTION MENU"
LINE (193, 70)-(390, 70)
COLOR 15
LOCATE 7, 25: PRINT "1. INPUT SHAPE FOR ANALYSIS / CHANGE SHAPE"
'--------------------------------------------------------------------------
'The shape properties will be calculated as soon as the shape is fully
'inputed into the program
'--------------------------------------------------------------------------
LOCATE 8, 25: PRINT "2. DISPLAY SHAPE
LOCATE 9, 25: PRINT "3. DISPLAY RESULTS"
LOCATE 10, 25: PRINT "4. SAVE RESULTS
LOCATE 11, 25: PRINT "5. PRINT RESULTS"
LOCATE 12, 25: PRINT "6. SAVE & PRINT RESULTS
LOCATE 13, 25: PRINT "0 TO EXIT"
LOCATE 14, 25: PRINT "9 FOR HELP"
COLOR 11
LOCATE 17, 20: INPUT "Please enter your selection ==>", mainchoice
DO WHILE (mainchoice < 0) OR (mainchoice > 9)
LOCATE 15, 20: INPUT "Please enter your selection ==>", mainchoice
LOOP
SELECT CASE mainchoice
CASE 1
shapeinput x(), y(), code()
CASE 2
CALL displayshape
CASE 3
CALL displayresults
CASE 4
CALL saveresults
CASE 5
CALL printresults
CASE 6
CALL saveprint
CASE 0
CALL exitprog
CASE 9
CALL helpmain
CASE ELSE
END SELECT
LOOP
END SUB
DEFSNG A-Z
SUB perim (x() AS SINGLE, y() AS SINGLE, perimext() AS SINGLE, perimint() AS SINGLE)
DIM i AS INTEGER, area AS SINGLE, area2 AS SINGLE, ndata AS INTEGER
ndata = UBOUND(x)
FOR i = 1 TO ndata - 1
IF code(i) = code(i + 1) THEN
l = SQR((x(i + 1) - x(i)) ^ 2 + (y(i + 1) - y(i)) ^ 2)
IF code(i) = 1 THEN
perimext = permiext + l
END IF
IF code(i) = -1 THEN
perimint = perimint + 1
END IF
END IF
NEXT i
END SUB
DEFINT A-Z
SUB printresults
END SUB
SUB readfile (x() AS SINGLE, y() AS SINGLE, code() AS INTEGER)
CLS
LINE (1, 2)-(638, 319), 9, B
COLOR 15
DIM npoints AS INTEGER, i AS INTEGER, file AS STRING
LOCATE 10, 20: INPUT "Enter the file path and name: "; file
LOCATE 12, 17: PRINT "Please ensure that the .dat file is in the format of"
LOCATE 13, 17: PRINT "x,y,code and that the total number of data points is"
LOCATE 14, 17: PRINT "on the very first line."
LOCATE 16, 17: PRINT "If your file is in the correct format, press return."
LOCATE 17, 17: PRINT "Press any other key to go back."
con$ = INPUT$(1)
IF con$ <> CHR$(13) THEN GOTO 1
OPEN file FOR INPUT AS #1
INPUT #1, npoints
REDIM x(npoints) AS SINGLE, y(npoints) AS SINGLE, code(npoints) AS INTEGER
FOR i
...
read more »