LINKed or Merged Modules - QB64 Wiki

LINKed or Merged Modules

From QB64 Wiki

Jump to: navigation, search

QB64 does not use LINK.EXE or MERGE to combine program modules as there is not a limit on the size of programs! This utility merges files and converts COMMON SHARED variables to SHARED ones. You will need to remove any other statements NOT supported by QB64 yourself!

It's pretty bare-bones, but so far, I have used it to convert three of my multi-modular programs to a single QB64 files.

It uses the steps outlined in the following thread to make the new file:
See Forum Thread
WARNING: It does CREATE and DELETE files, however, it runs a check first to see if any of those file names exist.

Use at your own risk. I make no statements of warranty as to the usability of this utility and the user accepts full responsibility for any outcome.

If you find bugs, or have other problems, please report them at the QB64 Forum topic above.

Enjoy....

Pete


Compile this program using Qbasic or QB64 with a BAS file name extension.
NOTE: You may wish to add SHELL _HIDE statements if compiling the program with QB64.

'***************************************************************************** '************* ************* '************* QB to QB64 Multi Modular Converter by Pete ************* '************* ************* '************* Copyright 2010 FTC Software. All rights reserved. ************* '************* ************* '***************************************************************************** DECLARE SUB QBIDE () DECLARE SUB help () DECLARE SUB construct (linecountnew%) DECLARE SUB rewrite (cntmak%, linecountorig%, dupshared%) DECLARE SUB keyboard (numofspaces%) DIM SHARED entry$, path$, f5key$ SCREEN 0, 0, 0, 0 CALL QBIDE COLOR 0, 3 prompt$ = " [Enter] Input [F1] Help [F5] Convert .bas files [Y]\[N] [Esc] Quit " LOCATE 25, 41 - LEN(prompt$) \ 2: PRINT prompt$; prompt$ = " QB Multi-Modular to QB64 Converter " COLOR 1, 7 LOCATE 2, 41 - LEN(prompt$) \ 2: PRINT prompt$ VIEW PRINT 4 TO 19 ON ERROR GOTO resnxt OPEN "QB64CONV.DAT" FOR INPUT AS #1 LINE INPUT #1, saveddir$ IF NOT EOF(1) THEN LINE INPUT #1, destpath$ CLOSE #1 ON ERROR GOTO 0 COLOR 7, 1 DO REDIM SHARED makefile$(100), path$(100) LOCATE , , 0 ON ERROR GOTO errhandler RESTORE FOR i = 1 TO 7 READ a$ OPEN a$ FOR INPUT AS #1 CLOSE #1 IF er1% = 0 THEN PRINT prompt$ = "The file " + a$ + " already exists in the current directory." GOSUB printline PRINT PRINT prompt$ = "Please remove, rename, or move this file to continue." GOSUB printline PRINT PRINT prompt$ = "If you would like to view it, press [F12] now." GOSUB printline PRINT PRINT prompt$ = "If you would like to permanently DELETE it, press [Ctrl + [Del] now." GOSUB printline DO key$ = INKEY$ SELECT CASE key$ CASE CHR$(27): COLOR 0, 3: SYSTEM CASE CHR$(0) + CHR$(134): SHELL "cmd /c start notepad qbtoqb64.tmp" END SELECT i = INP(96) IF i = 42 THEN EXIT DO LOOP KILL a$ RUN ELSE er1% = 0 END IF NEXT ON ERROR GOTO errhandler DO LOCATE , , 1, 7, 7 IF holdentry$ <> "" THEN entry$ = holdentry$ holdentry$ = "" rowredo% = CSRLIN: columnredo% = POS(0) - LEN(entry$) ELSE prompt$ = "[Drive:\][Path\][.MAK or Main .BAS]: " IF cntmak% <> 0 THEN prompt$ = "[Drive:\][Path\][.MAK or Next .BAS]: " entry$ = path$ IF saveddir$ <> "" THEN entry$ = saveddir$: saveddir$ = "" GOSUB printline rowredo% = CSRLIN: columnredo% = POS(0) PRINT entry$; END IF f5key$ = "ready": numofspaces% = 79 - POS(0): CALL keyboard(numofspaces%) entry$ = LTRIM$(RTRIM$(entry$)) IF INSTR(LCASE$(entry$), ".mak") <> 0 THEN IF MID$(LCASE$(entry$), LEN(entry$) - 3, 4) = ".mak" THEN OPEN entry$ FOR INPUT AS #1 DO IF er1% <> 0 THEN er1% = 0 prompt$ = " -File Not Found. Retry..." REM alternate new line display to substitute for redomessage. 'printlines% = 2: GOSUB redoborder 'GOSUB printline 'PRINT REM redo line display option GOSUB redomessage flag = 1 EXIT DO END IF DO UNTIL EOF(1) LINE INPUT #1, mak$ IF mak$ <> "" THEN cntmak% = cntmak% + 1 makefile$(cntmak%) = mak$ END IF LOOP CLOSE #1 GOSUB washmain flag = -1 EXIT DO LOOP IF flag = -1 THEN EXIT DO END IF END IF IF INSTR(entry$, ".bas") <> 0 THEN IF MID$(LCASE$(entry$), LEN(entry$) - 3, 4) = ".bas" THEN FOR i = 1 TO cntmak% IF makefile$(i) = MID$(entry$, LEN(path$(i)) + 1) THEN prompt$ = " -This module was already input. Retry..." GOSUB redomessage flag = -1 EXIT FOR END IF NEXT IF flag <> -1 THEN OPEN entry$ FOR INPUT AS #1 CLOSE #1 IF er1% <> 0 THEN SELECT CASE er1% CASE 1 prompt$ = " -File not found. Retry..." CASE 2 prompt$ = " -Path not found. Retry..." CASE 3 prompt$ = " -Bad file name. Redo..." END SELECT er1% = 0 GOSUB redomessage flag = 1 ELSE cntmak% = cntmak% + 1 GOSUB rememberpath makefile$(cntmak%) = MID$(entry$, LEN(path$(cntmak%)) + 1) IF cntmak% = 1 THEN makfilename$ = MID$(makefile$(cntmak%), 1, INSTR(makefile$(cntmak%), ".") - 1) + ".mak" END IF PRINT flag = 1 END IF END IF END IF END IF IF cntmak% > 1 AND f5key$ = "on" THEN OPEN path$ + makfilename$ FOR INPUT AS #1 CLOSE #1 IF er1% = 1 THEN prompt$ = "Would you like to create the .mak file in the source directory? [Y] \ [N] " printlines% = 1: GOSUB redoborder GOSUB printline DO entry$ = "": numofspaces% = 1: CALL keyboard(numofspaces%) entry$ = UCASE$(entry$) IF entry$ = "Y" OR entry$ = "N" THEN EXIT DO LOOP IF entry$ = "Y" THEN OPEN path$ + makfilename$ FOR OUTPUT AS #1 FOR i = 1 TO cntmak% IF path$ = source$ THEN PRINT #1, makefile$(i) ELSE PRINT #1, path$(i) + makefile$(i) END IF NEXT CLOSE #1 END IF ELSE er1% = 0 END IF GOSUB washmain EXIT DO END IF SELECT CASE flag CASE 0 prompt$ = " -Invalid file entry. Redo..." IF INSTR(LCASE$(entry$), ".mak") = 0 OR INSTR(LCASE$(entry$), ".bas") = 0 THEN prompt$ = " -Missing .mak or .bas ext. Redo..." GOSUB redomessage END IF CASE ELSE flag = 0 END SELECT IF CSRLIN > 17 THEN GOSUB redoborder LOOP f5key$ = "" GOSUB rememberpath IF cntmak% <> 0 THEN CALL rewrite(cntmak%, linecountorig%, dupshared%) printlines% = 1: GOSUB redoborder END IF CALL construct(linecountnew%) PRINT LOCATE , 2: PRINT "Lines with code in original file:"; : LOCATE , 50 - LEN(LTRIM$(STR$(linecountorig%))): PRINT linecountorig% GOSUB redoborder LOCATE , 2: PRINT "Less duplicated lines of COMMON SHARED:"; : LOCATE , 50 - LEN(LTRIM$(STR$(dupshared%))): PRINT dupshared% GOSUB redoborder LOCATE , 2: PRINT "Total lines transferred to new program:"; : LOCATE , 50 - LEN(LTRIM$(STR$(linecountorig% - dupshared%))): PRINT linecountorig% - dupshared% GOSUB redoborder LOCATE , 2: PRINT "Lines with code in new file: "; : LOCATE , 50 - LEN(LTRIM$(STR$(linecountnew%))): PRINT linecountnew% GOSUB redoborder PRINT IF linecountorig% - dupshared% = linecountnew% THEN prompt$ = "Conversion reults look promising. The lines of code match." ELSE prompt$ = "The number of lines of code DO NOT match. A manual method is recommended." END IF GOSUB printline PRINT printlines% = 1: GOSUB redoborder prompt$ = "The file: qbtoqb64.tmp was created in the current directory." GOSUB printline PRINT DO printlines% = 1: GOSUB redoborder prompt$ = "Rename qbtoqb64.tmp as: " GOSUB printline PRINT destpath$ + makefile$(1); DO entry$ = destpath$ + makefile$(1): numofspaces% = 79 - POS(0): CALL keyboard(numofspaces%) LOOP UNTIL entry$ <> "" PRINT ON ERROR GOTO errhandler OPEN entry$ FOR INPUT AS #1 CLOSE #1 IF er1% <> 1 THEN SELECT CASE er1% CASE 0 prompt$ = "Sorry, a file with that name already exists. Redo..." CASE 2 prompt$ = "Sorry, that is not a valid or existing pathway. Redo..." CASE 3 prompt$ = "Sorry, that file name is not an accepted MS-DOS 8.3 name. Redo..." CASE 4 prompt$ = "Sorry, that drive is not ready or available. Redo..." END SELECT er1% = 0 printlines% = 1: GOSUB redoborder GOSUB printline SLEEP 1 PRINT ELSE er1% = 0 NAME "QBTOQB64.TMP" AS entry$ ON ERROR GOTO resnxt OPEN "QB64CONV.DAT" FOR INPUT AS #1 LINE INPUT #1, a1$ LINE INPUT #1, a2$ CLOSE #1 ON ERROR GOTO 0 OPEN "QB64CONV.DAT" FOR OUTPUT AS #1 PRINT #1, a1$ PRINT #1, entry$ CLOSE #1 prompt$ = "Finished. The file " + entry$ + " was created." printlines% = 1: GOSUB redoborder GOSUB printline printlines% = 2: GOSUB redoborder FOR i = LEN(entry$) TO 1 STEP -1 IF INSTR(i, entry$, "\") <> 0 THEN destpath$ = MID$(entry$, 1, i): EXIT FOR NEXT prompt$ = "Convert another file? [Y] \ [N] " GOSUB printline entry$ = "": numofspaces% = 1: CALL keyboard(numofspaces%) entry$ = UCASE$(entry$) IF entry$ = "N" THEN COLOR 0, 3: SYSTEM EXIT DO END IF LOOP GOSUB washmain cntmak% = 0: flag = 0: er1% = 0: source$ = "": makfilename$ = "": entry$ = "" LOOP SYSTEM washmain: f5key$ = "" FOR i = 4 TO 19 LOCATE i, 2: PRINT SPACE$(78); NEXT VIEW PRINT 4 TO 19 RETURN printline: LOCATE , 2: PRINT prompt$; RETURN redoborder: FOR i = 1 TO printlines%: PRINT : NEXT IF CSRLIN > 17 THEN y% = CSRLIN: x% = POS(0) COLOR 0, 7 LOCATE 18, 80: PRINT CHR$(176); LOCATE 19, 80: PRINT CHR$(176); COLOR 7, 1 LOCATE 18, 1: PRINT CHR$(179); LOCATE 19, 1: PRINT CHR$(179); LOCATE y%, x% END IF printlines% = 0 RETURN rememberpath: FOR i = LEN(entry$) TO 1 STEP -1 IF INSTR(i, entry$, "\") <> 0 THEN path$ = MID$(entry$, 1, i): EXIT FOR NEXT path$(cntmak%) = path$ IF source$ = "" THEN source$ = path$ OPEN "QB64CONV.DAT" FOR OUTPUT AS #1 PRINT #1, source$ CLOSE #1 END IF RETURN redomessage: SOUND 100, .5 printlines% = 1: GOSUB redoborder LOCATE , 2: PRINT SPACE$(78); : LOCATE , 2 GOSUB printline SLEEP 1 REM Option to erase ths line... LOCATE , 2: PRINT SPACE$(78); LOCATE rowredo%, columnredo% + LEN(entry$) holdentry$ = entry$ RETURN errhandler: SELECT CASE ERR CASE 53 er1% = 1 CASE 76 er1% = 2 CASE 64 er1% = 3 CASE 71 er1% = 4 CASE ELSE prompt$ = " Error " + LTRIM$(STR$(ERR)) + " occurred. Ending program..." SLEEP 3 SYSTEM END SELECT RESUME NEXT resnxt: RESUME NEXT DATA declared.tmp DATA shared.tmp DATA top.tmp DATA main.tmp DATA bottom.tmp DATA subs.tmp DATA qbtoqb64.tmp SUB construct (linecountnew%) OPEN "qbtoqb64.tmp" FOR OUTPUT AS #1 OPEN "declared.tmp" FOR INPUT AS #2 OPEN "shared.tmp" FOR INPUT AS #3 OPEN "top.tmp" FOR INPUT AS #4 OPEN "main.tmp" FOR INPUT AS #5 OPEN "bottom.tmp" FOR INPUT AS #6 OPEN "subs.tmp" FOR INPUT AS #7 DO UNTIL EOF(2) LINE INPUT #2, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #2 DO UNTIL EOF(3) LINE INPUT #3, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #3 DO UNTIL EOF(4) LINE INPUT #4, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #4 DO UNTIL EOF(5) LINE INPUT #5, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #5 DO UNTIL EOF(6) LINE INPUT #6, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #6 DO UNTIL EOF(7) LINE INPUT #7, a$ GOSUB countnewlines PRINT #1, a$ LOOP CLOSE #7 CLOSE #1 KILL "declared.tmp" KILL "shared.tmp" KILL "top.tmp" KILL "main.tmp" KILL "bottom.tmp" KILL "subs.tmp" EXIT SUB countnewlines: IF RTRIM$(a$) <> "" THEN IF INSTR(a$, "REM ------------------- End ") = 0 THEN linecountnew% = linecountnew% + 1 ELSE END IF END IF RETURN END SUB SUB help y% = CSRLIN: x% = POS(0) PCOPY 0, 1 SCREEN 0, 0, 1, 1 COLOR 7, 0 VIEW PRINT 2 TO 20: CLS 2 LOCATE , , 0 LOCATE 2, 1: PRINT CHR$(218) LOCATE 2, 2: PRINT STRING$(78, CHR$(196)) LOCATE 2, 80: PRINT CHR$(191) LOCATE 2, 76: PRINT CHR$(180) LOCATE 2, 78: PRINT CHR$(195) LOCATE 2, 77: PRINT CHR$(24) LOCATE 2, 38: PRINT " Help " FOR Rows = 3 TO 20 LOCATE Rows, 1: PRINT CHR$(179); LOCATE Rows, 80: PRINT CHR$(179); NEXT Rows LOCATE 4, 3 PRINT "This utility converts multi-modular QB programs to a single QB64 module." PRINT "" LOCATE , 3 PRINT "Input a .mak file, and the .bas files associated with it will be converted." PRINT "" LOCATE , 3 PRINT "If you don't have a .mak file, input each .bas file, starting with the main." PRINT "" LOCATE , 3 PRINT "When the last .bas file has been input, press the F5 key to convert them." PRINT "" LOCATE , 3 PRINT "The application will ask you if you want to make a .mak file if none exist." PRINT "" LOCATE , 3 PRINT "Once a new QB64 .tmp file is created, rename it to a folder to finish." PRINT "" PRINT "" LOCATE , 3 PRINT "Note: You can type the drive and file path or omit them if files are in the" PRINT "" LOCATE , 3 PRINT "current directory. Press any key to exit help..." key$ = INKEY$ SLEEP key$ = INKEY$ LOCATE y%, x%, 1, 7, 7 SCREEN 0, 0, 0, 0 END SUB SUB keyboard (numofspaces%) startpos% = POS(0) - LEN(entry$) endpos% = POS(0) + numofspaces% DO DO b$ = INKEY$ IF b$ <> "" THEN EXIT DO LOOP row% = CSRLIN: column% = POS(0) SELECT CASE b$ CASE CHR$(0) + "K" mov% = -1: GOSUB action CASE CHR$(0) + "M" mov% = 1: GOSUB action CASE CHR$(0) + "S" GOSUB wash: GOSUB delete CASE CHR$(0) + "R" IF ins% = 0 THEN ins% = -1 ELSE ins% = 0 IF ins% = 0 THEN LOCATE , , 1, 7, 7 ELSE LOCATE , , 1, 7, 30 CASE CHR$(0) + "O" IF entry$ <> "" THEN LOCATE row%, startpos% + LEN(entry$) CASE CHR$(0) + "G" LOCATE row%, startpos% CASE CHR$(8) IF column% > startpos% THEN LOCATE , POS(0) - 1 column% = POS(0) GOSUB wash: GOSUB delete END IF CASE CHR$(13) EXIT SUB REM Special Keys CASE CHR$(0) + CHR$(59) CALL help CASE CHR$(0) + CHR$(63) IF f5key$ = "ready" THEN f5key$ = "on": EXIT SUB CASE CHR$(27) COLOR 0, 3: SYSTEM CASE CHR$(32) TO CHR$(126) key$ = b$: GOSUB action END SELECT mov% = 0: key$ = "" LOOP action: IF POS(0) + mov% >= startpos% AND POS(0) + mov% < endpos% THEN DO IF key$ <> "" THEN SELECT CASE ins% CASE 0 IF LEN(entry$) + LEN(key$) > endpos% - startpos% THEN EXIT DO entry$ = MID$(entry$, 1, POS(0) - startpos%) + key$ + MID$(entry$, POS(0) - startpos% + 1) CASE -1 entry$ = MID$(entry$, 1, POS(0) - startpos%) + key$ + MID$(entry$, POS(0) - startpos% + 2) END SELECT END IF IF POS(0) - startpos% >= LEN(entry$) - LEN(key$) AND key$ <> "" OR key$ = "" OR ins% = -1 THEN IF key$ = "" AND mov% = 1 THEN IF POS(0) - startpos% = LEN(entry$) THEN EXIT DO LOCATE , POS(0) + mov%: PRINT key$; ELSE LOCATE row%, startpos%: PRINT MID$(entry$, 1, column% - startpos%); key$; : yy2% = POS(0): PRINT MID$(entry$, column% - startpos% + 2); : LOCATE row%, yy2% END IF EXIT DO LOOP END IF RETURN wash: IF POS(0) >= startpos% AND entry$ <> "" AND POS(0) - startpos% < LEN(entry$) THEN LOCATE row%, startpos% + LEN(entry$) - 1 PRINT " "; LOCATE row%, column% END IF RETURN delete: IF POS(0) - startpos% = 0 THEN entry$ = MID$(entry$, 2) ELSE entry$ = MID$(entry$, 1, POS(0) - startpos%) + MID$(entry$, POS(0) - startpos% + 2) END IF PRINT MID$(entry$, column% - startpos% + 1); : LOCATE row%, column% RETURN END SUB DEFINT A-Z SUB QBIDE PALETTE 2, 59 COLOR 15, 1 CLS COLOR 0, 7 LOCATE 1, 1 PRINT SPACE$(80) LOCATE 1, 1: PRINT " File Edit View Search Run Debug Calls Options Help" COLOR 7, 1 LOCATE 2, 1: PRINT CHR$(218) LOCATE 2, 2: PRINT STRING$(78, CHR$(196)) LOCATE 2, 80: PRINT CHR$(191) LOCATE 2, 76: PRINT CHR$(180) LOCATE 2, 78: PRINT CHR$(195) COLOR 1, 7 LOCATE 2, 77: PRINT CHR$(24) LOCATE 2, 36: PRINT " Untitled " COLOR 7, 1 FOR Rows = 3 TO 24 LOCATE Rows, 1: PRINT CHR$(179); LOCATE Rows, 80: PRINT CHR$(179); NEXT Rows LOCATE 22, 1: PRINT CHR$(195) LOCATE 22, 80: PRINT CHR$(180) LOCATE 22, 2: PRINT STRING$(78, CHR$(196)) LOCATE 22, 35 PRINT " Immediate " COLOR 0, 7 LOCATE 21, 3: PRINT STRING$(76, CHR$(176)) LOCATE 21, 2: PRINT CHR$(27) LOCATE 21, 3: PRINT CHR$(219) LOCATE 21, 79: PRINT CHR$(26) FOR Rows = 4 TO 19 LOCATE Rows, 80: PRINT CHR$(176) NEXT Rows LOCATE 3, 80: PRINT CHR$(24) LOCATE 4, 80: PRINT CHR$(219) LOCATE 20, 80: PRINT CHR$(25) COLOR 0, 3: LOCATE 25, 1: PRINT " <Shift+F1=Help> <F6=Window> <F2=Subs> <F5=Run> <F8=Step> "; LOCATE 25, 59: PRINT SPACE$(4); COLOR 0, 3 LOCATE 25, 63: PRINT CHR$(179); LOCATE 25, 64: PRINT SPACE$(6); LOCATE 25, 68: PRINT "C 00001:001 "; END SUB DEFSNG A-Z SUB rewrite (cntmak%, linecountorig%, dupshared%) OPEN "declared.tmp" FOR OUTPUT AS #2 OPEN "shared.tmp" FOR OUTPUT AS #3 OPEN "top.tmp" FOR OUTPUT AS #4 OPEN "main.tmp" FOR OUTPUT AS #5 OPEN "bottom.tmp" FOR OUTPUT AS #6 OPEN "subs.tmp" FOR OUTPUT AS #7 FOR i = 1 TO cntmak% OPEN path$ + makefile$(i) FOR INPUT AS #1 LOCATE , POS(0) + 1: PRINT makefile$(i), DO UNTIL EOF(1) IF flag <> 2 THEN flag = 0 GOSUB countinput IF monitordeclare = -1 THEN IF INSTR(a$, "DECLARE SUB ") = 0 AND RTRIM$(a$) <> "" AND MID$(LTRIM$(a$), 1, 1) <> "'" AND MID$(LTRIM$(a$) + " ", 1, 4) <> "REM " THEN PRINT #2, "REM ------------------- End " + makefile$(i) + " Declare Statements" PRINT #2, "" pastdeclare = -1 monitordeclare = 0 END IF END IF IF MID$(LTRIM$(a$), 1, 12) = "DECLARE SUB " THEN IF monitordeclare = 0 THEN monitordeclare = -1 PRINT #2, a$: flag = -1 END IF IF ABS(flag) <> 1 THEN SELECT CASE i CASE 1 IF MID$(LTRIM$(a$), 1, 4) = "SUB " THEN flag = 2 GOSUB checksubprestatements IF pastdeclare = 0 AND MID$(LTRIM$(a$), 1, 3) = "REM" OR pastdeclare = 0 AND MID$(LTRIM$(a$), 1, 1) = "'" THEN REM Print REM statments before main declare statements. PRINT #2, a$: flag = -1 END IF IF INSTR(a$, "COMMON SHARED ") <> 0 THEN DO UNTIL INSTR(a$, "COMMON SHARED ") = 0 a$ = MID$(a$, 1, INSTR(a$, "COMMON SHARED ") - 1) + "DIM" + MID$(a$, INSTR(a$, "COMMON SHARED ") + 6) LOOP PRINT #3, a$: flag = -1 END IF IF flag = 0 THEN PRINT #5, a$ ELSE IF flag = 2 THEN PRINT #7, a$ CASE ELSE IF MID$(LTRIM$(a$), 1, 4) = "SUB " THEN flag = 2 GOSUB checksubprestatements IF flag <> 2 THEN IF MID$(LTRIM$(a$), 1, 12) = "DECLARE SUB " THEN PRINT #2, a$ END IF IF INSTR(a$, "COMMON SHARED ") <> 0 THEN DO UNTIL INSTR(a$, "COMMON SHARED ") = 0 dupshared% = dupshared% + 1 IF INSTR(a$, ":") = 0 THEN flag = 1: EXIT DO a$ = LTRIM$(MID$(a$, INSTR(a$, ":") + 1)) LOOP END IF IF MID$(LTRIM$(a$), 1, 5) = "TYPE " THEN DO UNTIL EOF(1) PRINT #4, a$ IF LTRIM$(a$) = "END TYPE" THEN PRINT #4, "": flag = 1: EXIT DO GOSUB countinput LOOP END IF IF MID$(LTRIM$(a$), 1, 4) = "DIM " OR MID$(LTRIM$(a$), 1, 6) = "REDIM " THEN PRINT #4, a$ ELSE IF flag = 0 THEN PRINT #6, a$ bottom = 1 END IF ELSE PRINT #7, a$: REM Flag = 2 END IF END SELECT END IF LOOP CLOSE #1 IF bottom <> 0 THEN PRINT #6, "REM ------------------- End " + makefile$(i) + " Loaded Module Main Statements" PRINT #7, "REM ------------------- End " + makefile$(i) + " Module" flag = 0 bottom = 0 pastdeclare = 0 NEXT RESET EXIT SUB countinput: LINE INPUT #1, a$ IF RTRIM$(a$) <> "" THEN linecountorig% = linecountorig% + 1 RETURN checksubprestatements: IF pastdeclare = -1 THEN IF MID$(LTRIM$(a$), 1, 11) = "REM $STATIC" THEN flag = 2 IF MID$(LTRIM$(a$), 1, 8) = "'$STATIC" THEN flag = 2 IF MID$(LTRIM$(a$), 1, 7) = "DEFINT " THEN flag = 2 IF MID$(LTRIM$(a$), 1, 7) = "DEF SEG " THEN flag = 2 END IF RETURN END SUB

NOTE: If full code is not displayed, Refresh browser!


The method using the QB IDE is:

Load all files...

Move all DECLARE statements to main module.

Move all DATA to the main module.

Move all Error handlers to the main module.

- Note: Error traps are remembered in a module. If you go to a different module, make a new ON ERROR statement, it will only be good for that module. Once the sub is exited and control is back to the previous module, the last ON ERROR statement in that module is again in effect. Since all error handlers are now in the same module, you may have to update them to allow for this change.

Convert all COMMON SHARED variables to DIM SHARED or REDIM SHARED in the main module.

- Note: If you use REDIM in a sub do not use REDIM SHARED, it is not allowed because the variable remains a shared once it is declared that way in the main.

- Note: You will need to REMOVE or type in the number of elements in each array in any COMMOM SHARED statement that appears as the following example: COMMON SHARED (x(), y(), z()). This would be converted to DIM SHARED (x(), y(), z()). Now you must either remove them and DIM them in a more appropriate place in your program or leave them and supply the number of elements to each, such as a DIM SHARED (x(100), y(20), z(300)). The same is true for multi-dimensional arrays. Move all subs and functions to the main module.

-Note be careful about duplicate variable names. Although duplicate names represent completely different values when separated in modules, when you join the modules, you will encounter a problem. It is recommended to rename any duplicate named variables as well as rename any duplicate labels or line numbers between modules before joining them.

Remove all modules except main module.

Rem-out all unsupported statements.

Save new file.


The above information is supplied by Pete who is the current owner of the Network 54 Qbasic Forum


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Personal tools