Author Topic: quickbasic instruction alternative to qb64  (Read 4574 times)

0 Members and 1 Guest are viewing this topic.

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
quickbasic instruction alternative to qb64
« on: September 10, 2020, 09:58:46 am »
hi I wanted to know if there is an alternative to this instruction
DEF FNA(Z)=30*EXP(-Z*Z/100)


as I understand the qb64 does not read this instruction  DEF FNA


the reason is' because you are unable to run this program

Code: QB64: [Select]
  1. 1 PRINT TAB(32);"3D PLOT"
  2. 2 PRINT TAB(15);"CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. 5 DEF FNA(Z)=30*EXP(-Z*Z/100)
  4. 100 PRINT
  5. 110 FOR X=-30 TO 30 STEP 1.5
  6. 120 L=0
  7. 130 Y1=5*INT(SQR(900-X*X)/5)
  8. 140 FOR Y=Y1 TO -Y1 STEP -5
  9. 150 Z=INT(25+FNA(SQR(X*X+Y*Y))-.7*Y)
  10. 160 IF Z<=L THEN 190
  11. 170 L=Z
  12. 180 PRINT TAB(Z);"*";
  13. 190 NEXT Y
  14. 200 PRINT
  15. 210 NEXT X
  16. 300 END
  17.  
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #1 on: September 10, 2020, 10:07:18 am »
Code: QB64: [Select]
  1. 1 PRINT TAB(32); "3D PLOT"
  2. 2 PRINT TAB(15); "CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY"
  3. '5 DEF FNA(Z)=30*EXP(-Z*Z/100)
  4. 100 PRINT
  5. 110 FOR X = -30 TO 30 STEP 1.5
  6.    120 L = 0
  7.    130 Y1 = 5 * INT(SQR(900 - X * X) / 5)
  8.    140 FOR Y = Y1 TO -Y1 STEP -5
  9.        150 Z = INT(25 + fna(SQR(X * X + Y * Y)) - .7 * Y)
  10.        160 IF Z <= L THEN 190
  11.        170 L = Z
  12.        180 PRINT TAB(Z); "*";
  13.    190 NEXT Y
  14.    200 PRINT ;
  15. 210 NEXT X
  16. 300 END
  17.  
  18. FUNCTION fna (z)
  19.     fna = 30 * EXP(-z * z / 100)
  20.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #2 on: September 10, 2020, 11:34:41 am »
Line 160 a perfect opportunity to try out the _CONTINUE keyword for beyond QB4.5!

That code looks like it comes from GW BASIC or even before that (<1980's?)! Otherwise an IF THEN block might have been used instead of THEN (implied GOTO) 190. Of course that is pretty elegant if you HAVE to have line numbers :)
« Last Edit: September 10, 2020, 11:39:31 am by bplus »

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #3 on: September 10, 2020, 04:05:38 pm »
Line 160 a perfect opportunity to try out the _CONTINUE keyword for beyond QB4.5!

That code looks like it comes from GW BASIC or even before that (<1980's?)! Otherwise an IF THEN block might have been used instead of THEN (implied GOTO) 190. Of course that is pretty elegant if you HAVE to have line numbers :)

I don't know from what language but I downloaded it on google
I'll post the sources attached if you want to play with the code
se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline Kiara87

  • Forum Regular
  • Posts: 164
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #4 on: September 10, 2020, 04:14:14 pm »
Line 160 a perfect opportunity to try out the _CONTINUE keyword for beyond QB4.5!

That code looks like it comes from GW BASIC or even before that (<1980's?)! Otherwise an IF THEN block might have been used instead of THEN (implied GOTO) 190. Of course that is pretty elegant if you HAVE to have line numbers :)

I had not seen but you have created a function thanks for the very good modification

FUNCTION fna (z)
    fna = 30 * EXP(-z * z / 100)
END FUNCTION

it serves to learn

se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #5 on: September 10, 2020, 05:08:46 pm »
QB64 doesn't support the DEF FN instruction of Qbasic/QB4.5

DEF FN has been used to define an old kind of FUNCTION that works like a GOSUB block in the main. That old FUNCTION often is oneline function, like in the example that you have posted, but that FUNCTION can be also multiline.
The same QB4.5 authors have not so much good consideration about it because it is a main block of code and it can access to all global variables and its inner variables are global .
The modern version is FUNCTION that is a local block of code that can have inner local variables, moreover it can access to all global variables SHARED or DIM SHARED or passed to it by parameters. The FUNCTION returns a value of the same type of data of the name of FUNCTION.
In developing by me a tool to convert all old DEF FN into a FUNCTION without loose the right flow of the program.
/
IT:
DEF FN è stato utilizzato per definire un vecchio tipo di FUNZIONE che funziona come un blocco GOSUB nel main. Quella vecchia FUNZIONE è spesso una funzione di una riga, come nell'esempio che hai pubblicato, ma quella FUNZIONE può essere anche su più righe.
Gli stessi autori di QB4.5 non hanno molta considerazione al riguardo perché è un blocco principale di codice e può accedere a tutte le variabili globali e le sue variabili interne sono globali.
La versione moderna è FUNCTION ovvero un blocco locale di codice che può avere variabili locali interne, inoltre può accedere a tutte le variabili globali SHARED o DIM SHARED o passate ad essa da parametri. La FUNZIONE restituisce un valore dello stesso tipo di dati del nome di FUNZIONE.
Sto sviluppando una utilità per convertire le vecchie DEF FN in FUNCTION mantenendo la funzionalità del programma.
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #6 on: September 10, 2020, 05:36:26 pm »
I had not seen but you have created a function thanks for the very good modification

FUNCTION fna (z)
    fna = 30 * EXP(-z * z / 100)
END FUNCTION

it serves to learn

Yes, well _vince did the function for you. That "3D" view in ANSII was odd!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: quickbasic instruction alternative to qb64
« Reply #7 on: September 12, 2020, 05:00:27 am »
Line 160 a perfect opportunity to try out the _CONTINUE keyword for beyond QB4.5!

Perfect example on how breaks and continues are the modern GOTOs!