Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDT problems
#1
Neither of these 2 functions work:

Code: (Select All)
Type BitStruct
  xbit As _Bit
End Type

Dim BitStructure As BitStruct
BitStructure.xbit = 0
Print BitStructure.xbit
Code: (Select All)
type StructType
  Array(10) As Integer
End Type

Dim Structure As StructType
Structure.Array(10) = 10
Reply
#2
(11-12-2023, 05:46 AM)eoredson Wrote: Neither of these 2 functions work:

Code: (Select All)
Type BitStruct
  xbit As _Bit
End Type

Dim BitStructure As BitStruct
BitStructure.xbit = 0
Print BitStructure.xbit
Code: (Select All)
type StructType
  Array(10) As Integer
End Type

Dim Structure As StructType
Structure.Array(10) = 10
Bit length variables and arrays are not allowed inside UDTs.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#3
So are you saying it can't be done or nobody wants to!?
Reply
#4
He's saying it isn't able to be done. Also, it isn't something worth implementing.
Tread on those who tread on you

Reply
#5
(11-12-2023, 06:05 AM)eoredson Wrote: So are you saying it can't be done or nobody wants to!?

Code: (Select All)
Type BitStruct
  xbit As _Bit
End Type

Dim BitStructure As BitStruct

Why do you want an UDT variable as opposed to a variable which straight out declared ```AS _BIT```?

Not even C++ allows a "property" to occupy seven bits or less, let alone only one. I used "property" as term coming from OOP as synonym for "field". Although "bit fields" do exist they are for maniacs to handle.

As was already said around here many times before, if you need an array as UDT field member, make it type ```_MEM``` and use the statements and functions from that gang, that's what they are there for. It's clunky but to make it "prettier" than that, you will have to begin your bid today to transform QB64 into an object-oriented programming language.

You should know that you could also use a ```STRING * whatever``` variable and parse it, although it will be slow and it's a PITA sometimes working with FLS. The additional advantage of the "string list", though is that you could set whatever values of "array" elements you please, ie. mix the types, as long as you know how to program for what to look for.
Reply
#6
(11-12-2023, 06:19 AM)SpriggsySpriggs Wrote: He's saying it isn't able to be done. Also, it isn't something worth implementing.
Yet QB64PE claims to be QB45 compatible which has UDT arrays...

Is a question of principle.
Reply
#7
(11-12-2023, 06:19 AM)SpriggsySpriggs Wrote: He's saying it isn't able to be done. Also, it isn't something worth implementing.
Implementing the _BIT in UDTs I agree is not useful but allowing the use of arrays in UDTs would be monumental. Smile
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#8
(11-12-2023, 06:44 AM)TerryRitchie Wrote:
(11-12-2023, 06:19 AM)SpriggsySpriggs Wrote: He's saying it isn't able to be done. Also, it isn't something worth implementing.
Implementing the _BIT in UDTs I agree is not useful but allowing the use of arrays in UDTs would be monumental. Smile

Thank you for stating the obvious!! Because I have several products with UDT arrays which need to be edited.

Erik.
Reply
#9
If you need bits (presumably as flags) you could always use a _BYTE and manipulate each of the 8 bits. This will give you 8 flags to choose from.

Code: (Select All)
TYPE BitStruct
    xbits AS _BYTE
END TYPE

DIM BitsStructure AS BitStruct

BitsStructure.xbits = BitsStructure.xbits XOR 8 ' toggle 4th bit

PRINT BitsStructure.xbits

BitsStructure.xbits = BitsStructure.xbits XOR 8 ' toggle 4th bit

PRINT BitsStructure.xbits
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#10
(11-12-2023, 06:50 AM)eoredson Wrote:
(11-12-2023, 06:44 AM)TerryRitchie Wrote:
(11-12-2023, 06:19 AM)SpriggsySpriggs Wrote: He's saying it isn't able to be done. Also, it isn't something worth implementing.
Implementing the _BIT in UDTs I agree is not useful but allowing the use of arrays in UDTs would be monumental. Smile

Thank you for stating the obvious!! Because I have several products with UDT arrays which need to be edited.

Erik.
Was it written in QuickBasic? QuickBasic never allowed arrays in UDTs. I don't remember if VBDOS did though.

Edit: I just looked it up, both QB7.1(BC7/PDS) and VBDOS(v1.00) did allow arrays in UDTs.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 5 Guest(s)