Author Topic: QB64 Practice  (Read 1721 times)

0 Members and 1 Guest are viewing this topic.

Offline ASJACO

  • Newbie
  • Posts: 1
QB64 Practice
« on: November 02, 2019, 12:50:50 pm »
Hi i'm new using qb64 im trying to make some practices but i don't get at all some commands. I'm trying  to make a loop where i compare a business name(A2002$) with the user typing 5 characters (A$ = INPUT$(5)) from a file called COAN20 in that file is located all the business name but i'm not sure  which comand should i use. I would appreciate some help thanks. Here it is the code.

CLEAR
ON ERROR GOTO 930
'pelaja-> Check or modify clients by their business name.
'

DEFINT I-N
DEFLNG E
'Screen Position'
SCREEN 0, 0, 0

'Open COAN20 '
OPEN COMPA$ + "COAN20" FOR RANDOM SHARED AS 1 LEN = 778
FIELD 1, 2 AS N2097$
FIELD 1, 6 AS A2001$, 70 AS A2002$, 60 AS A2003$, 60 AS A2004$, 60 AS A2005$
FIELD 1, 256 AS A200$, 5 AS A2006$, 30 AS A2007$, 15 AS A2008$, 4 AS L2009$
FIELD 1, 310 AS A201$, 4 AS L2010$, 4 AS L2011$, 4 AS L2012$, 4 AS L2013$
FIELD 1, 326 AS A202$, 4 AS L2014$, 8 AS D2015$, 8 AS D2016$, 4 AS L2017$
FIELD 1, 350 AS A203$, 4 AS L2018$, 4 AS L2019$, 4 AS L2020$, 8 AS D2021$
FIELD 1, 370 AS A204$, 8 AS D2022$, 60 AS A2023$, 4 AS L2024$, 2 AS N2025$
FIELD 1, 444 AS A205$, 2 AS A2026$, 1 AS A2027$, 16 AS A2028$, 4 AS L2029$
FIELD 1, 467 AS A206$, 4 AS L2030$, 6 AS A2031$, 2 AS N2032$, 1 AS A2033$
FIELD 1, 480 AS A207$, 1 AS A2034$, 2 AS N2035$, 2 AS N2036$, 1 AS A2037$
FIELD 1, 486 AS A208$, 2 AS N2038$, 2 AS N2039$, 1 AS A2040$, 2 AS N2041$
FIELD 1, 493 AS A209$, 2 AS N2042$, 1 AS A2043$, 2 AS N2044$, 2 AS N2045$
FIELD 1, 500 AS A210$, 2 AS N2046$, 6 AS A2047$, 16 AS A2048$, 16 AS A2049$
FIELD 1, 540 AS A211$, 60 AS A2050$, 60 AS A2051$, 60 AS A2052$, 24 AS A2053$
FIELD 1, 744 AS A212$, 32 AS A2098$, 2 AS N2099$



GET 1,1 'Read file and archive
NUMR=CVI(N2097$) ' Register number
i = 2 ' Register value

10 Print "Please type 5 characters"
A$ = INPUT$(5) '5 characters type by the user
GET 1,i 'Reads file number and register value
if INSTR(A$, A2002$) THEN PRINT A2002$  'A2002$ is the business name
i = i + 1 'ITERation
ELSE GOTO 12


12 PRINT "Wanna make another search?"
INPUT "Y/N?"; DES$   
if UCASE$(DES$) = "Y" then GOTO 10 ELSE GOTO 1000
END
ELSE
GOTO 1000
'Desplegado del Error
930 IF ERR = 70 THEN RESUME
LOCATE 22, 22: PRINT "Error No.- "; ERR; " En la Linea.- "; ERL;
940 SOUND 37, 12
950 GOSUB 970: GOTO 1000

'Rutina con la Transmision.
970 A$ = "To continue press " + CHR$(34) + "any" + CHR$(34) + " keybind"
LOCATE 23, 20: COLOR 7, 1: PRINT A$;: COLOR 7, 0
A$ = INPUT$(1)
LOCATE 23, 1: PRINT SPACE$(79);
Hi i'm new using qb64 im trying to make some practices but i don't get at all some commands. I'm trying  to make a loop where i get all the business name from a file called COAN20 in that file is located all the business name but i'm not sure  which comand should i use. I would appreciate some help thanks. Here it is the code.

CLEAR
ON ERROR GOTO 930
'pelaja-> Check or modify clients by their business name.
'

DEFINT I-N
DEFLNG E
'Screen Position'
SCREEN 0, 0, 0

'Open COAN20 '
OPEN COMPA$ + "COAN20" FOR RANDOM SHARED AS 1 LEN = 778
FIELD 1, 2 AS N2097$
FIELD 1, 6 AS A2001$, 70 AS A2002$, 60 AS A2003$, 60 AS A2004$, 60 AS A2005$
FIELD 1, 256 AS A200$, 5 AS A2006$, 30 AS A2007$, 15 AS A2008$, 4 AS L2009$
FIELD 1, 310 AS A201$, 4 AS L2010$, 4 AS L2011$, 4 AS L2012$, 4 AS L2013$
FIELD 1, 326 AS A202$, 4 AS L2014$, 8 AS D2015$, 8 AS D2016$, 4 AS L2017$
FIELD 1, 350 AS A203$, 4 AS L2018$, 4 AS L2019$, 4 AS L2020$, 8 AS D2021$
FIELD 1, 370 AS A204$, 8 AS D2022$, 60 AS A2023$, 4 AS L2024$, 2 AS N2025$
FIELD 1, 444 AS A205$, 2 AS A2026$, 1 AS A2027$, 16 AS A2028$, 4 AS L2029$
FIELD 1, 467 AS A206$, 4 AS L2030$, 6 AS A2031$, 2 AS N2032$, 1 AS A2033$
FIELD 1, 480 AS A207$, 1 AS A2034$, 2 AS N2035$, 2 AS N2036$, 1 AS A2037$
FIELD 1, 486 AS A208$, 2 AS N2038$, 2 AS N2039$, 1 AS A2040$, 2 AS N2041$
FIELD 1, 493 AS A209$, 2 AS N2042$, 1 AS A2043$, 2 AS N2044$, 2 AS N2045$
FIELD 1, 500 AS A210$, 2 AS N2046$, 6 AS A2047$, 16 AS A2048$, 16 AS A2049$
FIELD 1, 540 AS A211$, 60 AS A2050$, 60 AS A2051$, 60 AS A2052$, 24 AS A2053$
FIELD 1, 744 AS A212$, 32 AS A2098$, 2 AS N2099$



GET 1, 2

PRINT A2002$
A$ = INPUT$(1)
GOTO 1000 'Manda a cerrar el sistema


'Desplegado del Error
930 IF ERR = 70 THEN RESUME
LOCATE 22, 22: PRINT "Error No.- "; ERR; " En la Linea.- "; ERL;
940 SOUND 37, 12
950 GOSUB 970: GOTO 1000

'Rutina con la Transmision.
970 A$ = "To continue press " + CHR$(34) + "any" + CHR$(34) + " keybind"
LOCATE 23, 20: COLOR 7, 1: PRINT A$;: COLOR 7, 0
A$ = INPUT$(1)
LOCATE 23, 1: PRINT SPACE$(79);
RETURN

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QB64 Practice
« Reply #1 on: November 02, 2019, 02:30:45 pm »
Hi ASJACO, welcome to the forum!

Looks like you are having problems with forum editor, posted code twice?

Here is button for code block, highlight code and click button or click button and paste code between code and /code tags.

  [ You are not allowed to view this attachment ]  

Your code looks like really old QB, can't find line 1000 to GOTO?

Marked as best answer by ASJACO on November 04, 2019, 07:41:56 am

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: QB64 Practice
« Reply #2 on: November 02, 2019, 02:48:02 pm »
Hi ASJACO

1. welcome into QB64 forum, here you can find many people to talk and to exchange experiences.

2. you have posted twice the same code

3. please use the codebox button when you post the code (like I do here) so the code will be more visible and readable
Code: QB64: [Select]
  1. 'pelaja-> Check or modify clients by their business name.
  2. '
  3.  
  4. DEFINT I-N
  5. 'Screen Position'
  6. SCREEN 0, 0, 0
  7.  
  8. 'Open COAN20 '
  9. OPEN COMPA$ + "COAN20" FOR RANDOM SHARED AS 1 LEN = 778
  10. FIELD 1, 2 AS N2097$
  11. FIELD 1, 6 AS A2001$, 70 AS A2002$, 60 AS A2003$, 60 AS A2004$, 60 AS A2005$
  12. FIELD 1, 256 AS A200$, 5 AS A2006$, 30 AS A2007$, 15 AS A2008$, 4 AS L2009$
  13. FIELD 1, 310 AS A201$, 4 AS L2010$, 4 AS L2011$, 4 AS L2012$, 4 AS L2013$
  14. FIELD 1, 326 AS A202$, 4 AS L2014$, 8 AS D2015$, 8 AS D2016$, 4 AS L2017$
  15. FIELD 1, 350 AS A203$, 4 AS L2018$, 4 AS L2019$, 4 AS L2020$, 8 AS D2021$
  16. FIELD 1, 370 AS A204$, 8 AS D2022$, 60 AS A2023$, 4 AS L2024$, 2 AS N2025$
  17. FIELD 1, 444 AS A205$, 2 AS A2026$, 1 AS A2027$, 16 AS A2028$, 4 AS L2029$
  18. FIELD 1, 467 AS A206$, 4 AS L2030$, 6 AS A2031$, 2 AS N2032$, 1 AS A2033$
  19. FIELD 1, 480 AS A207$, 1 AS A2034$, 2 AS N2035$, 2 AS N2036$, 1 AS A2037$
  20. FIELD 1, 486 AS A208$, 2 AS N2038$, 2 AS N2039$, 1 AS A2040$, 2 AS N2041$
  21. FIELD 1, 493 AS A209$, 2 AS N2042$, 1 AS A2043$, 2 AS N2044$, 2 AS N2045$
  22. FIELD 1, 500 AS A210$, 2 AS N2046$, 6 AS A2047$, 16 AS A2048$, 16 AS A2049$
  23. FIELD 1, 540 AS A211$, 60 AS A2050$, 60 AS A2051$, 60 AS A2052$, 24 AS A2053$
  24. FIELD 1, 744 AS A212$, 32 AS A2098$, 2 AS N2099$
  25.  
  26.  
  27.  
  28. GET 1, 1 'Read file and archive
  29. NUMR = CVI(N2097$) ' Register number  '<---- CVI is used to convert MK$ generated string read from file
  30. i = 2 ' Register value
  31.  
  32. 10 PRINT "Please type 5 characters"
  33. A$ = INPUT$(5) '5 characters type by the user
  34. GET 1, i 'Reads file number and register value
  35. IF INSTR(A$, A2002$) THEN
  36.     PRINT A2002$ 'A2002$ is the business name
  37.     i = i + 1 'ITERation
  38.     REM GOTO 12             '<---- this line gives error in QB64Ide and 12 is the next line
  39.    12 PRINT "Wanna make another search?"
  40.     INPUT "Y/N?"; DES$
  41.     IF UCASE$(DES$) = "Y" THEN GOTO 10 ELSE GOTO 1000
  42. END IF ' you add this to close the if then else
  43.  
  44. REM ELSE '<--- this else is alone
  45. GOTO 1000
  46. 'Desplegado del Error
  47. 930 IF ERR = 70 THEN RESUME
  48. LOCATE 22, 22: PRINT "Error No.- "; ERR; " En la Linea.- "; ERL;
  49. 940 SOUND 37, 12
  50. 950 GOSUB 970: GOTO 1000
  51.  
  52. 'Rutina con la Transmision.
  53. 970 A$ = "To continue press " + CHR$(34) + "any" + CHR$(34) + " keybind"
  54. LOCATE 23, 20: COLOR 7, 1: PRINT A$;: COLOR 7, 0
  55. A$ = INPUT$(1)
  56. LOCATE 23, 1: PRINT SPACE$(79);
  57. RETURN '<---- Added this line to close the GOSUB alone at 950
  58. 1000

4. do you like spaghetti? Or do you like zombie code written with spaghetti?
I'm talking about the massive use of number of line as label (too poor descreptive) , GOTO and GOSUB .

I'm not saying that they are evil but only obsolete also if they work yet.
Code: QB64: [Select]
  1. ' FOR NEXT loop by GOTO label
  2. n = 0: min = 1: max = 10: steps = 1
  3. ForLabel:
  4. n = min
  5. ForLabel2:
  6. IF n < 10 THEN n = n + steps ELSE GOTO EndFor
  7. LOCATE 1, 1: PRINT n
  8. GOTO ForLabel2
  9. EndFor:

versus

Code: QB64: [Select]
  1. n = 0: min = 1: max = 10: steps = 1
  2. FOR n = min TO max STEP steps
  3.     LOCATE 1, 1: PRINT n


5. about FIELD I have no experience... but is it possible to convert a FIELD group into a TYPE of data so you can access easily to data and manage them in reading and in writing?
Here there is the wiki of FIELD http://www.qb64.org/wiki/FIELD


 6. at a first look  the code posted by you is not complete...
as shown the second example in the wiki page about FIELD you can use single field in sequence to get the information from the file or you can define an overall FIELD that is the sum of all fields defined so you can GET the info of all fields  at once.
Surely this is useful if all the FIELDs have always the same order in the file so you can join them into a maxiField to read/write...
and this becomes the grandfather of the UDT defined by TYPE...END TYPE

if you see your code in the codebox has some my comments and modifications
but seeing the example of wiki it seems that
Code: QB64: [Select]
  1. GET 1, i 'Reads file number and register value            
is an error because you GET the last field defined starting from the byte 2 of the file. (i = 2)

try this at its place
Code: QB64: [Select]
  1. FIELD 1, 2 AS N2097$
  2. GET 1
  3.  

Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: QB64 Practice
« Reply #3 on: November 02, 2019, 04:08:03 pm »
I think TYPE... END TYPE is best and more modern way to define a record structure.