Author Topic: Problem with CLEAR  (Read 4572 times)

0 Members and 1 Guest are viewing this topic.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Problem with CLEAR
« on: June 23, 2021, 07:44:20 am »
PROBLEM WITH CLEAR

The goal is to implement the possibility, at the end of the program, to restart it from the beginning if the user want to do that, without going SYSTEM end run the program one more time.

Below, there is an extract of the program.

At line 1, a DO LOOP cycle starts and it ends at the end of the main code, at line 227. In lines 222 to 225, an other DO LOOP cycle waits a key press from user that has to be "s" or "n" in order exit this DO LOOP cycle. If it is "n", IF command in line 226 EXIT DO started in line 1, and program goes SYSTEM. IF it is "s", the program loops and goes to line 1.

It works.

But, when the program restarts, I have to clear all variables and arrays. Activating CLEAR command in line 2, the program not even starts! Everywhere I put the command CLEAR, no way the program works. In the help, I sawn that CLEAR has some problems with REDIM. But don't have found solution even moving away DATA.

Code: QB64: [Select]
  1.     '    CLEAR
  2.     CLS
  3.     OPTION BASE 1
  4.     _TITLE "Calcolo dell'idrogramma di piena di progetto tramite il metodo SCS-CN"
  5.  
  6.     TempiRitorno:
  7.     DATA "Definito dall'utente",2,5,10,20,50,100,200,500,1000
  8.     DATA 1,0.82,1.24,1.46,1.69,2.04,2.34,2.70,3.22,3.64
  9.     CoefficientiIdrogrammaUnitarioMockus: 'dati dell'idrogramma unitario di Mockus
  10.     DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  11.     DATA 0.03,0.1,0.19,0.31,0.47,0.66,0.82,0.93,0.99,1,0.99,0.93,0.86,0.78,0.68,0.56,0.46,0.39,0.33,0.28,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.04,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0: ' t/tp
  12.     CoefficientiDiscretizzazioneTemporale:
  13.     DATA 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32: 'N volte tc!.
  14.     DATA 0.1,0.2,0.3,0.2,0.3,0.3,0.3,0.3,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,1,1,1,1,1,1: 'discretizzazione dei coeff. di Mockus.
  15.  
  16.     TYPE mockus
  17.         tSUta AS SINGLE
  18.         qSUqp AS SINGLE
  19.     END TYPE
  20.     TYPE CoefficientiDiscretizzazioneTemporale
  21.         N AS INTEGER
  22.         d AS SINGLE
  23.         tSUta AS SINGLE
  24.     END TYPE
  25.     TYPE TempiRitorno
  26.         T AS STRING
  27.         k AS SINGLE
  28.     END TYPE
  29.     TYPE matrice1
  30.         mdt AS SINGLE '[ore] conta la progessione delle ore fino al raggiungimento di "d".
  31.         h1 AS SINGLE '[mm] DisegnaValore h della curva di possibilità climatica.
  32.         i1 AS SINGLE '[mm/ora] intensità di pioggia.
  33.         i2 AS SINGLE '[mm/ora] intensità di pioggia secondo lo ietogramma Chicago o costante.
  34.         DH AS SINGLE '[mm] pioggia in ogni istante temporale dt.
  35.         H2 AS SINGLE '[mm] pioggia cumulata ad ogni istante temporale.
  36.         he AS SINGLE '[mm] piggia efficace cumulata ad ogni istante temporale.
  37.         Dhe AS SINGLE '[mm] pioggia efficace ad ogni istante temporale.
  38.         tSUta AS SINGLE
  39.         qSUqp AS SINGLE
  40.         tmSUta AS SINGLE '[-].
  41.         qmSUqp AS SINGLE '[-] il DisegnaValore di qm/qp corrispondente a tm/ta e' = al DisegnaValore di q/qp che corrisponde a t/ta=tm/ta.
  42.         qm AS SINGLE '[mc/s].
  43.     END TYPE
  44.     TYPE idrogramma
  45.         i AS INTEGER
  46.         ore AS SINGLE
  47.         portata AS SINGLE
  48.     END TYPE
  49.     TYPE composizione
  50.         grafico AS LONG
  51.         composizione AS LONG
  52.     END TYPE
  53.  
  54.     CONST R& = _RGB32(255, 0, 0)
  55.     CONST G& = _RGB32(0, 255, 0)
  56.     CONST B& = _RGB32(0, 0, 255)
  57.     CONST bianco& = _RGB32(255, 255, 255)
  58.     CONST giallo& = _RGB32(255, 255, 0)
  59.     CONST grigio& = _RGB32(127, 127, 127)
  60.     CONST azzurro& = _RGB32(0, 255, 255)
  61.     CONST pastello& = _RGB32(183, 150, 139)
  62.     CONST viola& = _RGB32(255, 0, 255)
  63.     CONST trasparente& = _RGB32(0, 0)
  64.     CONST LarghezzaColonna% = 8
  65.  
  66.     DIM SHARED idrogrammi1a24(2, 24, 50, 1) AS idrogramma
  67.     DIM SHARED MassimiIdrogrammi1a24(2, 24, 1) AS idrogramma
  68.     DIM SHARED FinePioggiaIdrogrammi1a24(2, 24, 1) AS idrogramma ' per ogniidrogrammi1a24( trova il momento di Durata della pioggia.
  69.     DIM SHARED i%, n%, z%, ieto%, VisualizzaIeto%
  70.     DIM SHARED ore!(3), portata!(3) 'ore e portate di picco dell'idrogramma di progetto e scelto (entrambi interpolati).
  71.     DIM SHARED tipo% '1:idrogrammi1a24( di progetto. 2: a ascelta. Entrambi interpolati.
  72.     DIM SHARED MassimiAssolutiIeto(2) AS idrogramma
  73.     DIM SHARED IdroMaxIeto%(2) 'memorizza l'idrogramma con la portata di picco massima (che per lo ietogramma chicago è sempre l'ultimo), in modo da definire l'idrogramma di progetto quando la soglia di progetto e' troppo bassa.
  74.     DIM SHARED FinePioggiaIdrogrammi1e2(2) AS idrogramma 'serve a memorizzare l'ora e la portata in cui termina la pioggia.
  75.     DIM SHARED PassiFinePioggia1a24%(2, 24)
  76.     DIM SHARED L%, H%
  77.     DIM SHARED CoefficientiDiscretizzazioneTemporale(24) AS CoefficientiDiscretizzazioneTemporale
  78.     DIM SHARED TempiRitorno(10) AS TempiRitorno
  79.     DIM SHARED T$
  80.     DIM SHARED KeyPress$
  81.  
  82.     REDIM SHARED IdroPixel1(1) AS idrogramma
  83.     REDIM SHARED IdroPixel2(1) AS idrogramma
  84.     REDIM SHARED idrogramma1(1) AS idrogramma 'idrogramma di progetto.
  85.     REDIM SHARED idrogramma2(1) AS idrogramma 'idrogramma a scelta.
  86.  
  87.     DIM FineColonna%(8)
  88.     DIM esci$
  89.     DIM esci%(2)
  90.     DIM schermo&
  91.     DIM ComplessivoIeto1e2(2) AS composizione
  92.     DIM idrogramma1e2(2) AS composizione
  93.     DIM graficoCOPIA&
  94.     DIM quadro&
  95.     DIM unitari&
  96.     DIM MatriciIeto1e2(2, 24)
  97.     DIM mockus(50) AS mockus
  98.     DIM dt!(2, 24)
  99.     DIM matrice1(2, 24, 50, 1) AS matrice1
  100.     DIM matrice2!(2, 24, 50, 50)
  101.     DIM MinimiMatriciQuadrante1(2, 24, 1) AS idrogramma 'riferito all'idrogramma
  102.     DIM MinimiMatriciQuadrante2(2, 24, 1) AS idrogramma 'riferito all'idrogramma unitario
  103.     DIM MassimiQuadrante2(2, 24, 1) AS idrogramma 'riferito all'idrogramma unitario
  104.     DIM test%
  105.     DIM CoeffPerditeIniziali!
  106.     DIM S2! '[mm] contenuto idrico massimodel terreno.
  107.     DIM Ia! '[mm] perdite iniziali.
  108.     DIM tc! '[ore] tempo di corrivazione
  109.     DIM ta! '[ore] tempo di picco.
  110.     DIM qp! '[mc/s] portata al colmo dell'idrogramma unitario.
  111.     DIM k! '[-] coeff. della curva di possibilità climatica tado dal sito della Regione.
  112.     DIM a1! '[mm/d^n] coeff. della curva di possibilità climatica.
  113.     DIM n1! '[-] coeff. della curva di possibilità climatica.
  114.     DIM A2! '[mq] superficie bacino idrografico.
  115.     DIM L! '[m] lunghezza asta principale.
  116.     DIM HmaxL! '[m] punto più alto dell'astra principale.
  117.     DIM HminL! '[m] punto più basso dell'asta principale.
  118.     DIM s1! '[-] pendenza media del bacino non espressa in percentuale ma come 0,x.
  119.     DIM CNII! '[-] Intestazioneto.
  120.     DIM CNIII '[-] discende da CNII.
  121.     DIM tl! '[ore] tempo di ritardo.
  122.  
  123.     RESTORE TempiRitorno
  124.     FOR i% = 1 TO 20
  125.         IF i% <= 10 THEN READ TempiRitorno(i%).T
  126.         IF i% > 10 THEN READ TempiRitorno(i% - 10).k
  127.     NEXT i%
  128.     RESTORE CoefficientiIdrogrammaUnitarioMockus
  129.     FOR i% = 1 TO 100
  130.         IF i% <= 50 THEN READ mockus(i%).tSUta
  131.         IF i% > 50 THEN READ mockus(i% - 50).qSUqp
  132.     NEXT i%
  133.     L% = _DESKTOPWIDTH - 20: H% = L% \ 1.62 'imposta la larghezza dello SCREEN in modo che L%xH% sia un rettangolo aureo.
  134.     FOR ieto% = 1 TO 2
  135.         ComplessivoIeto1e2(ieto%).grafico = _NEWIMAGE(L% - (L% \ 5), H%, 32)
  136.         ComplessivoIeto1e2(ieto%).composizione = _NEWIMAGE(L%, H%, 32)
  137.         idrogramma1e2(ieto%).grafico = _NEWIMAGE(L% - (L% \ 4), H%, 32)
  138.         idrogramma1e2(ieto%).composizione = _NEWIMAGE(L%, H%, 32)
  139.         FOR z% = 1 TO 24
  140.             MatriciIeto1e2(ieto%, z%) = _NEWIMAGE(L%, H%, 32)
  141.         NEXT z%
  142.     NEXT ieto%
  143.     quadro& = _NEWIMAGE(L% \ 2, H% \ 2, 32)
  144.     unitari& = _NEWIMAGE(L%, H%, 32)
  145.     schermo& = _NEWIMAGE(_DESKTOPWIDTH, _DESKTOPHEIGHT, 32)
  146.     esci$ = "I dati forniti non determinano pioggia efficace o questa Š tale da comportare portate trascurabili."
  147.     SCREEN schermo&
  148.     _SCREENMOVE 0, 0
  149.     PRINT "Questo programma serve a calcolare l'idrogramma di progetto (e relativa portata di picco) per"
  150.     PRINT "un  dato  tempo  di  ritorno,  utilizzando  l'idrogramma  unitario  adimensionale di Mockus e"
  151.     PRINT "ietrogrammi tipo "; CHR$(34); "Chicago"; CHR$(34); " o "; CHR$(34); "costanti"; CHR$(34); "."
  152.     PRINT
  153.     PRINT "Di seguito si dovranno inserire i valori della curva di possibilit… climatica "; CHR$(34); "h = Ktúaúd^n"; CHR$(34); "."
  154.     PRINT "Se  si dispone  dei valori  del Centro  Funzionale, digitare il valore "; CHR$(34); "Kt"; CHR$(34); " relativo al tempo"
  155.     PRINT "di ritorno "; CHR$(34); "T"; CHR$(34); " d'interesse, con i relativi valori "; CHR$(34); "a"; CHR$(34); " e "; CHR$(34); "n"; CHR$(34); "."
  156.     PRINT "Se invece si ha una  propria curva di possibilit… climatica, quando verr… chiesto di inserire"
  157.     PRINT CHR$(34); "Kt"; CHR$(34); ", digitare "; CHR$(34); "INVIO"; CHR$(34); ", o "; CHR$(34); "1"; CHR$(34); "."
  158.     PRINT "In tal caso "; CHR$(34); "Kt"; CHR$(34); " sar… considerato pari a "; CHR$(34); "1"; CHR$(34); " e "; CHR$(34); "T"; CHR$(34); " come "; CHR$(34); "definito dall'utente"; CHR$(34); "."
  159.     PRINT
  160.     PRINT "- Kt [-] (INVIO per 1)                                           = "
  161.     PRINT "- a [mm/d^n]                                                     = "
  162.     PRINT "- n [-] (0ö1)                                                    = "
  163.     PRINT "- Area del bacino idrografico [mý]                               = "
  164.     PRINT "- Lunghezza dell'asta principale del bacino idrografico [m]      = "
  165.     PRINT "- Altitudine s.l.m. del punto pi— alto dell'asta principale [m]  = "
  166.     PRINT "- Altitudine s.l.m. del punto pi— basso dell'asta principale [m] = "
  167.     PRINT "- Pendenza media del bacino idrografico [%] (1ö100)              = "
  168.     PRINT "- CN(II) [-] (1ö100)                                             = "
  169.     PRINT "- Coefficiente delle perdite inziali [-] (0ö0.2 - INVIO per 0.1) = "
  170.     CALL InserimentoDati(k!, a1!, n1, A2!, L!, HmaxL!, HminL!, s1!, CNII!, CoeffPerditeIniziali!)
  171.     LOCATE PosizioneCursore% + 10, 1
  172.     PRINT "- Visualizzare i risultati utilizzando lo ietogramma Chicago [1] o costante [2]?"
  173.     PRINT
  174.     DO
  175.         _LIMIT 50
  176.         KeyPress$ = INKEY$
  177.     LOOP UNTIL KeyPress$ = "1" OR KeyPress$ = "2"
  178.     VisualizzaIeto% = VAL(KeyPress$)
  179.     CNIII! = (23 * CNII!) / (10 + 0.13 * CNII!)
  180.     tl! = 0.342 * ((L! / 1000) ^ 0.8 / s1! ^ 0.5) * (1000 / CNIII! - 9) ^ 0.7 'formula di Mockus.
  181.     S2! = 25.4 * (1000 / CNIII! - 10)
  182.     Ia! = CoeffPerditeIniziali! * S2! 'coeff.=0.03-0.2. 'perdite iniziali
  183.     tc! = tl! / 0.6
  184.     ta! = tl! / 0.9
  185.     qp! = 0.208 * ((A2! / 1000000) / ta!)
  186.     RESTORE CoefficientiDiscretizzazioneTemporale
  187.     FOR i% = 1 TO 48
  188.         IF i% <= 24 THEN READ CoefficientiDiscretizzazioneTemporale(i%).N: CoefficientiDiscretizzazioneTemporale(i%).d = CoefficientiDiscretizzazioneTemporale(i%).N * tc!
  189.         IF i% > 24 THEN READ CoefficientiDiscretizzazioneTemporale(i% - 24).tSUta
  190.     NEXT i%
  191.  
  192.     'FOR ieto% = 1 TO 2
  193.     '    FOR z% = 1 TO 24
  194.     '        GOSUB CalcolaMatriciIeto1e2
  195.     '        IF esci%(ieto%) = 0 THEN GOSUB DisegnaMatriciIeto1e2
  196.     '    NEXT z%
  197.     '    IF esci%(ieto%) = 0 THEN GOSUB DisegnaComplessivoIeto1e2
  198.     'NEXT ieto%
  199.     '_DEST schermo&
  200.     'SELECT CASE esci%(VisualizzaIeto%)
  201.     '    CASE IS = 0
  202.     '        CLS
  203.     '        GOSUB DisegnaUnitari
  204.     '        GOSUB VisualizzaComplessivo
  205.     '        SLEEP
  206.     '        CALL CalcolaIdrogramma(MassimiIdrogrammi1a24(VisualizzaIeto%, 24, 1).ore, idrogrammi1a24(VisualizzaIeto%, 24, 50, 1).ore, MassimiAssolutiIeto(VisualizzaIeto%).ore, MassimiAssolutiIeto(VisualizzaIeto%).portata, ComplessivoIeto1e2(VisualizzaIeto%).grafico, ComplessivoIeto1e2(VisualizzaIeto%).composizione, graficoCOPIA&)
  207.     '        SLEEP
  208.     '        GOSUB DisegnaIdrogramma
  209.     '        GOSUB VisualizzaIdrogramma
  210.     '        SLEEP
  211.     '        GOSUB VisualizzaUnitari
  212.     '        GOSUB VisualizzaMatrici
  213.     '    GOSUB Risultati
  214.     '    CASE IS = 1
  215.     '        PRINT esci$
  216.     'END SELECT
  217.     GOSUB freeimage
  218.     PRINT
  219.     PRINT "- Riavviare il programma? [S/N]"
  220.     DO
  221.         _LIMIT 50
  222.         KeyPress$ = LCASE$(INKEY$)
  223.     LOOP UNTIL KeyPress$ = "s" OR KeyPress$ = "n"
  224.     IF KeyPress$ = "n" THEN EXIT DO
  225. '---------------------------------------------------------------------------------------------------------------------------------------------------
  226. freeimage:
  227. FOR ieto% = 1 TO 2
  228.     _FREEIMAGE ComplessivoIeto1e2(ieto%).grafico
  229.     _FREEIMAGE ComplessivoIeto1e2(ieto%).composizione
  230.     _FREEIMAGE idrogramma1e2(ieto%).grafico
  231.     _FREEIMAGE idrogramma1e2(ieto%).composizione
  232.     FOR z% = 1 TO 24
  233.         _FREEIMAGE MatriciIeto1e2(ieto%, z%)
  234.     NEXT z%
  235.     '    IF esci%(ieto%) = 0 THEN _FREEIMAGE graficoCOPIA&
  236. NEXT ieto%
  237. _FREEIMAGE unitari&
  238. _FREEIMAGE quadro&
  239.  
  240.  
  241. '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  242. SUB InserimentoDati (k!, a1!, n1, A2!, L!, HmaxL!, HminL!, s1!, CNII!, CoeffPerditeIniziali!)
  243.  
  244.     SHARED PosizioneCursore%
  245.  
  246.     DIM inputs$(10)
  247.     DIM richiesta%
  248.     DIM test%(10)
  249.     DIM debug%
  250.     DIM carattere$
  251.     DIM punti%
  252.     DIM T!
  253.     DIM cursore%
  254.     DIM esci%
  255.  
  256.     PosizioneCursore% = CSRLIN - 10
  257.     richiesta% = 1
  258.     T! = TIMER
  259.     DO
  260.         _LIMIT 30
  261.         KeyPress$ = INKEY$
  262.         IF TIMER > T! + 0.5 THEN
  263.             cursore% = NOT cursore%
  264.             T! = TIMER
  265.         END IF
  266.         FOR i% = 1 TO 10
  267.             LOCATE PosizioneCursore% - 1 + i%, 68: PRINT inputs$(i%) + SPACE$(30)
  268.         NEXT i%
  269.         LOCATE PosizioneCursore% - 1 + richiesta%, 68 + LEN(inputs$(richiesta%))
  270.         IF debug% = 1 THEN EXIT SUB
  271.         IF esci% = 1 THEN EXIT DO
  272.         IF cursore% THEN PRINT "_"
  273.         SELECT CASE KeyPress$
  274.             CASE CHR$(44), CHR$(46) ',e.
  275.                 punti% = 0
  276.                 IF KeyPress$ = CHR$(44) THEN KeyPress$ = CHR$(46)
  277.                 FOR n% = 1 TO LEN(inputs$(richiesta%))
  278.                     carattere$ = MID$(inputs$(richiesta%), n%, 1)
  279.                     IF carattere$ = CHR$(46) THEN punti% = 1
  280.                 NEXT n%
  281.                 IF punti% = 0 THEN inputs$(richiesta%) = inputs$(richiesta%) + KeyPress$
  282.             CASE CHR$(48) TO CHR$(57) '0-9
  283.                 inputs$(richiesta%) = inputs$(richiesta%) + KeyPress$
  284.             CASE CHR$(8) 'del
  285.                 IF LEN(inputs$(richiesta%)) > 0 THEN inputs$(richiesta%) = LEFT$(inputs$(richiesta%), LEN(inputs$(richiesta%)) - 1)
  286.             CASE CHR$(0) + "H" 'su
  287.                 GOSUB Valutavalore
  288.                 SELECT CASE test%(richiesta%)
  289.                     CASE IS = 0
  290.                         inputs$(richiesta%) = ""
  291.                     CASE IS = 1
  292.                         IF richiesta% = 1 THEN
  293.                             EXIT SELECT
  294.                         ELSEIF richiesta <= 10 THEN
  295.                             richiesta% = richiesta% - 1
  296.                         END IF
  297.                 END SELECT
  298.             CASE CHR$(13), CHR$(0) + "P" 'invio
  299.                 IF debug% = 1 THEN EXIT SELECT
  300.                 GOSUB Valutavalore
  301.                 IF richiesta% <> 10 THEN
  302.                     IF KeyPress$ = CHR$(0) + "P" THEN KeyPress$ = CHR$(13)
  303.                 END IF
  304.                 IF richiesta% <> 1 THEN
  305.                     IF LEN(inputs$(richiesta%)) = 0 THEN test%(richiesta%) = 0
  306.                 END IF
  307.                 SELECT CASE test%(richiesta%)
  308.                     CASE IS = 0
  309.                         inputs$(richiesta%) = ""
  310.                     CASE IS = 1
  311.                         IF richiesta% = 10 THEN
  312.                             IF KeyPress$ = CHR$(0) + "P" THEN
  313.                                 EXIT SELECT
  314.                             ELSE
  315.                                 esci% = 1
  316.                             END IF
  317.                         ELSE
  318.                             richiesta% = richiesta% + 1
  319.                         END IF
  320.                 END SELECT
  321.         END SELECT
  322.     LOOP
  323.     k! = VAL(inputs$(1)): a1! = VAL(inputs$(2)): n1! = VAL(inputs$(3)): A2! = VAL(inputs$(4)): L! = VAL(inputs$(5)): HmaxL! = VAL(inputs$(6)): HminL! = VAL(inputs$(7)): s1! = VAL(inputs$(8)): CNII! = VAL(inputs$(9)): CoeffPerditeIniziali! = VAL(inputs$(10))
  324.     EXIT SUB
  325.     '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  326.     Valutavalore:
  327.     test%(richiesta%) = 0 ' se 0 rimane nella richiesta in corso, se 1, cambia.
  328.  
  329.     SELECT CASE richiesta%
  330.         CASE 1
  331.             IF inputs$(richiesta%) = "123" THEN 'avvia debug
  332.                 debug% = 1
  333.                 'test:
  334.                 'k! = 2.34: a1! = 1: n1! = 0.45596: A2! = 0: L! = 3300: HmaxL! = 1981: HminL! = 1062: s1! = 41.5: CNII! = 70: CoeffPerditeIniziali! = 0.1
  335.                 'Cillian:
  336.                 k! = 2.34: a1! = 14.6653: n1! = 0.45596: A2! = 2641902: L! = 3300: HmaxL! = 1981: HminL! = 1062: s1! = 41.5: CNII! = 70: CoeffPerditeIniziali! = 0.1
  337.                 'pialong:
  338.                 'k! = 2.34:'a1! = 17.097811:'n1! = 0.497753:'A2! = 2509318:'L! = 2919:'HmaxL! = 1654:'HminL! = 388:'s1! = 0.663:'CNII! = 66:CoeffPerditeIniziali!=0.1
  339.                 GOSUB TrovaT
  340.                 RETURN
  341.             END IF
  342.             IF LEN(inputs$(richiesta%)) = 0 THEN
  343.                 IF KeyPress$ = CHR$(13) THEN inputs$(richiesta%) = "1"
  344.             END IF
  345.             GOSUB TrovaT
  346.             IF KeyPress$ = CHR$(0) + "P" THEN
  347.                 IF LEN(inputs$(richiesta%)) = 0 THEN test%(richiesta%) = 0
  348.             END IF
  349.         CASE 2, 4, 5, 6, 7
  350.             test%(richiesta%) = 1
  351.         CASE 3
  352.             IF VAL(inputs$(richiesta%)) <= 1 THEN
  353.                 test%(richiesta%) = 1
  354.             ELSE
  355.                 test%(richiesta%) = 0
  356.             END IF
  357.         CASE 8, 9
  358.             IF VAL(inputs$(richiesta%)) >= 1 THEN
  359.                 IF VAL(inputs$(richiesta%)) <= 100 THEN test%(richiesta%) = 1
  360.             ELSEIF inputs$(richiesta%) = "" THEN test%(richiesta%) = 1
  361.             ELSE
  362.                 test%(richiesta%) = 0
  363.             END IF
  364.         CASE IS = 10
  365.             IF LEN(inputs$(richiesta%)) = 0 THEN
  366.                 IF KeyPress$ = CHR$(13) THEN inputs$(richiesta%) = "0.1"
  367.                 test%(richiesta%) = 1
  368.                 EXIT SELECT
  369.             END IF
  370.             IF VAL(inputs$(richiesta%)) >= 0 THEN
  371.                 IF VAL(inputs$(richiesta%)) <= 0.2 THEN
  372.                     IF KeyPress$ = CHR$(0) + "P" THEN
  373.                         test%(richiesta%) = 1
  374.                     ELSE
  375.                         test%(richiesta%) = 1
  376.                     END IF
  377.                 ELSE
  378.                     test%(richiesta%) = 0
  379.                 END IF
  380.             END IF
  381.     END SELECT
  382.     RETURN
  383.     '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  384.     TrovaT:
  385.     i% = 1
  386.     '    IF debug% <> 1 THEN k! = VAL(inputs$(1))
  387.     FOR i% = 1 TO 10
  388.         IF VAL(inputs$(1)) = TempiRitorno(i%).k THEN
  389.             IF i% = 1 THEN
  390.                 T$ = TempiRitorno(i%).T
  391.                 test%(richiesta%) = 1
  392.             ELSE
  393.                 T$ = TempiRitorno(i%).T + " anni"
  394.                 test%(richiesta%) = 1
  395.             END IF
  396.             EXIT FOR
  397.         ELSE
  398.             test%(richiesta%) = 0
  399.         END IF
  400.     NEXT i%
  401.     RETURN
  402.  
« Last Edit: June 23, 2021, 07:46:44 am by bartok »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with CLEAR
« Reply #1 on: June 23, 2021, 09:14:32 am »
I seem to recall there being an issue with CLEAR causing it to free screen handles? Do you recall, @FellippeHeitor ?
Shuwatch!

FellippeHeitor

  • Guest
Re: Problem with CLEAR
« Reply #2 on: June 23, 2021, 09:50:02 am »
That got fixed in the dev builds. This seems like something else. I'll have a closer look later.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Problem with CLEAR
« Reply #3 on: June 23, 2021, 10:12:59 am »
@bartok

Can you provide some test data? I don't understand the language and don't know what it expects as input. Also, I don't think you need your freeimage subroutine since CLEAR already frees all valid images.
« Last Edit: June 23, 2021, 10:41:48 am by SpriggsySpriggs »
Shuwatch!

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem with CLEAR
« Reply #4 on: June 23, 2021, 11:38:07 am »
@bartok

[...] Also, I don't think you need your freeimage subroutine since CLEAR already frees all valid images.

I posted a question about that some time ago, just asking why Terry Ritchie's tutorials insisted in _FREEIMAGE importance at the end of the main code, if a simple CLEAR command, should clear all.

It was responded to me something like this: imagines access the video memory and CLEAR doesn't free these memory handles.

@bartok

Can you provide some test data? I don't understand the language and don't know what it expects as input. [...]

Below, the code you have asked for. Reduncing it at the minimum in order to make it clearer, I have found the problem, but it is a mystery!

Enabling command CLEAR in line 2, the program doesn't work and crashes. I works ONLY disabling "RESTORE group 1"...

Changing the text in DATA "Definito dall'utente" with a random number, it still not works.

But besides changing:

    TYPE TempiRitorno
        T AS STRING
        k AS SINGLE
    END TYPE
   
with

    TYPE TempiRitorno
        T AS SINGLE
        k AS SINGLE
    END TYPE

It works.

So, it seems that CLEAR has some problem with TYPE defining STRING or mixed kind of variables.

Code: QB64: [Select]
  1.     CLEAR
  2.     CLS
  3.     OPTION BASE 1
  4.  
  5.  
  6.     TempiRitorno:
  7.     DATA "Definito dall'utente",2,5,10,20,50,100,200,500,1000
  8.     DATA 1,0.82,1.24,1.46,1.69,2.04,2.34,2.70,3.22,3.64
  9.     CoefficientiIdrogrammaUnitarioMockus: 'dati dell'idrogramma unitario di Mockus
  10.     DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  11.     DATA 0.03,0.1,0.19,0.31,0.47,0.66,0.82,0.93,0.99,1,0.99,0.93,0.86,0.78,0.68,0.56,0.46,0.39,0.33,0.28,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.04,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0: ' t/tp
  12.  
  13.     TYPE mockus
  14.         tSUta AS SINGLE
  15.         qSUqp AS SINGLE
  16.     END TYPE
  17.     TYPE TempiRitorno
  18.         T AS STRING
  19.         k AS SINGLE
  20.     END TYPE
  21.     DIM SHARED i%, n%, z%, ieto%, VisualizzaIeto%
  22.     DIM SHARED TempiRitorno(10) AS TempiRitorno
  23.     DIM mockus(50) AS mockus
  24.  
  25.     ' 'RESTORE group 1:
  26.     RESTORE TempiRitorno
  27.     FOR i% = 1 TO 20
  28.         IF i% <= 10 THEN READ TempiRitorno(i%).T
  29.         IF i% > 10 THEN READ TempiRitorno(i% - 10).k
  30.     NEXT i%
  31.  
  32.     ' 'RESTORE group 2:
  33.     RESTORE CoefficientiIdrogrammaUnitarioMockus
  34.     FOR i% = 1 TO 100
  35.         IF i% <= 50 THEN READ mockus(i%).tSUta
  36.         IF i% > 50 THEN READ mockus(i% - 50).qSUqp
  37.     NEXT i%
  38.  
  39.  
  40.     '[...]
  41.     PRINT
  42.     PRINT "- Restart program? [Y/N]"
  43.     DO
  44.         _LIMIT 50
  45.         KeyPress$ = LCASE$(INKEY$)
  46.     LOOP UNTIL KeyPress$ = "y" OR KeyPress$ = "n"
  47.     IF KeyPress$ = "n" THEN EXIT DO
« Last Edit: June 23, 2021, 11:49:12 am by bartok »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with CLEAR
« Reply #5 on: June 23, 2021, 02:53:29 pm »
Seems to me that Type, Const, Shared statements should all be outside of loop.

To restart with everything cleared do that at start of a rerun loop (instead of a Run statement) set everything to 0.

Erase, arrays started with Dim and ReDim dynamic arrays started with Redim.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Problem with CLEAR
« Reply #6 on: June 24, 2021, 12:15:24 am »
Can you nest RUN statements?

What I mean is can you in program A, execute a RUN for program A?

A RUN clears memory of the calling program. The only question is can you do a recursive RUN to the calling program.
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem with CLEAR
« Reply #7 on: June 24, 2021, 02:25:18 am »
Seems to me that Type, Const, Shared statements should all be outside of loop.

It not works:
Code: QB64: [Select]
  1.  
  2.  
  3. TempiRitorno:
  4. DATA "Definito dall'utente",2,5,10,20,50,100,200,500,1000
  5. DATA 1,0.82,1.24,1.46,1.69,2.04,2.34,2.70,3.22,3.64
  6. CoefficientiIdrogrammaUnitarioMockus: 'dati dell'idrogramma unitario di Mockus
  7. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  8. DATA 0.03,0.1,0.19,0.31,0.47,0.66,0.82,0.93,0.99,1,0.99,0.93,0.86,0.78,0.68,0.56,0.46,0.39,0.33,0.28,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.04,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0: ' t/tp
  9.  
  10. TYPE mockus
  11.     tSUta AS SINGLE
  12.     qSUqp AS SINGLE
  13. TYPE TempiRitorno
  14.     T AS STRING
  15.     k AS SINGLE
  16. DIM SHARED i%, n%, z%, ieto%, VisualizzaIeto%
  17. DIM SHARED TempiRitorno(10) AS TempiRitorno
  18. DIM mockus(50) AS mockus
  19.  
  20.     CLEAR
  21.  
  22.     ' 'RESTORE group 1:
  23.     RESTORE TempiRitorno
  24.     FOR i% = 1 TO 20
  25.         IF i% <= 10 THEN READ TempiRitorno(i%).T
  26.         IF i% > 10 THEN READ TempiRitorno(i% - 10).k
  27.     NEXT i%
  28.  
  29.     ' 'RESTORE group 2:
  30.     RESTORE CoefficientiIdrogrammaUnitarioMockus
  31.     FOR i% = 1 TO 100
  32.         IF i% <= 50 THEN READ mockus(i%).tSUta
  33.         IF i% > 50 THEN READ mockus(i% - 50).qSUqp
  34.     NEXT i%
  35.  
  36.  
  37.     '[...]
  38.     PRINT
  39.     PRINT "- Restart program? [Y/N]"
  40.     DO
  41.         _LIMIT 50
  42.         KeyPress$ = LCASE$(INKEY$)
  43.     LOOP UNTIL KeyPress$ = "y" OR KeyPress$ = "n"
  44.     IF KeyPress$ = "n" THEN EXIT DO
  45.  

However, in this way I have solved:

Code: QB64: [Select]
  1.     CLEAR
  2.  
  3.     CLS
  4.     OPTION BASE 1
  5.  
  6.  
  7.     TempiRitorno:
  8.     DATA 0,2,5,10,20,50,100,200,500,1000: '------------------------------------------------------>removed text end changed with "0".
  9.     DATA 1,0.82,1.24,1.46,1.69,2.04,2.34,2.70,3.22,3.64
  10.     CoefficientiIdrogrammaUnitarioMockus: 'dati dell'idrogramma unitario di Mockus
  11.     DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  12.     DATA 0.03,0.1,0.19,0.31,0.47,0.66,0.82,0.93,0.99,1,0.99,0.93,0.86,0.78,0.68,0.56,0.46,0.39,0.33,0.28,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.04,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0: ' t/tp
  13.  
  14.     TYPE mockus
  15.         tSUta AS SINGLE
  16.         qSUqp AS SINGLE
  17.     END TYPE
  18.     TYPE TempiRitorno
  19.         T AS SINGLE '-------------------------------------------------------------------------->changed STRING to SINGLE
  20.         k AS SINGLE
  21.     END TYPE
  22.     DIM SHARED i%, n%, z%, ieto%, VisualizzaIeto%
  23.     DIM SHARED TempiRitorno(10) AS TempiRitorno
  24.     DIM mockus(50) AS mockus
  25.  
  26.  
  27.     ' 'RESTORE group 1:
  28.     RESTORE TempiRitorno
  29.     FOR i% = 1 TO 20
  30.         IF i% <= 10 THEN READ TempiRitorno(i%).T
  31.         IF i% > 10 THEN READ TempiRitorno(i% - 10).k
  32.     NEXT i%
  33.  
  34.     ' 'RESTORE group 2:
  35.     RESTORE CoefficientiIdrogrammaUnitarioMockus
  36.     FOR i% = 1 TO 100
  37.         IF i% <= 50 THEN READ mockus(i%).tSUta
  38.         IF i% > 50 THEN READ mockus(i% - 50).qSUqp
  39.     NEXT i%
  40.  
  41.  
  42.     '[...]
  43.     PRINT
  44.     PRINT "- Restart program? [Y/N]"
  45.     DO
  46.         _LIMIT 50
  47.         KeyPress$ = LCASE$(INKEY$)
  48.     LOOP UNTIL KeyPress$ = "y" OR KeyPress$ = "n"
  49.     IF KeyPress$ = "n" THEN EXIT DO
  50.  

I suppose there is a bug in CLEAR command:
with

    TYPE TempiRitorno
        T AS STRING
        k AS SINGLE
    END TYPE

program crashes. Same thing with:

    TYPE TempiRitorno
        T AS STRING
        k AS STRING
    END TYPE

It works only with:

    TYPE TempiRitorno
        T AS SINGLE
        k AS SINGLE
    END TYPE


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with CLEAR
« Reply #8 on: June 24, 2021, 07:04:39 am »
Quote
It not works:

I was suggesting a work around CLEAR, clear the things manually without CLEAR.
Code: QB64: [Select]
  1.  
  2.  
  3. TempiRitorno:
  4. DATA "Definito dall'utente",2,5,10,20,50,100,200,500,1000
  5. DATA 1,0.82,1.24,1.46,1.69,2.04,2.34,2.70,3.22,3.64
  6. CoefficientiIdrogrammaUnitarioMockus: 'dati dell'idrogramma unitario di Mockus
  7. DATA 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5: 't/ta
  8. DATA 0.03,0.1,0.19,0.31,0.47,0.66,0.82,0.93,0.99,1,0.99,0.93,0.86,0.78,0.68,0.56,0.46,0.39,0.33,0.28,0.244,0.207,0.177,0.147,0.127,0.107,0.092,0.077,0.066,0.055,0.048,0.04,0.035,0.029,0.025,0.021,0.018,0.015,0.013,0.011,0.009,0.008,0.007,0.006,0.006,0.005,0.004,0.003,0.001,0: ' t/tp
  9.  
  10. TYPE mockus
  11.     tSUta AS SINGLE
  12.     qSUqp AS SINGLE
  13. TYPE TempiRitorno
  14.     T AS STRING
  15.     k AS SINGLE
  16. DIM SHARED i%, n%, z%, ieto%, VisualizzaIeto%
  17. DIM SHARED TempiRitorno(10) AS TempiRitorno
  18. DIM mockus(50) AS mockus
  19.  
  20.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''CLEAR
  21.  
  22.     ' 'RESTORE group 1:
  23.     RESTORE TempiRitorno
  24.     FOR i% = 1 TO 20
  25.         IF i% <= 10 THEN READ TempiRitorno(i%).T
  26.         IF i% > 10 THEN READ TempiRitorno(i% - 10).k
  27.     NEXT i%
  28.  
  29.     ' 'RESTORE group 2:
  30.     RESTORE CoefficientiIdrogrammaUnitarioMockus
  31.     FOR i% = 1 TO 100
  32.         IF i% <= 50 THEN READ mockus(i%).tSUta
  33.         IF i% > 50 THEN READ mockus(i% - 50).qSUqp
  34.     NEXT i%
  35.  
  36.  
  37.     '[...]
  38.     PRINT
  39.     PRINT "- Restart program? [Y/N]"
  40.     DO
  41.         _LIMIT 50
  42.         KeyPress$ = LCASE$(INKEY$)
  43.     LOOP UNTIL KeyPress$ = "y" OR KeyPress$ = "n"
  44.     IF KeyPress$ = "n" THEN EXIT DO
  45.  
  46.  
Seems to work fine for me since main code isn't doing anything but load arrays.
« Last Edit: June 24, 2021, 07:11:22 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem with CLEAR
« Reply #9 on: June 24, 2021, 08:55:51 am »
Here, I've simplified the issue so everyone can see what's going on here a little better:

Code: QB64: [Select]
  1. Data "Hello World",1
  2. Type test_type
  3.     x As String
  4.     y As Single
  5. Dim test As test_type
  6. Read x$, y
  7. Print x$, y
  8. Read test.x '<<< The issue is in this line here.  CLEAR and UDT don't seem to play nicely together.
  9. Print "Hello Crash"
  10.  

CLEAR and User Defined Types  simply aren't playing nice together with other.

An even simpler demo:

Code: QB64: [Select]
  1. Type test_type: x As String: End Type: Dim test As test_type
  2. x$ = "Hello World": Print x$: Sleep
  3. test.x = x$
  4. Print "Hello Crash", x$: Sleep
  5.  

Apparently, the way it seems to exist to me, at the moment, if you're going to use CLEAR, you don't want to make use of UDTs in your program.

Personally, I tend to *always* to avoid the CLEAR and RUN statements, as I've always found them to be buggy and unreliable at best.  Simply having a GOSUB to initialize all variables when they're first defined seems to be the best way to me.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem with CLEAR
« Reply #10 on: June 24, 2021, 03:42:26 pm »
Quote
Personally, I tend to *always* to avoid the CLEAR and RUN statements, as I've always found them to be buggy and unreliable at best.  Simply having a GOSUB to initialize all variables when they're first defined seems to be the best way to me.

+1 yes!

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Problem with CLEAR
« Reply #11 on: June 24, 2021, 03:48:50 pm »
I do too (I never use CLEAR, and I will use pipecom or SHELL instead of RUN).

I thought because RUN wipes out memory and that the fact that the calling program never existed, it was an idea.


+1 yes!
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: Problem with CLEAR
« Reply #12 on: June 25, 2021, 04:49:19 am »
The problem I have found about CLEAR, at the end was very simple to be fixed. I needed to define T AS STRING, but I solved defining T AS SINGLE  (and even INTEGER is working) and then converting it in string with _LTRIM and STR$. But, when the code starts to be long and complicated, like the mine with 12 subroutines and almost 2000 lines, it becomes difficult to distinguish if the problem is about something wrong somewhere in the code, or a bug. Generally, 999 every 1000 times the problem is something wrong in the code, so one doesn't think about a bug and finishes to spend much time in searching an error. Finally, one can suppose a bug, but even in this case, it is impossible to know that the problem is in something apparently separate: how one can suppose that there is a conflict between CLEAR and defining a string in TYPE?

Even when I wrote the first post, I was not thinking about a bug in CLEAR, and I was convinced that there was someting wrong in the code, or maybe a wrong use of CLEAR. I found the bug only cutting the first example in order to make it more understandable for you. And, as you say that CLEAR is buggy, maybe there are other bug in it.

I think that it will be nice if CLEAR will be fixed, because I think that it is not a marginal command, as RUN, but a very important one: it is common that a program has to restart itself without exiting and rerun it, so it is important to have a simple and well working command that clear all variables without the necessity to create specific routines to do it.

FellippeHeitor

  • Guest
Re: Problem with CLEAR
« Reply #13 on: June 25, 2021, 08:01:54 am »
We've had a few corner cases like this one since the introduction of variable-width strings in types. Do you get the same problem with CLEAR if you declare your element as a fixed string element? For example:

Code: QB64: [Select]
  1.     T AS STRING * 256

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Problem with CLEAR
« Reply #14 on: June 25, 2021, 12:12:55 pm »
Here, I've simplified the issue so everyone can see what's going on here a little better:

Code: QB64: [Select]
  1. Data "Hello World",1
  2. Type test_type
  3.     x As String
  4.     y As Single
  5. Dim test As test_type
  6. Read x$, y
  7. Print x$, y
  8. Read test.x '<<< The issue is in this line here.  CLEAR and UDT don't seem to play nicely together.
  9. Print "Hello Crash"
  10.  

CLEAR and User Defined Types  simply aren't playing nice together with other.

An even simpler demo:

Code: QB64: [Select]
  1. Type test_type: x As String: End Type: Dim test As test_type
  2. x$ = "Hello World": Print x$: Sleep
  3. test.x = x$
  4. Print "Hello Crash", x$: Sleep
  5.  

Apparently, the way it seems to exist to me, at the moment, if you're going to use CLEAR, you don't want to make use of UDTs in your program.

Personally, I tend to *always* to avoid the CLEAR and RUN statements, as I've always found them to be buggy and unreliable at best.  Simply having a GOSUB to initialize all variables when they're first defined seems to be the best way to me.

must be a variable length thing, cause using defined length does not crash.

though CLEAR seems to wipe the UDT out, as test.x becomes a single value variable no longer a string. why there is no error when trying to apply a string to numerical variable is odd. cause that is where the crash is, trying to apply a string to numerical.

@FellippeHeitor doesn't crash at least with a fix length string value.
Granted after becoming radioactive I only have a half-life!