Author Topic: memory leak and question  (Read 5990 times)

0 Members and 1 Guest are viewing this topic.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
memory leak and question
« on: September 29, 2020, 12:00:38 pm »
Hello

First the question. When a sub is call when the end sub or exit sub is encountered does it return to the next statement after the call

memory leak i am going to post my code here. I use rem statement to an excess do to my eyes so the code will not run together so please dont pound on me about the clutter ok just look at the prompt area and tell me if i left any memory leaks

thanks in advance
Badger
if this is not allowed sorry please delete and let me know how to post code


REM ***************************************************************************
REM **** Program Bridal Store *************************************************
REM ***************************************************************************
REM ***************************************************************************
REM **** Author Philip King  **************************************************
REM ***************************************************************************
REM ***************************************************************************
REM ***************************************************************************
REM **** Includes go here *****************************************************
REM ***************************************************************************

REM ***************************************************************************
REM ***************************************************************************
REM **** Sreen statements here ************************************************
REM ***************************************************************************

$COLOR:32

REM ***************************************************************************

REM ***************************************************************************
REM **** Listing of subs and funtions *****************************************
REM ***************************************************************************

REM ***************************************************************************

REM ***************************************************************************
REM **** arrays decleared here ************************************************
REM ***************************************************************************
imenu = 4
DIM SHARED smenu(imenu) AS STRING

REM ***************************************************************************

REM ***************************************************************************
REM **** arrays set to data here **********************************************
REM ***************************************************************************

smenu(1) = "1) Edit Customer Info": smenu(2) = "3) Edit Inventory Data "
smenu(3) = "2) Edit Sales ": smenu(4) = "4) System Maintenance "

REM ***************************************************************************
REM **** variables declares go here *******************************************
REM ***************************************************************************
DIM SHARED sr AS STRING
CONST null = ""
REM ***************************************************************************

REM ***************************************************************************
REM **** customer info record type ********************************************
REM ***************************************************************************
TYPE customer
        id AS LONG
        sfirst_name AS STRING * 25
        slast_name AS STRING * 25
        saddress AS STRING * 30
        scity AS STRING * 25
        sstate AS STRING * 2
        szip AS STRING * 5
        sphone AS STRING * 10
END TYPE
REM ***************************************************************************

REM ***************************************************************************
REM **** inventory record type ************************************************
REM ***************************************************************************
TYPE inventory
        ienventory AS LONG
        sdesc AS STRING * 250
        sdate_bought AS STRING * 8
        sdate_sold AS STRING * 8
        fcost AS _FLOAT
        fretail AS _FLOAT
        ssize AS STRING * 2
        ssold AS STRING * 1
END TYPE
REM ***************************************************************************

REM ***************************************************************************
REM **** point of sale type ***************************************************
REM ***************************************************************************
TYPE spos
        lposid AS LONG
END TYPE
REM ***************************************************************************
DIM SHARED custinforec AS customer
custinforeclen = LEN(custinforec)

CLS


REM ***************************************************************************
REM **** defines for quick use data types *************************************
REM ***************************************************************************
_DEFINE I AS INTEGER : _DEFINE S AS STRING : _DEFINE D AS DOUBLE :
_DEFINE F AS _FLOAT : _DEFINE L AS LONG
REM ***************************************************************************


REM ***************************************************************************
REM **** main modual **********************************************************
REM ***************************************************************************
SCREEN _NEWIMAGE(640, 400, 32)
COLOR LightCyan, MidnightBlue
iflag2 = 0
iflag3 = 1
CLS
'SCREEN 12
_FULLSCREEN
IF se = "X" THEN END
GOSUB menuloop:
IF saction = "X" THEN END
'if se ="1" then call that prompt
'LINE INPUT siy: END
REM ***************************************************************************
REM **** main menu loop *******************************************************
REM ***************************************************************************

menuloop:
CALL systemheader
CALL printmain
CALL mainmenuchoice
IF sr = "" OR sr = CHR$(13) THEN GOTO menuloop
IF sr = "X" THEN END
'IF sr = "1" THEN CALL custinfo: 'GOSUB custinfo1
IF sr = "1" THEN
        CALL promptid
        CALL promptfname
        CALL promptlname
        CALL promptaddress
        CALL promptcity
        CALL promptsstate
        CALL promptszip
        CALL promptphone
        RETURN
END IF
REM ***************************************************************************




REM ***************************************************************************
REM **** customer input modual ************************************************
REM ***************************************************************************

's0:
SUB custinput
        CALL systemheader
        LOCATE 10, 1: PRINT "Customer ID           ";: PRINT custinforec.id
        LOCATE 11, 1: PRINT "Customer First Name   ";: PRINT custinforec.sfirst_name
        LOCATE 12, 1: PRINT "customer Last Name    ";: PRINT custinforec.slast_name
        LOCATE 13, 1: PRINT "Customer Address      ";: PRINT custinforec.saddress
        LOCATE 14, 1: PRINT "Customer City         ";: PRINT custinforec.scity
        LOCATE 15, 1: PRINT "customer State        ";: PRINT custinforec.sstate
        LOCATE 16, 1: PRINT "customer Zip          ";: PRINT custinforec.szip
        LOCATE 17, 1: PRINT "Customer Phone Number ";
        PRINT LEFT$(custinforec.sphone, 3) + "/"; MID$(custinforec.sphone, 4, 3) + "/"; RIGHT$(custinforec.sphone, 4)
        'RETURN
END SUB
REM ********************************************************************
's1:
SUB promptid
        CALL custinput
        saction = "Enter Customer ID X to Exit "
        ib = 9
        ilow = 1
        ihigh = 999999999
        iflag1 = 1
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF
        IF sr = "-" THEN
                EXIT SUB
                RETURN
        END IF
        IF sr = "X" THEN
                iflag1 = 0
                EXIT SUB
                RETURN
        END IF
        custinforec.id = VAL(sr): CALL custinput
END SUB
REM ********************************************************************
's2:
SUB promptfname
        CALL custinput
        saction = "Enter First Name X to Exit - To Backup "
        ib = 25
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptid
        END IF
        IF sr = "X" THEN
                EXIT SUB
        END IF

        custinforec.sfirst_name = sr: CALL custinput
END SUB
REM ***************************************************************************
's3:
SUB promptlname
        CALL custinput
        saction = "Enter Last Name X to Exit To Back up "
        ib = 25
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        '        IF sr = "-" THEN
        '                EXIT SUB
        '                CALL promptfname
        '       END IF
        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.slast_name = sr
        CALL custinput
END SUB
REM ***************************************************************************
's4:
SUB promptaddress
        CALL custinput
        saction = "Enter Address X to Exit - To Back up "
        ib = 30
        ilow = 99
        ihigh = 99
        iflag1 = 0

        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptlname
        END IF



        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.saddress = sr
        CALL custinput
END SUB
REM ***************************************************************************
's5:
SUB promptcity
        CALL custinput
        saction = "Enter City Name X to Exit - To Back up "
        ib = 25
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptaddress
        END IF
        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.scity = sr
        CALL custinput
END SUB
REM ***************************************************************************
's6:
SUB promptsstate
        CALL custinput
        saction = "Enter State X to Exit - To Back up "
        ib = 2
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptcity
        END IF
        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.sstate = sr
        CALL custinput
END SUB

REM ***************************************************************************

's7:
SUB promptszip
        CALL custinput
        saction = "Enter Zip Code Name X to Exit - To Back up "
        ib = 5
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptsstate
        END IF
        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.szip = sr
        CALL custinput
END SUB
REM ***************************************************************************
's8:
SUB promptphone
        CALL custinput
        saction = "Enter Phone Number X to Exit - To Back up "
        ib = 30
        ilow = 99
        ihigh = 99
        iflag1 = 0
        IF iflag2 = 1 THEN
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        ELSE
                CALL clearprompt
                CALL salphainput(saction, ib, ilow, ihigh, iflag1)
        END IF

        IF sr = "-" THEN
                EXIT SUB
                CALL promptszip
        END IF
        IF sr = "X" THEN
                EXIT SUB
                RETURN
        END IF
        custinforec.sphone = sr
        CALL custinput
        LINE INPUT sr
END SUB

REM ***************************************************************************


REM ***************************************************************************
REM **** set custinforrec variables to zero or null ***************************
REM ***************************************************************************
SUB custinforec_null
        custinforec.id = 0
        custinforec.sfirst_name = null
        custinforec.slast_name = null
        custinforec.saddress = null
        custinforec.scity = null
        custinforec.sstate = null
        custinforec.szip = null
        custinforec.sphone = null
END SUB
REM ***************************************************************************

REM ***************************************************************************
REM **** Sytem Header *********************************************************
REM ***************************************************************************
SUB systemheader
        COLOR White, Blue
        CLS
        LOCATE 1, 1: PRINT CHR$(201): LOCATE 1, 80: PRINT CHR$(187)
        LOCATE 1, 2: PRINT STRING$(78, 205):
        FOR ix = 2 TO 7
                LOCATE ix, 1: PRINT CHR$(186)
                LOCATE ix, 80: PRINT CHR$(186)
        NEXT ix
        LOCATE 7, 2: PRINT STRING$(78, 205)
        LOCATE 7, 1: PRINT CHR$(200): LOCATE 7, 80: PRINT CHR$(188)
        LOCATE 4, 30: PRINT "Main System Menu"
        LOCATE 4, 63: PRINT "Date ": LOCATE 4, 68: PRINT DATE$
        LOCATE 4, 4: PRINT "Virsion 1.0"
END SUB



REM ***************************************************************************
REM **** printes in system erros **********************************************
REM ***************************************************************************
SUB sprintserrors (se)
        CLS
        SCREEN 0
        IF se = "" THEN se = "INVALID RESPONSE"
        itemp = LEN(se)
        itemp1 = 40 - (itemp / 2)
        BEEP
        COLOR 16, 7
        'COLOR Yellow, Blue
        LOCATE 25, itemp1: _BLINK ON: PRINT se;
        Delay 1.5
        _BLINK OFF
        $COLOR:0
        iflag2 = 1
END SUB
REM ***************************************************************************

REM *****************************************************************************
REM **** numeric input sub ******************************************************
REM *****************************************************************************
SUB snumeric (sr, ilow, ihigh)

        ftemp = VAL(sr)
        IF ftemp < ilow OR ftemp > ihigh THEN
                se = "INPUT OUT OF BOUNDS"
                CALL sprintserrors(se)
        END IF

END SUB
REM ***************************************************************************

REM ***************************************************************************
REM **** alpha input sub ******************************************************
REM ***************************************************************************
SUB salphainput (saction, ib, ilow, ihigh, iflag1)

        iflag2 = 0
        ilength1 = LEN(sr)
        ilength2 = LEN(saction) + 2

        LOCATE 23, 1: PRINT saction; '               prints action menu
        LOCATE 23, ilength2 '                        set prompt one space after action menu print
        COLOR Yellow, Black: PRINT SPC(ib); '                changes color and prints ib spaces to screen for input lenght
        LOCATE 23, ilength2 '                        sets curser at the begining of input space from previouse line
        LINE INPUT sr: sr = UCASE$(sr) '             inputs data from user changes it to upper case

        IF LEN(sr) > ib THEN
                se = "ENVALID INPUT LENGTH"
                CALL sprintserrors(se)
                sr = ""
                iflag2 = 1
        END IF
        IF iflag1 = 1 AND sr = "X" THEN iflag1 = 0
        IF iflag1 = 1 AND VAL(sr) < ilow AND VAL(sr) > ihigh THEN CALL snumeric(sr, ilow, ihigh)

        COLOR White, Blue
END SUB


REM ***************************************************************************
REM **** main menu to the screen **********************************************
REM ***************************************************************************
SUB printmain
        COLOR White, Blue
        FOR ix = 11 TO imenu
                READ smenu(ix): LOCATE ix, 20: PRINT smenu(ix)
        NEXT ix

        LOCATE 11, 15: PRINT smenu(1)
        LOCATE 11, 40: PRINT smenu(2)
        LOCATE 13, 15: PRINT smenu(3)
        LOCATE 13, 40: PRINT smenu(4)

END SUB
REM ***************************************************************************

REM ***************************************************************************
REM **** array data goes here *************************************************
REM ***************************************************************************

SUB Delay (dlay!)
        start! = TIMER
        DO WHILE start! + dlay! >= TIMER
                IF start! > TIMER THEN start! = start! - 86400
        LOOP
END SUB

REM ***************************************************************************

REM ***************************************************************************
REM **** menu prompts start here **********************************************
REM ***************************************************************************
SUB mainmenuchoice
        ib = 1
        ihigh = 99
        ilow = 1
        saction = "Choose Menu Option or X to Quit "
        CALL salphainput(saction, ib, ilow, ihigh, iflag1)
END SUB
REM ***************************************************************************

REM ***************************************************************************
REM **** clean up the prompt area *********************************************
REM ***************************************************************************

SUB clearprompt
        LOCATE 23, 1: PRINT STRING$(79, 32)
END SUB

REM ***************************************************************************


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #1 on: September 29, 2020, 12:20:30 pm »
Quote
First the question. When a sub is call when the end sub or exit sub is encountered does it return to the next statement after the call

Yes!

For posting code here at forum,
paste copy of code into editor, select it, and then use Code Tag button looks like QB64 icon:
  [ You are not allowed to view this attachment ]  



Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #2 on: September 29, 2020, 12:27:27 pm »
Hello

will do

Badger
like this

Code: QB64: [Select]
  1. REM ***************************************************************************
  2. REM **** Program Bridal Store *************************************************
  3. REM ***************************************************************************
  4. REM ***************************************************************************
  5. REM **** Author Philip King  **************************************************
  6. REM ***************************************************************************
  7. REM ***************************************************************************
  8. REM ***************************************************************************
  9. REM **** Includes go here *****************************************************
  10. REM ***************************************************************************
  11.  
  12. REM ***************************************************************************
  13. REM ***************************************************************************
  14. REM **** Sreen statements here ************************************************
  15. REM ***************************************************************************
  16.  
  17.  
  18. REM ***************************************************************************
  19.  
  20. REM ***************************************************************************
  21. REM **** Listing of subs and funtions *****************************************
  22. REM ***************************************************************************
  23.  
  24. REM ***************************************************************************
  25.  
  26. REM ***************************************************************************
  27. REM **** arrays decleared here ************************************************
  28. REM ***************************************************************************
  29. imenu = 4
  30. DIM SHARED smenu(imenu) AS STRING
  31.  
  32. REM ***************************************************************************
  33.  
  34. REM ***************************************************************************
  35. REM **** arrays set to data here **********************************************
  36. REM ***************************************************************************
  37.  
  38. smenu(1) = "1) Edit Customer Info": smenu(2) = "3) Edit Inventory Data "
  39. smenu(3) = "2) Edit Sales ": smenu(4) = "4) System Maintenance "
  40.  
  41. REM ***************************************************************************
  42. REM **** variables declares go here *******************************************
  43. REM ***************************************************************************
  44. CONST null = ""
  45. REM ***************************************************************************
  46.  
  47. REM ***************************************************************************
  48. REM **** customer info record type ********************************************
  49. REM ***************************************************************************
  50. TYPE customer
  51.         id AS LONG
  52.         sfirst_name AS STRING * 25
  53.         slast_name AS STRING * 25
  54.         saddress AS STRING * 30
  55.         scity AS STRING * 25
  56.         sstate AS STRING * 2
  57.         szip AS STRING * 5
  58.         sphone AS STRING * 10
  59. REM ***************************************************************************
  60.  
  61. REM ***************************************************************************
  62. REM **** inventory record type ************************************************
  63. REM ***************************************************************************
  64. TYPE inventory
  65.         ienventory AS LONG
  66.         sdesc AS STRING * 250
  67.         sdate_bought AS STRING * 8
  68.         sdate_sold AS STRING * 8
  69.         fcost AS _FLOAT
  70.         fretail AS _FLOAT
  71.         ssize AS STRING * 2
  72.         ssold AS STRING * 1
  73. REM ***************************************************************************
  74.  
  75. REM ***************************************************************************
  76. REM **** point of sale type ***************************************************
  77. REM ***************************************************************************
  78. TYPE spos
  79.         lposid AS LONG
  80. REM ***************************************************************************
  81. DIM SHARED custinforec AS customer
  82. lcustinforeclen = LEN(custinforec)
  83.  
  84.  
  85.  
  86. REM ***************************************************************************
  87. REM **** defines for quick use data types *************************************
  88. REM ***************************************************************************
  89. REM ***************************************************************************
  90.  
  91.  
  92. REM ***************************************************************************
  93. REM **** main modual **********************************************************
  94. REM ***************************************************************************
  95. SCREEN _NEWIMAGE(640, 400, 32)
  96. COLOR LightCyan, MidnightBlue
  97. iflag2 = 0
  98. iflag3 = 1
  99. IF se = "X" THEN END
  100. GOSUB menuloop:
  101. REM ***************************************************************************
  102. REM **** main menu loop *******************************************************
  103. REM ***************************************************************************
  104.  
  105. menuloop:
  106. CALL systemheader
  107. CALL printmain
  108. CALL mainmenuchoice
  109. IF sr = "" OR sr = CHR$(13) THEN GOTO menuloop
  110. IF sr = "X" THEN END
  111. 'IF sr = "1" THEN CALL custinfo: 'GOSUB custinfo1
  112.  
  113. IF sr = "1" THEN
  114.         CALL promptid
  115.         IF sr = "X" THEN RETURN
  116.         CALL promptfname
  117.         IF sr = "X" THEN RETURN
  118.         CALL promptlname
  119.         IF sr = "X" THEN RETURN
  120.         CALL promptaddress
  121.         IF sr = "X" THEN RETURN
  122.         CALL promptcity
  123.         IF sr = "X" THEN RETURN
  124.         CALL promptsstate
  125.         IF sr = "X" THEN RETURN
  126.         CALL promptszip
  127.         IF sr = "X" THEN RETURN
  128.         CALL promptphone
  129.         IF sr = "X" THEN RETURN
  130.         RETURN
  131. REM ***************************************************************************
  132.  
  133. REM ***************************************************************************
  134. REM **** customer input modual ************************************************
  135. REM ***************************************************************************
  136.  
  137. 's0:
  138. SUB custinput
  139.         CALL systemheader
  140.         LOCATE 10, 1: PRINT "Customer ID           ";: PRINT custinforec.id
  141.         LOCATE 11, 1: PRINT "Customer First Name   ";: PRINT custinforec.sfirst_name
  142.         LOCATE 12, 1: PRINT "customer Last Name    ";: PRINT custinforec.slast_name
  143.         LOCATE 13, 1: PRINT "Customer Address      ";: PRINT custinforec.saddress
  144.         LOCATE 14, 1: PRINT "Customer City         ";: PRINT custinforec.scity
  145.         LOCATE 15, 1: PRINT "customer State        ";: PRINT custinforec.sstate
  146.         LOCATE 16, 1: PRINT "customer Zip          ";: PRINT custinforec.szip
  147.         LOCATE 17, 1: PRINT "Customer Phone Number ";
  148.         PRINT LEFT$(custinforec.sphone, 3) + "/"; MID$(custinforec.sphone, 4, 3) + "/"; RIGHT$(custinforec.sphone, 4)
  149.         'RETURN
  150.  
  151. REM ********************************************************************
  152.  
  153. 's1:
  154. SUB promptid
  155.         CALL custinput
  156.         saction = "Enter Customer ID X to Exit "
  157.         ib = 9
  158.         ilow = 1
  159.         ihigh = 999999999
  160.         iflag1 = 1
  161.         IF iflag2 = 1 THEN
  162.                 CALL clearprompt
  163.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  164.         ELSE
  165.                 CALL clearprompt
  166.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  167.         END IF
  168.         IF sr = "X" THEN
  169.                 iflag1 = 0
  170.                 EXIT SUB
  171.                 ' RETURN
  172.         END IF
  173.         custinforec.id = VAL(sr): CALL custinput
  174.  
  175. REM ********************************************************************
  176.  
  177. 's2:
  178. SUB promptfname
  179.         CALL custinput
  180.         saction = "Enter First Name X to Exit - To Backup "
  181.         ib = 25
  182.         ilow = 99
  183.         ihigh = 99
  184.         iflag1 = 0
  185.         IF iflag2 = 1 THEN
  186.                 CALL clearprompt
  187.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  188.         ELSE
  189.                 CALL clearprompt
  190.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  191.         END IF
  192.  
  193.         IF sr = "-" THEN
  194.                 EXIT SUB
  195.                 CALL promptid
  196.         END IF
  197.         IF sr = "X" THEN
  198.                 EXIT SUB
  199.         END IF
  200.  
  201.         custinforec.sfirst_name = sr: CALL custinput
  202.  
  203. REM ***************************************************************************
  204.  
  205. 's3:
  206.  
  207. SUB promptlname
  208.         CALL custinput
  209.         saction = "Enter Last Name X to Exit - To Back up "
  210.         ib = 25
  211.         ilow = 99
  212.         ihigh = 99
  213.         iflag1 = 0
  214.         IF iflag2 = 1 THEN
  215.                 CALL clearprompt
  216.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  217.         ELSE
  218.                 CALL clearprompt
  219.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  220.         END IF
  221.  
  222.         '        IF sr = "-" THEN
  223.         '                EXIT SUB
  224.         '                CALL promptfname
  225.         '       END IF
  226.         IF sr = "X" THEN
  227.                 EXIT SUB
  228.                 RETURN
  229.         END IF
  230.         custinforec.slast_name = sr
  231.         CALL custinput
  232. REM ***************************************************************************
  233.  
  234. 's4:
  235. SUB promptaddress
  236.         CALL custinput
  237.         saction = "Enter Address X to Exit - To Back up "
  238.         ib = 30
  239.         ilow = 99
  240.         ihigh = 99
  241.         iflag1 = 0
  242.  
  243.         IF iflag2 = 1 THEN
  244.                 CALL clearprompt
  245.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  246.         ELSE
  247.                 CALL clearprompt
  248.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  249.         END IF
  250.  
  251.         IF sr = "-" THEN
  252.                 EXIT SUB
  253.                 CALL promptlname
  254.         END IF
  255.  
  256.  
  257.  
  258.         IF sr = "X" THEN
  259.                 EXIT SUB
  260.                 RETURN
  261.         END IF
  262.         custinforec.saddress = sr
  263.         CALL custinput
  264. REM ***************************************************************************
  265.  
  266. 's5:
  267. SUB promptcity
  268.         CALL custinput
  269.         saction = "Enter City Name X to Exit - To Back up "
  270.         ib = 25
  271.         ilow = 99
  272.         ihigh = 99
  273.         iflag1 = 0
  274.         IF iflag2 = 1 THEN
  275.                 CALL clearprompt
  276.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  277.         ELSE
  278.                 CALL clearprompt
  279.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  280.         END IF
  281.  
  282.         IF sr = "-" THEN
  283.                 EXIT SUB
  284.                 CALL promptaddress
  285.         END IF
  286.         IF sr = "X" THEN
  287.                 EXIT SUB
  288.                 RETURN
  289.         END IF
  290.         custinforec.scity = sr
  291.         CALL custinput
  292. REM ***************************************************************************
  293. 's6:
  294. SUB promptsstate
  295.         CALL custinput
  296.         saction = "Enter State X to Exit - To Back up "
  297.         ib = 2
  298.         ilow = 99
  299.         ihigh = 99
  300.         iflag1 = 0
  301.         IF iflag2 = 1 THEN
  302.                 CALL clearprompt
  303.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  304.         ELSE
  305.                 CALL clearprompt
  306.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  307.         END IF
  308.  
  309.         IF sr = "-" THEN
  310.                 EXIT SUB
  311.                 CALL promptcity
  312.         END IF
  313.         IF sr = "X" THEN
  314.                 EXIT SUB
  315.                 RETURN
  316.         END IF
  317.         custinforec.sstate = sr
  318.         CALL custinput
  319.  
  320. REM ***************************************************************************
  321.  
  322. 's7:
  323. SUB promptszip
  324.         CALL custinput
  325.         saction = "Enter Zip Code Name X to Exit - To Back up "
  326.         ib = 5
  327.         ilow = 99
  328.         ihigh = 99
  329.         iflag1 = 0
  330.         IF iflag2 = 1 THEN
  331.                 CALL clearprompt
  332.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  333.         ELSE
  334.                 CALL clearprompt
  335.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  336.         END IF
  337.  
  338.         IF sr = "-" THEN
  339.                 EXIT SUB
  340.                 CALL promptsstate
  341.         END IF
  342.         IF sr = "X" THEN
  343.                 EXIT SUB
  344.                 RETURN
  345.         END IF
  346.         custinforec.szip = sr
  347.         CALL custinput
  348. REM ***************************************************************************
  349.  
  350. 's8:
  351. SUB promptphone
  352.         CALL custinput
  353.         saction = "Enter Phone Number X to Exit - To Back up "
  354.         ib = 30
  355.         ilow = 99
  356.         ihigh = 99
  357.         iflag1 = 0
  358.         IF iflag2 = 1 THEN
  359.                 CALL clearprompt
  360.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  361.         ELSE
  362.                 CALL clearprompt
  363.                 CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  364.         END IF
  365.  
  366.         IF sr = "-" THEN
  367.                 EXIT SUB
  368.                 CALL promptszip
  369.         END IF
  370.         IF sr = "X" THEN
  371.                 EXIT SUB
  372.                 RETURN
  373.         END IF
  374.         custinforec.sphone = sr
  375.         CALL custinput
  376.         LINE INPUT sr
  377.  
  378. REM ***************************************************************************
  379.  
  380.  
  381. REM ***************************************************************************
  382. REM **** set custinforrec variables to zero or null ***************************
  383. REM ***************************************************************************
  384. SUB custinforec_null
  385.         custinforec.id = 0
  386.         custinforec.sfirst_name = null
  387.         custinforec.slast_name = null
  388.         custinforec.saddress = null
  389.         custinforec.scity = null
  390.         custinforec.sstate = null
  391.         custinforec.szip = null
  392.         custinforec.sphone = null
  393. REM ***************************************************************************
  394.  
  395. REM ***************************************************************************
  396. REM **** Sytem Header *********************************************************
  397. REM ***************************************************************************
  398. SUB systemheader
  399.         COLOR White, Blue
  400.         CLS
  401.         LOCATE 1, 1: PRINT CHR$(201): LOCATE 1, 80: PRINT CHR$(187)
  402.         LOCATE 1, 2: PRINT STRING$(78, 205):
  403.         FOR ix = 2 TO 7
  404.                 LOCATE ix, 1: PRINT CHR$(186)
  405.                 LOCATE ix, 80: PRINT CHR$(186)
  406.         NEXT ix
  407.         LOCATE 7, 2: PRINT STRING$(78, 205)
  408.         LOCATE 7, 1: PRINT CHR$(200): LOCATE 7, 80: PRINT CHR$(188)
  409.         LOCATE 4, 30: PRINT "Main System Menu"
  410.         LOCATE 4, 63: PRINT "Date ": LOCATE 4, 68: PRINT DATE$
  411.         LOCATE 4, 4: PRINT "Virsion 1.0"
  412.  
  413.  
  414.  
  415. REM ***************************************************************************
  416. REM **** printes in system erros **********************************************
  417. REM ***************************************************************************
  418. SUB sprintserrors (se)
  419.         CLS
  420.         SCREEN 0
  421.         IF se = "" THEN se = "INVALID RESPONSE"
  422.         itemp = LEN(se)
  423.         itemp1 = 40 - (itemp / 2)
  424.         BEEP
  425.         COLOR 16, 7
  426.         'COLOR Yellow, Blue
  427.         LOCATE 25, itemp1: _BLINK ON: PRINT se;
  428.         Delay 1.5
  429.         _BLINK OFF
  430.         $COLOR:0
  431.         iflag2 = 1
  432. REM ***************************************************************************
  433.  
  434. REM *****************************************************************************
  435. REM **** numeric input sub ******************************************************
  436. REM *****************************************************************************
  437. SUB snumeric (sr, ilow, ihigh)
  438.  
  439.         ftemp = VAL(sr)
  440.         IF ftemp < ilow OR ftemp > ihigh THEN
  441.                 se = "INPUT OUT OF BOUNDS"
  442.                 CALL sprintserrors(se)
  443.         END IF
  444.  
  445. REM ***************************************************************************
  446.  
  447. REM ***************************************************************************
  448. REM **** alpha input sub ******************************************************
  449. REM ***************************************************************************
  450. SUB salphainput (saction, ib, ilow, ihigh, iflag1)
  451.  
  452.         iflag2 = 0
  453.         ilength1 = LEN(sr)
  454.         ilength2 = LEN(saction) + 2
  455.  
  456.         LOCATE 23, 1: PRINT saction; '               prints action menu
  457.         LOCATE 23, ilength2 '                        set prompt one space after action menu print
  458.         COLOR Yellow, Black: PRINT SPC(ib); '                changes color and prints ib spaces to screen for input lenght
  459.         LOCATE 23, ilength2 '                        sets curser at the begining of input space from previouse line
  460.         LINE INPUT sr: sr = UCASE$(sr) '             inputs data from user changes it to upper case
  461.  
  462.         IF LEN(sr) > ib THEN
  463.                 se = "ENVALID INPUT LENGTH"
  464.                 CALL sprintserrors(se)
  465.                 sr = ""
  466.                 iflag2 = 1
  467.         END IF
  468.         IF iflag1 = 1 AND sr = "X" THEN iflag1 = 0
  469.         IF iflag1 = 1 AND VAL(sr) < ilow AND VAL(sr) > ihigh THEN CALL snumeric(sr, ilow, ihigh)
  470.  
  471.         COLOR White, Blue
  472.  
  473.  
  474. REM ***************************************************************************
  475. REM **** main menu to the screen **********************************************
  476. REM ***************************************************************************
  477. SUB printmain
  478.         COLOR White, Blue
  479.         FOR ix = 11 TO imenu
  480.                 READ smenu(ix): LOCATE ix, 20: PRINT smenu(ix)
  481.         NEXT ix
  482.  
  483.         LOCATE 11, 15: PRINT smenu(1)
  484.         LOCATE 11, 40: PRINT smenu(2)
  485.         LOCATE 13, 15: PRINT smenu(3)
  486.         LOCATE 13, 40: PRINT smenu(4)
  487.  
  488. REM ***************************************************************************
  489.  
  490. REM ***************************************************************************
  491. REM **** array data goes here *************************************************
  492. REM ***************************************************************************
  493.  
  494. SUB Delay (dlay!)
  495.         start! = TIMER
  496.         DO WHILE start! + dlay! >= TIMER
  497.                 IF start! > TIMER THEN start! = start! - 86400
  498.         LOOP
  499.  
  500. REM ***************************************************************************
  501.  
  502. REM ***************************************************************************
  503. REM **** menu prompts start here **********************************************
  504. REM ***************************************************************************
  505. SUB mainmenuchoice
  506.         ib = 1
  507.         ihigh = 99
  508.         ilow = 1
  509.         saction = "Choose Menu Option or X to Quit "
  510.         CALL salphainput(saction, ib, ilow, ihigh, iflag1)
  511. REM ***************************************************************************
  512.  
  513. REM ***************************************************************************
  514. REM **** clean up the prompt area *********************************************
  515. REM ***************************************************************************
  516.  
  517. SUB clearprompt
  518.         LOCATE 23, 1: PRINT STRING$(79, 32)
  519.  
  520. REM ***************************************************************************
  521.  
  522.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #3 on: September 29, 2020, 12:32:23 pm »
Yes! Much better!

Not seeing a loop here:
Code: QB64: [Select]
  1. menuloop:
  2. CALL systemheader
  3. CALL printmain
  4. CALL mainmenuchoice
  5. IF sr = "" OR sr = CHR$(13) THEN GOTO menuloop
  6. IF sr = "X" THEN END
  7. 'IF sr = "1" THEN CALL custinfo: 'GOSUB custinfo1
  8. IF sr = "1" THEN
  9.     CALL promptid
  10.     CALL promptfname
  11.     CALL promptlname
  12.     CALL promptaddress
  13.     CALL promptcity
  14.     CALL promptsstate
  15.     CALL promptszip
  16.     CALL promptphone
  17.     RETURN ' <<<<<<<<<<<<<<<<<<<<<<< this is trouble!
  18.  
  19. 's0:
  20. SUB custinput
  21.  

How are you coming back from SUB calls and looping around for menu again?
A simple
Code: QB64: [Select]
  1. GOTO menuloop
would do it, just before the first SUB.

BTW you don't have to CALL a sub, the sub name will do it.


Update: O hell now I see you put that dang mainLoop in a GOSUB, missed this
Code: QB64: [Select]
  1. IF se = "X" THEN END
  2. GOSUB menuloop:  ' <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< oh here it is
  3. REM ***************************************************************************
  4. REM **** main menu LOOP *******************************************************
  5. REM

Well pooh, who puts the mainloop in a GOSUB?
« Last Edit: September 29, 2020, 02:33:18 pm by bplus »

Offline MelliLewis

  • Newbie
  • Posts: 1
    • View Profile
Re: memory leak and question
« Reply #4 on: September 29, 2020, 12:39:58 pm »
Hello...There are various wellsprings of memory spills. The utilization of strings is one. An instructional exercise on all memory spill issues would take what might be compared to a section in an Intro to DXL book.

String source memory holes can be diminished yet not disposed of by utilizing cushions. It is significant when utilizing supports to abstain from string link when adding string factors to the cushion. For instance if S1, S2 and S3 are string factors and buText is a support, don't do the accompanying to connect the strings.

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #5 on: September 29, 2020, 12:43:17 pm »
Hello

i will try that i have other things to do off the main menu but i can always go back to the main by goto as well

Badger

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #6 on: September 29, 2020, 12:44:59 pm »
Code: QB64: [Select]
  1.     CALL promptid
  2.     CALL promptfname
  3.     CALL promptlname
  4.     CALL promptaddress
  5.     CALL promptcity
  6.     CALL promptsstate
  7.     CALL promptszip
  8.     CALL promptphone
  9.  

You have this code so fragmented and broken up, that it is way more complex than need be.

The above code can just be one or two screens of INPUT lines, one sub routine!

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #7 on: September 29, 2020, 12:50:36 pm »
Hello

I think i understand what you are trying to say. but i only use one input statement then set conditions on each prompt

Badger

this was the way i was taught. This is also the first time of using subs i can to this much easier with gosubs and gotos


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #8 on: September 29, 2020, 12:59:26 pm »
Well I appreciate the fact you are trying to use SUBs for first time but you can write a Customer Data Entry Form with 1 SUB in about 50 lines.

You just want to get all this into a customer record:
Code: QB64: [Select]
  1. TYPE customer
  2.     id AS LONG
  3.     sfirst_name AS STRING * 25
  4.     slast_name AS STRING * 25
  5.     saddress AS STRING * 30
  6.     scity AS STRING * 25
  7.     sstate AS STRING * 2
  8.     szip AS STRING * 5
  9.     sphone AS STRING * 10
  10.  

Correct?

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #9 on: September 29, 2020, 01:02:28 pm »
Hello

yes that is correct then the next step is into a random file

Phil

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #10 on: September 29, 2020, 01:16:35 pm »
Imagine how one SUB can take over screen and get all this info and return a Customer Record:

Code: QB64: [Select]
  1. SUB GetCustomerInfo(custRecord as Customer)
  2. DIM rec as Customer
  3.  
  4. PRINT " Customer Data Form:"
  5. INPUT "Enter customer first name "; rec.name_first
  6. INPUT "Enter customer last name "; rec.name_last
  7. ...
  8.  
  9. 'rec.id   ' probably assigned according to record number so leave black and fill in later
  10.  
  11. custRecord = rec ' Sub passes custRec back to main caller code

As time goes on you can refine this very crude input form with checks and nice formatting. I would just get a crude outline working first.
« Last Edit: September 29, 2020, 01:24:53 pm by bplus »

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #11 on: September 29, 2020, 01:27:39 pm »
hello

Let me ask this.. if you mess up on one of the input statements how do you go back up to that statement. with gotos and gosubs that is easy with the way you are explaining you would have to start all over to do that... All the same can you send me a small code snipit on doing what you are suggesting. Please

thanks in advance
Badger

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #12 on: September 29, 2020, 01:34:46 pm »
The beauty of INPUT is that before you press Enter to move on you can check what you wrote, but yes surely there will be a screw up any way!

So before you exit the sub you can confirm the whole record is good to send back to main code or eh... start over is definitely easiest but who wants that?

OK I will work on data Entry Form, I had a nice generic one made with EDIT way, way back in 90's with QB4.5

But go ahead and try a crude one as I suggest so you can get to work on saving data to file and loading a records view or making queries or getting on with the whole of the thing. Get that working good then refine later.

Customer ID? will that be the same as record number?
« Last Edit: September 29, 2020, 01:41:20 pm by bplus »

Offline badger

  • Forum Regular
  • Posts: 148
    • View Profile
Re: memory leak and question
« Reply #13 on: September 29, 2020, 01:36:30 pm »
Hello

Thanks i want to see that i am willing to learn new tricks i am not that old LOL

Badger

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: memory leak and question
« Reply #14 on: September 29, 2020, 02:42:17 pm »
Apology to badger, sorry I missed the place where GOSUB'd to mainloop in reply #3.

Now the RETURN makes more sense.

I hope I can help show how nice working with SUBs are. But remember one main thing, variable values are private to SUB, what happens in a SUB stays in the SUB unless you DIM SHARE variables in main or pass info in and out through arguments to the SUB (or FUNCTION). This is the main difference between a SUB and a GOSUB.
« Last Edit: September 29, 2020, 02:43:41 pm by bplus »