Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays inside Types?
#11
(Yesterday, 02:48 PM)Kernelpanic Wrote: Same program: Why is the first entry always duplicated here ( summe = Liste(1).Index + Liste(2).Index )? Does anyone have an explanation for this? Thanks!
It's a copy-paste bug.... In your example, it should have been:
Code: (Select All)

...
Input "Zweite Zahl eingeben: ", wert
Liste(1).Index = wert

Input "Zweite Zahl eingeben: ", wert2
Liste(2).Index = wert2                              ' <===== should be *wert2* instead of *wert*
...


------------------------------------------------------------------------


(Yesterday, 05:43 PM)hsiangch_ong Wrote: can't believe the commodore 64 is being sold again.  i don't think any of the ones sold as we speak.  are being used to program in basic.
I beg to differ... strongly!  Big Grin

PS: do you use a STT-system to write your posts (Speech To Text)?
If not, it is a bit hard to read your posts with all the unnecessary punctuation.
But if you use a STT-system then please ignore this comment/suggestion.  Wink
Who remembers QB30, GWBASIC, C64, ZX80?
Reply
#12
Quote:@Cookie Oscar -  It's a copy-paste bug....
Goddamn it... Thank you! - I need a drink! 

Reply
#13
(Yesterday, 05:43 PM)hsiangch_ong Wrote: not a "naysayer about progress" or alike.

but merely pointing out.  this is like the third topic.  (not really counting how many.)  about the same thing.  only because basic pds 7.1 supported it and not quickbasic/qbasic.

if not then something like with... end with like in turbo pascal.

the "possibly related threads" listed are all off.  one of them is "arrays as udt's" by pete.  i'm not good with names around here.  but another of the european users here.  created a topic several months ago.  because they had some programs to "convert" from basic pds 7.1.

"progress" increasingly means "features of object-oriented language."  if not then oh yeah, recall 1970's and 1980's.

can't believe the commodore 64 is being sold again.  i don't think any of the ones sold as we speak.  are being used to program in basic.

Hey VB for DOS had property arrays way way back in the 90's! So not exactly serious OOP with methods nor even serious progress. 

Still turning longstrings into arrays and back again has advatages! You can do more with strings as far as editing elements deleting, slicing middle pieces, mix and matching... strings so much more flexible! no Redim _Preserve when changing string size, beautiful stuff! Since arrays not likely to happen any time soon enjoy work with long strings!

Seriously check this out, I've been doing this for years and years now!
https://qb64phoenix.com/forum/showthread...9#pid22809

@Ikerkaz what justsomeguy showed you is fabulous for numbers I highly recommend that for number arrays. Luke gave us the same thing years and years ago! What I offer is varaible length string "arrays" in longstrings as supplement to numbers arrays in strings, they do have a bit more processing because you have delimiters to deal with but the numbers examples teach how long strings work even if they have fixed item byte sizes.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#14
https://qb64phoenix.com/forum/showthread.php?tid=4335

Problem solved! At least as far as it can be!

Unseen
Reply
#15
@bplus
Quote: Luke gave us the same thing years and years ago!
can you provide a link ?
Reply
#16
It was at .net or .org prob .org, so no link, but its same as posted in this thread by justsomeguy.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#17
@Jack It was in early 2021 here is my copy of justsomeguy code from Luke:
Code: (Select All)
_Title "SetDbl GetDbl Test" '2021-01-31 for Handy Toolbox
ReDim dbl As Double
Print Len(dbl) ' = 8
Print
For i = 0 To 20
    SetDbl rndArr$, i, Rnd + i
Next
For i = 20 To 0 Step -1
    Print GetDbl#(rndArr$, i)
Next

Sub SetDbl (array$, index As Long, value#) ' Luke's Method except option explicit requires mod, no variables needed for one type
    If Len(array$) < 8 * (index + 1) Then array$ = array$ + String$(8 * (index + 1) - Len(array$), Chr$(0))
    Mid$(array$, index * 8 + 1) = _MK$(Double, value#)
End Sub

Function GetDbl# (array$, index As Long)
    GetDbl# = _CV(Double, Mid$(array$, index * 8 + 1, 8))
End Function

so array$ is your longString to use in your UDT.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#18
thanks bplus
but that basically the same method I had used and the overhead is very high
I am wondering if there is a way to simulate the PowerBasic Dim At
type MyType
s as string*80
end type
dim MyVar as MyType
dim MyNewVar(9) as double at varptr(MyVar.s)

you could then manipulate the array as normal but the values would be stored in the string
Reply
#19
I tend to just do this the mostest of simplest of ways:

TYPE Foo_Type
   X AS LONG
   Y AS LONG
   Z AS LONG
END TYPE

DIM Whatever AS Foo_Type
DIM Whatever.array(100) AS LONG

Now I can do stuff like:

Whatever.X = 100
Whatever.Y = 100
Whatever.Z = 100

FOR i = 0 to 100
  Whatever.array(i) = i
NEXT

See?  I still has an array and it's easily associated with my whatever.  Big Grin

All I has to do when saving to disk or whatnot is remember to:

PUT #1, ,whatever
PUT #1, ,whatever.array()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Arrays as UDTs Pete 26 1,200 02-06-2026, 04:31 AM
Last Post: bplus
  Preserving multi-dim arrays Pete 5 416 12-19-2025, 03:17 PM
Last Post: Dimster
  Array out of passing arrays... Pete 2 407 09-22-2025, 08:53 PM
Last Post: ahenry3068
  Methods in types bobalooie 7 1,568 01-30-2025, 08:00 PM
Last Post: Pete
  C++ types > QB64 types: do we have an equivalent QB64PE page? madscijr 5 1,126 06-01-2024, 03:44 AM
Last Post: grymmjack

Forum Jump:


Users browsing this thread: Unseen Machine, 2 Guest(s)