Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem using constants
#1
const w=320
Type test
x(d) as short
end type

In this example the variable d must me a const, otherwise i get a error.
How would i do if i wanted to define d at runtime.

Screeninfo w, h
Type test
x(d) as short
end type

Something like this.
ttp://hem.passagen.se/qb.basta
Reply
#2
Just redim test.x(d) later on. You must use constants when making the type, but you can redim parts of the type later on.

Code:
d = 0
type test
x(0) as short
end type

d = 10
redim preserve test.x(0 to (d - 1)) as short
will Live Forever, or Die Trying >_<;;
Reply
#3
You'd have to set x up as a short pointer and allocate the number of shorts you need.

FreeBasic does NOT support dynamic arrays in a structure (type).

Code:
Const D = 10

Type Test
   As Short Ptr   X
End Type

Dim As Test   IsA

IsA.X = Callocate( Len( Short ) * D )
If ( IsA.X = 0 ) Then
   Print "Failed to allocate space for shorts!"
   End
End If

For I = 0 To D - 1
   IsA.X[ I ] = Int( Rnd * 32768 )
Next I

For I = 0 To D - 1
   Print I; IsA.X[ I ]
Next I

Deallocate IsA.X
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply
#4
Now why didn't I think of that...Oh yeah, I don't understand that code. That's why ^_^;; Or do I? *looks..Thinks he could figure it out in about 3 seconds*
will Live Forever, or Die Trying >_<;;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)