Temporary Forum Oddities
#71
When I use the IDE to Export As... Forum codebox (to clipboard) I get prettier code (see below), but still the unaligned text.

Code: (Select All)

TYPE StarType '              definition of a star
    x AS INTEGER '            x coordinate
    y AS INTEGER '            y coordinate
END TYPE

DIM Star(100) AS StarType '  star array      (LOCAL to the main program level)
DIM s AS INTEGER '            generic counter  (LOCAL to the main program level)
DIM ScreenWidth AS INTEGER '  width of screen  (LOCAL to the main program level)
DIM ScreenHeight AS INTEGER ' height of screen (LOCAL to the main program level)

RANDOMIZE TIMER '            seed random number generator
ScreenWidth = 640 '          set screen width
ScreenHeight = 480 '          set screen height

'-----------------------------------------------------------------------------------
' A subroutine using GOSUB and a local array
GOSUB PopulateStars
PRINT UBOUND(Star); "stars created (array LOCAL at main program level using GOSUB)"
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A subroutine using SUB and an array passed by reference
Populate_Stars Star()
PRINT UBOUND(Star); "stars created (array passed by reference into SUB)"
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A subroutine using SUB and an array that has been SHARED
Populate__Stars
PRINT UBOUND(Star); "stars created (array SHARED in SUB)"
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A function using FUNCTION and an array passed by reference
PRINT Populate_and_count_Stars(Star()); "stars created (array passed by reference into FUNCTION)"
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A function using FUNCTION and an array that has been SHARED
PRINT Populate_and_count_Stars2; "stars created (array SHARED in FUNCTION)"
'-----------------------------------------------------------------------------------

END


'-----------------------------------------------------------------------------------
' Everything LOCAL to the main program level
'-----------------------------------------------------------------------------------
PopulateStars: ' subroutine to populate Star() array

FOR s = 1 TO UBOUND(Star) '                cycle through array
    Star(s).x = INT(RND * ScreenWidth) '  create random star coordinates
    Star(s).y = INT(RND * ScreenHeight)
NEXT s

RETURN '                                  return to next command statement
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' An array passed into a subroutine by reference
'-----------------------------------------------------------------------------------
SUB Populate_Stars (Array() AS StarType)

    ' Any changes in Array() will be passed back to Star()
    ' Star() has been passed 'by reference' into Array()

    SHARED ScreenWidth AS INTEGER '  share the variable from main program level
    SHARED ScreenHeight AS INTEGER ' share the variable from main program level
    DIM s AS INTEGER '              generic counter (LOCAL to this subroutine)

    FOR s = 1 TO UBOUND(Array) '              cycle through array
        Array(s).x = INT(RND * ScreenWidth) ' create random star coordinates
        Array(s).y = INT(RND * ScreenHeight)
    NEXT s

END SUB '                                    return to next command statement
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A SHARED array from the main program level
'-----------------------------------------------------------------------------------
SUB Populate__Stars ()

    ' Any changes in Star() will be saved when subroutine exits

    SHARED ScreenWidth AS INTEGER '  share the variable from main program level
    SHARED ScreenHeight AS INTEGER ' share the variable from main program level
    SHARED Star() AS StarType '      share the array from the main program level
    DIM s AS INTEGER '              generic counter (LOCAL to this subroutine)

    FOR s = 1 TO UBOUND(Star) '              cycle through array
        Star(s).x = INT(RND * ScreenWidth) ' create random star coordinates
        Star(s).y = INT(RND * ScreenHeight)
    NEXT s

END SUB '                                    return to the next command statement
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' An array passed into a function by reference
'-----------------------------------------------------------------------------------
FUNCTION Populate_and_count_Stars (Array() AS StarType)

    ' Any changes in Array() will be passed back to Star()
    ' Star() has been passed 'by reference' into Array()

    SHARED ScreenWidth AS INTEGER '  share the variable from main program level
    SHARED ScreenHeight AS INTEGER ' share the variable from main program level
    DIM s AS INTEGER '              generic counter (LOCAL to this subroutine)

    FOR s = 1 TO UBOUND(Array) '              cycle through array
        Array(s).x = INT(RND * ScreenWidth) '  create random star coordinates
        Array(s).y = INT(RND * ScreenHeight)
    NEXT s
    Populate_and_count_Stars = UBOUND(Array) ' return size of the array passed in

END FUNCTION '                                return to the next command statement
'-----------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------
' A SHARED array from the main program level
'-----------------------------------------------------------------------------------
FUNCTION Populate_and_count_Stars2 ()

    ' Any changes in Star() will be saved when function exits

    SHARED ScreenWidth AS INTEGER '  share the variable from main program level
    SHARED ScreenHeight AS INTEGER ' share the variable from main program level
    SHARED Star() AS StarType '      share the array from the main program level
    DIM s AS INTEGER '              generic counter (LOCAL to this subroutine)

    FOR s = 1 TO UBOUND(Star) '                cycle through array
        Star(s).x = INT(RND * ScreenWidth) '  create random star coordinates
        Star(s).y = INT(RND * ScreenHeight)
    NEXT s
    Populate_and_count_Stars2 = UBOUND(Star) ' return size of the array passed in

END FUNCTION '                                return to the next command statement
'-----------------------------------------------------------------------------------
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply


Messages In This Thread
Temporary Forum Oddities - by admin - 06-04-2023, 05:04 AM
RE: Temporary Forum Oddities - by grymmjack - 06-04-2023, 05:21 AM
RE: Temporary Forum Oddities - by TerryRitchie - 06-04-2023, 02:19 PM
RE: Temporary Forum Oddities - by bplus - 06-04-2023, 03:23 PM
RE: Temporary Forum Oddities - by bplus - 06-04-2023, 03:56 PM
RE: Temporary Forum Oddities - by bplus - 06-04-2023, 04:05 PM
RE: Temporary Forum Oddities - by grymmjack - 06-04-2023, 04:31 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-04-2023, 05:15 PM
RE: Temporary Forum Oddities - by bplus - 06-04-2023, 09:55 PM
RE: Temporary Forum Oddities - by bplus - 06-04-2023, 10:27 PM
RE: Temporary Forum Oddities - by grymmjack - 06-05-2023, 12:22 AM
RE: Temporary Forum Oddities - by bplus - 06-05-2023, 04:48 PM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-05-2023, 08:28 PM
RE: Temporary Forum Oddities - by bplus - 06-05-2023, 09:06 PM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-06-2023, 12:00 AM
RE: Temporary Forum Oddities - by SMcNeill - 06-06-2023, 12:10 AM
RE: Temporary Forum Oddities - by SMcNeill - 06-05-2023, 09:10 PM
RE: Temporary Forum Oddities - by grymmjack - 06-06-2023, 12:03 AM
RE: Temporary Forum Oddities - by TerryRitchie - 06-06-2023, 02:07 AM
RE: Temporary Forum Oddities - by grymmjack - 06-06-2023, 12:59 PM
RE: Temporary Forum Oddities - by bplus - 06-06-2023, 12:44 AM
RE: Temporary Forum Oddities - by SMcNeill - 06-06-2023, 05:07 PM
RE: Temporary Forum Oddities - by grymmjack - 06-08-2023, 10:08 PM
RE: Temporary Forum Oddities - by grymmjack - 06-08-2023, 10:06 PM
RE: Temporary Forum Oddities - by bplus - 06-09-2023, 01:11 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-09-2023, 01:40 PM
RE: Temporary Forum Oddities - by bplus - 06-09-2023, 04:33 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-09-2023, 05:01 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-10-2023, 06:39 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-10-2023, 06:49 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-10-2023, 07:02 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-10-2023, 06:57 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-10-2023, 07:14 PM
RE: Temporary Forum Oddities - by grymmjack - 06-10-2023, 07:43 PM
RE: Temporary Forum Oddities - by grymmjack - 06-10-2023, 08:23 PM
RE: Temporary Forum Oddities - by grymmjack - 06-10-2023, 08:25 PM
RE: Temporary Forum Oddities - by grymmjack - 06-10-2023, 08:26 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-10-2023, 08:45 PM
RE: Temporary Forum Oddities - by bplus - 06-10-2023, 09:22 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-10-2023, 09:30 PM
RE: Temporary Forum Oddities - by bplus - 06-10-2023, 09:32 PM
RE: Temporary Forum Oddities - by bplus - 06-10-2023, 09:53 PM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-10-2023, 10:29 PM
RE: Temporary Forum Oddities - by Kernelpanic - 06-11-2023, 11:36 AM
RE: Temporary Forum Oddities - by SMcNeill - 06-11-2023, 11:41 AM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-11-2023, 04:54 PM
RE: Temporary Forum Oddities - by grymmjack - 06-17-2023, 01:46 PM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-23-2023, 01:03 AM
RE: Temporary Forum Oddities - by grymmjack - 06-11-2023, 02:40 PM
RE: Temporary Forum Oddities - by grymmjack - 06-11-2023, 02:51 PM
RE: Temporary Forum Oddities - by bplus - 06-11-2023, 03:11 PM
RE: Temporary Forum Oddities - by grymmjack - 06-11-2023, 03:29 PM
RE: Temporary Forum Oddities - by grymmjack - 06-11-2023, 03:26 PM
RE: Temporary Forum Oddities - by bplus - 06-11-2023, 03:26 PM
RE: Temporary Forum Oddities - by grymmjack - 06-11-2023, 03:49 PM
RE: Temporary Forum Oddities - by bplus - 06-11-2023, 03:40 PM
RE: Temporary Forum Oddities - by bplus - 06-11-2023, 04:40 PM
RE: Temporary Forum Oddities - by Kernelpanic - 06-11-2023, 04:57 PM
RE: Temporary Forum Oddities - by grymmjack - 06-12-2023, 12:35 AM
RE: Temporary Forum Oddities - by grymmjack - 06-13-2023, 12:24 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-13-2023, 01:09 PM
RE: Temporary Forum Oddities - by bplus - 06-13-2023, 03:33 PM
RE: Temporary Forum Oddities - by Kernelpanic - 06-13-2023, 08:04 PM
RE: Temporary Forum Oddities - by SMcNeill - 06-13-2023, 10:03 PM
RE: Temporary Forum Oddities - by grymmjack - 06-17-2023, 01:54 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 01:05 PM
RE: Temporary Forum Oddities - by bplus - 06-22-2023, 02:12 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 03:23 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-22-2023, 02:37 PM
RE: Temporary Forum Oddities - by bplus - 06-22-2023, 03:18 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 03:25 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-22-2023, 04:05 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 03:37 PM
RE: Temporary Forum Oddities - by bplus - 06-22-2023, 03:39 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 03:41 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-22-2023, 05:01 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 11:39 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-23-2023, 06:55 AM
RE: Temporary Forum Oddities - by TerryRitchie - 06-23-2023, 01:41 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-23-2023, 04:13 PM
RE: Temporary Forum Oddities - by bplus - 06-22-2023, 03:44 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-22-2023, 03:49 PM
RE: Temporary Forum Oddities - by bplus - 06-22-2023, 05:40 PM
RE: Temporary Forum Oddities - by grymmjack - 06-24-2023, 02:53 PM
RE: Temporary Forum Oddities - by bplus - 06-24-2023, 03:17 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-24-2023, 07:34 PM
RE: Temporary Forum Oddities - by bplus - 06-24-2023, 09:29 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-24-2023, 10:02 PM
RE: Temporary Forum Oddities - by TerryRitchie - 06-24-2023, 04:45 PM
RE: Temporary Forum Oddities - by RhoSigma - 06-24-2023, 07:32 PM
RE: Temporary Forum Oddities - by bplus - 06-25-2023, 01:29 AM
RE: Temporary Forum Oddities - by RhoSigma - 06-25-2023, 07:35 AM
RE: Temporary Forum Oddities - by mnrvovrfc - 06-25-2023, 02:42 AM
RE: Temporary Forum Oddities - by RhoSigma - 06-25-2023, 07:44 AM



Users browsing this thread: 34 Guest(s)