Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any better way around Duplicate Definition problems?
#11
(01-25-2025, 05:23 PM)Pete Wrote:
(01-25-2025, 06:44 AM)hsiangch_ong Wrote: what happened to redim _preserve?

i'm missing something.  go ahead.  laugh at me.

Well, if you mean trying...

Code: (Select All)
test pete$()

Sub test (pete$())
    ReDim _Preserve pete$(5)
End Sub

That still throws a DUPLICATE DEFINITION error and it would also require a Redim pete$(0) as the first line to work, just like Redim without _Preserve. ...

this is because you are going against an old maxim in basic.  because quickbasic/qbasic was derrived from gw-basic/basica.  in those interpreted basic's there was no need to declare an array if the program didn't need more than 11 elements.  in some basic's however, the data type had to be the "default."  in gw-basic i believe it was single.  otherwise dim had to be used to create an array of a different data type especially string.  so it was what quickbasic/qbasic inherited.  qb64(pe) had to go along with those ancestors on 16-bit computers.

also in quickbasic, qbasic and basic pds.  there had to be a way to mark an array as dynamic without having to use the fake precompiler switch.  so use redim instead of dim for it.  qb64(pe) probably never allows _preserve used after dim with $dynamic precompiler switch or not.

but needing to do something with global array would require specific subprograms anyway to initialize it.

some of us can't survive without some c/c++ so the declare and "dot-bi" files won't go away completely.
Reply
#12
Yeah I settled on the .bi and .bm INCLUDE file method, since it has become pretty apparent there is no other better solution... and that's fine. Arrays are a bit of the ugly step-child in this language. All Biden's D.E.I. B.S. didn't do a thing for them. Oh well, at least they won't be deprecated... or worse, de-ported.

Pete Big Grin
Reply
#13
One way to send an array to a function would be:

Code: (Select All)
Dim Array(1 To 100) As Integer
For x = 1 To 100
  Array(x) = x
Next
z = DisplayArray(Array%())
If z Then Print "Correct."
End

Function DisplayArray (GetArray%())
  For z = 1 To 100
      Print GetArray%(z);
  Next
  DisplayArray = -1
End Function
Where you don't need to share anything or redim _preserve the array.
Reply
#14
Sure, but you had to Dim it in the calling procedure. So if the function were made into a library, that library would have to be accompanied by a bi file to include the Dim statement, either as SHARED, if it is not being passed, or without declaring as SHARED if, as in your example, it was being passed.

Pete
Reply
#15
(01-27-2025, 09:41 PM)Pete Wrote: Sure, but you had to Dim it in the calling procedure. So if the function were made into a library, that library would have to be accompanied by a bi file to include the Dim statement, either as SHARED, if it is not being passed, or without declaring as SHARED if, as in your example, it was being passed.

Pete
So, break it down into chunks.

Code: (Select All)
Rem sample.bi header include file.
Dim Array(1 To 100) As Integer
Code: (Select All)
Rem sample.bm function include source.
Function DisplayArray (GetArray%())
  For z = 1 To 100
      Print GetArray%(z);
  Next
  DisplayArray = -1
End Function
Code: (Select All)
Rem $Include:'sample.bi'
Rem sample.bas Main source
For x = 1 To 100
  Array%(x) = x
Next
z = DisplayArray(Array%())
If z Then Print "Correct."
End
Rem $Include:'sample.bm'


Attached Files
.zip   SAMPLE.ZIP (Size: 652 bytes / Downloads: 73)
Reply
#16
Exactly. For arrays use, it's the only game in town, but I'm still glad I rattled a few cages, just in case I was missing some other method.

My new obsession with libraries is really just age related. I figured as I get older, and it get's harder and harder to figure, I'll be happy if I can still put some programs together in between sponge baths. That's going to be considerably easier if I can create universal use libraries now, while I still have 50% of my wits about me. Oh well, at least that's better than being half witted, I think...

Pete Confused
Reply
#17
Quote:Exactly. For arrays use, it's the only game in town, but I'm still glad I rattled a few cages, just in case I was missing some other method.
The only other method is if you don't want to use arrays is like what Steve mentioned: you could use the _MEM function sets instead.

Although I have never used _Memcopy or _Memput or _Memget I wouldn't know..

-ejo Confused
Reply




Users browsing this thread: 1 Guest(s)