Author Topic: Did I just stumble on some sort of QB64 bug???  (Read 2517 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Did I just stumble on some sort of QB64 bug???
« on: January 31, 2021, 03:17:41 pm »
https://www.qb64.org/forum/index.php?topic=3558.msg129096#msg129096

Look at line #350 and #351.

i% = UBOUND(ifield$)
REDIM entry$(UBOUND(ifield$))

Rem out i% = UBOUND(ifield$)

In v1.3, the IDE gives a Name already in use error. WTH?

It will accept REDIM entry$(i%)

I know I'm using the upper bounds of an array to DIM another array, but why will it work as coded, where the i% has NO FUNCTION in what's going on in the code, but when we Rem out i% = UBOUND(ifield$), it errors out?

If this doesn't do what I'm talking about, and you are using a more current version, then I just stumbled on an old bug, and the situation has been resolved. If it does error out in the newest version, it's either a bug, or something is going on that just makes no sense to me, since that i% part shouldn't effect the code, period.

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

FellippeHeitor

  • Guest
Re: Did I just stumble on some sort of QB64 bug???
« Reply #1 on: January 31, 2021, 03:24:22 pm »
Please try it in the latest development build to see if it still happens, so we can try to understand the issue at hand with more detail.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Did I just stumble on some sort of QB64 bug???
« Reply #2 on: January 31, 2021, 03:33:43 pm »
Did you try it in the latest build? I would, but I haven't downloaded the latest build yet and I'm not planning on adding it to my overly long to do list. If it doesn't fail in your Windows version, then it's something that has already been worked out. BTW - you don't even have to run the code. Just copy and paste it in the IDE then RE out line #350, and let us know if you get an IDE error message of "Name already in use." on line 351.

Pete
« Last Edit: January 31, 2021, 03:41:02 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Did I just stumble on some sort of QB64 bug???
« Reply #3 on: January 31, 2021, 03:37:09 pm »
I didn't try it.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Did I just stumble on some sort of QB64 bug???
« Reply #4 on: January 31, 2021, 03:40:38 pm »
  [ You are not allowed to view this attachment ]  
You're not done when it works, you're done when it's right.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Did I just stumble on some sort of QB64 bug???
« Reply #5 on: January 31, 2021, 03:42:39 pm »
Thanks Bill. That's the same thing I get in V1.3. So is this a bug, or what's going on here?

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

FellippeHeitor

  • Guest
Re: Did I just stumble on some sort of QB64 bug???
« Reply #6 on: January 31, 2021, 03:42:50 pm »
If line 348 is the first ever appearance of the entry$() array in your code, then you allowed QB64 to create it on-the-fly for you, which ended up creating a static array with 10 indexes.

Add REDIM entry$(0) to the beginning of your program to fix the issue. (Not a QB64 bug).
« Last Edit: January 31, 2021, 03:44:33 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Did I just stumble on some sort of QB64 bug???
« Reply #7 on: January 31, 2021, 03:43:53 pm »
Or add this to the beginning of your code:

Code: QB64: [Select]
  1. '$DYNAMIC

Both methods will fix the issue.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Did I just stumble on some sort of QB64 bug???
« Reply #8 on: January 31, 2021, 05:21:43 pm »
'$DYNAMIC is not an issue, and it didn't fix it. The array entry$() array was already DIM SHARED in line at line #63, so that's not it, but...

I went over the code, and discovered the array ifield$() is LOCAL. Making that DIM SHARED in the main corrects the error.

In short, it looks like this...

Code: QB64: [Select]
  1. REDIM SHARED entry$(10)
  2.  
  3. CALL local
  4.  
  5. i% = (UBOUND(ifield$))
  6. REDIM entry$(UBOUND(ifield$))
  7.  
  8. SUB local
  9.     REDIM ifield$(2)


EDIT: Okay, back up the truck... So my guess is that i% = UBOUND(ifield$), the UBOUND keyword is establishing a single instance of ifield$(), which I put as a local array, and forgot to pass it or just make it shared in the main. Without that UBOUND statement, no ifield$() array is found in the main, as coded. That has to be it. That must be what Fell meant by QB64 creates a 10 element array on the fly, but with UBOUND???? I don't use UBOUND much, but if this is what happened, I'll know where to look the next time I encounter it. Now I'm curious if QB worked the same way?

Thanks guys,

Pete
« Last Edit: January 31, 2021, 05:40:12 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/