Author Topic: Does a program that runs on qb32 also runs smootly on qb64, without any problem?  (Read 3791 times)

0 Members and 1 Guest are viewing this topic.

Offline zauberhaft

  • Newbie
  • Posts: 3
    • View Profile
Hello,

My question is this:
shoud a program that runs on qb32 (in dosbox) run without any problem on qb64?
I have problems with open for random, put for random and get for random.
So I can't read any file (and I have a lot of files) language and leerdam (see youtube search for: zauberhaft1)
thx zauberhaft
I

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Is there a QB32? Or are you referring to QB64 before it actually was 64 bit?

And do you know there still is a QB64 version for 32 bit?

I think DosBox is meant for old Dos versions of QB.

Are you trying to run old code in modern OS, if any Basic can do it QB64 is likely one.

Show code For Random you are trying, maybe we can get it going in modern OS.


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Hey maybe he means QB45, a.k.a. QB 4.5 and Quick Basic. If so, the answer is yes to most of the QB45 commands, with only a few exceptions. RUN and CLEAR do not work exactly the same. FRE was never implemented, because there is no real need to monitor memory with QB64. DEF FN was also never implemented, so those shortcut functions would need to be converted to full functions. There are a couple more I'm just not thinking about at the moment, but with so few keywords not supported there are very few programs written in QB45 that will not run exactly the same on QB64, except they will run faster.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline zauberhaft

  • Newbie
  • Posts: 3
    • View Profile
Thank you both for the quick respose.
I just discovered: in the old basic (qbasic, qb qnd qb32) in dosbox it runs with:
Open file11$ For Random As #11 Len = (30):
with qb64 I get the error: Bad record lenght. so I found on the internet that I have to add two bytes more on the Len = (30) statement Len = (32)
But I Have to do this only on the open statement, and not on the get and put statement!

If this is correct then I have only to ad 2 spaces on the first line of the file. I hope it wil work! You can see my programs on youtube, search for zauberhaft1. The draughts and the language program dates from 1992, and it was a pleasure to make in that time. Took me more than a year, but I learned a lot. Now I will pick up with qb64. Ps the language program was first written on a Commodore C16, Later on a C64, en dan on an IBM 486. but enough for this day. it is : 00:18 hour here, so goodnight for now!

    file11$ = "engd0001"
    Open file11$ For Random As #11 Len = (32):
    e = Len(eng$): d = Len(dut$)
    en$ = Space$(15 - e): du$ = Space$(15 - d): eng$ = eng$ + en$: dut$ = dut$ + du$
    Taal$ = eng$ + dut$
    Put #11, I, Taal$
    eng$ = "": dut$ = ""
    Get #11, I, Taal$
    Locate 18, 5: Print Taal$
    Close #11: Close #12

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
If your file is LEN(30), you have to keep it that size so the records align properly.

I'd think that all you're missing is the proper DIM statement.

DIM Taal AS STRING * 30 'set the string to the proper 30 character length

And then it's a case of:

GET #11, record_number, Taal

and

PUT #11, record_number, Taal
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Thank you both for the quick respose.
I just discovered: in the old basic (qbasic, qb qnd qb32) in dosbox it runs with:
Open file11$ For Random As #11 Len = (30):
with qb64 I get the error: Bad record lenght. so I found on the internet that I have to add two bytes more on the Len = (30) statement Len = (32)
But I Have to do this only on the open statement, and not on the get and put statement!

If this is correct then I have only to ad 2 spaces on the first line of the file. I hope it wil work! You can see my programs on youtube, search for zauberhaft1. The draughts and the language program dates from 1992, and it was a pleasure to make in that time. Took me more than a year, but I learned a lot. Now I will pick up with qb64. Ps the language program was first written on a Commodore C16, Later on a C64, en dan on an IBM 486. but enough for this day. it is : 00:18 hour here, so goodnight for now!

    file11$ = "engd0001"
    Open file11$ For Random As #11 Len = (32):
    e = Len(eng$): d = Len(dut$)
    en$ = Space$(15 - e): du$ = Space$(15 - d): eng$ = eng$ + en$: dut$ = dut$ + du$
    Taal$ = eng$ + dut$
    Put #11, I, Taal$
    eng$ = "": dut$ = ""
    Get #11, I, Taal$
    Locate 18, 5: Print Taal$
    Close #11: Close #12

I wonder if that add 2-bytes was one  of my old posts! Funny though, back in the day that trick was needed for QBasic and QB45, too. In other words, if the largest record length was 30bytes, you simply needed to add 2-bytes to the open statement. It makes for an ugly file, if you ever open it n notepad, but it does work. For a perfectly aligned file, you need to do the DIM method Steve mentioned. Basically that fills each smaller than 30-byte data statement with CHR$(32) if I remember right, if I don't it would b character(0). In either case it makes the record length of every data entry 30-bytes long.

Glad you found a solution,

Pete
« Last Edit: February 24, 2022, 06:59:45 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
@Pete The +2 is for random length strings so you can include 2 byte line-endings.  If the file LEN with the OPEN statement is 30, then either you need a set length string of 30, or else you need for the variable length string to be a maximum length of 28 characters.

Making the OPEN length 2 larger will make records misaligned.  The only working solution is either max 28 byte variable length strings (+2 for line endings), or set 30 byte strings.  32-bytes make the record length off and existing records won't read properly.

"(and I have a lot of files)" makes it seem he's got to access old records, not create new ones.  ;)



From the code, it seems like the data was originally a custom type.

TYPE Dictionary_Type
    eng AS STRING * 15
    dut AS STRING * 15
END TYPE

DIM Dict AS Dictionary_Type

Then you get and put Dict to each record position.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
This fixes everything:
Code: QB64: [Select]
  1. file11$ = "engd0001"
  2.  
  3.  
  4. Dim taal As String * 30 ' standard way to setup a record for a Random File
  5.  
  6. Open file11$ For Random As #11 Len = Len(taal) ' standard way to open a random with a record
  7.  
  8.  
  9. eng$ = "Test": dut$ = "this." ' <<<<<<<<< let's try something real!
  10. e = Len(eng$): d = Len(dut$)
  11. en$ = Space$(15 - e): du$ = Space$(15 - d)
  12. eng$ = eng$ + en$: dut$ = dut$ + du$
  13. taal$ = eng$ + dut$
  14.  
  15. 'Print Len(taal), taal
  16. 'Sleep
  17.  
  18.  
  19. Put #11, 1, taal$ ' <<<< I is 0 but get and put start at 1 !!!!
  20.  
  21. eng$ = "": dut$ = ""
  22. Get #11, 1, taal$
  23. Locate 18, 5: Print taal$
  24. Close #11
  25.  

Ha! didn't mean to leave $ on taal but works ideally I'd do this:
Code: QB64: [Select]
  1. file11$ = "engd0001"
  2.  
  3.  
  4. Dim taal As String * 30 ' standard way to setup a record for a Random File
  5.  
  6. Open file11$ For Random As #11 Len = Len(taal) ' standard way to open a random with a record
  7.  
  8.  
  9. eng$ = "Test": dut$ = "this." ' <<<<<<<<< let's try something real!
  10. e = Len(eng$): d = Len(dut$)
  11. en$ = Space$(15 - e): du$ = Space$(15 - d)
  12. eng$ = eng$ + en$: dut$ = dut$ + du$
  13. taal = eng$ + dut$
  14.  
  15. 'Print Len(taal), taal
  16. 'Sleep
  17.  
  18.  
  19. Put #11, 1, taal ' <<<< I is 0 but get and put start at 1 !!!!
  20.  
  21. eng$ = "": dut$ = ""
  22. Get #11, 1, taal
  23. Locate 18, 5: Print taal
  24. Close #11
  25.  

oh a better test is to clear taal between Put and Get:
Code: QB64: [Select]
  1. file11$ = "engd0001"
  2.  
  3.  
  4. Dim taal As String * 30 ' standard way to setup a record for a Random File
  5.  
  6. Open file11$ For Random As #11 Len = Len(taal) ' standard way to open a random with a record
  7.  
  8.  
  9. eng$ = "Test": dut$ = "this." ' <<<<<<<<< let's try something real!
  10. e = Len(eng$): d = Len(dut$)
  11. en$ = Space$(15 - e): du$ = Space$(15 - d)
  12. eng$ = eng$ + en$: dut$ = dut$ + du$
  13. taal = eng$ + dut$
  14.  
  15. 'Print Len(taal), taal
  16. 'Sleep
  17.  
  18.  
  19.  
  20. Put #11, 1, taal ' <<<< I is 0 but get and put start at 1 !!!!
  21.  
  22. ' eng$ = "": dut$ = ""
  23.  
  24. taal = Space$(15)
  25. Get #11, 1, taal
  26. Locate 18, 5: Print taal
  27. Close #11
  28.  
  29.  
  30.  
« Last Edit: February 24, 2022, 07:30:20 pm by bplus »

Offline zauberhaft

  • Newbie
  • Posts: 3
    • View Profile
Thx everyone for your support.
The program Language kan read now every file!

Dim ge As String * 70 ' standard way to setup a record for a Random File
Dim taal As String * 70
Dim sys As String * 10

Those changes did the job. No need to ad 2 bytes. It is geat to use qb64 because I can now see quicly what the program does to a file.
now I can try to let ldam486a en ldam486b working again. (draughts program)

Question: Is there also a decompiler in qb64. I lost the .bas program, and I want it back!

So thanks all!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
...
Question: Is there also a decompiler in qb64. I lost the .bas program, and I want it back!


No, sorry.