Redim question

Started by Frank Brübach, November 28, 2024, 02:15:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hello.. How does Work redim in my example?

' test code for array 27-11-2024
uses console

indexbase 1

dim k as long

'Dim As Single a[4] = {1,2,3,4 }

' that's possible below?
Dim As Single a[9],b[9],c[9],x[9] = {10,20,30,40,50,60,70,80,90 }

'dim as single b[4]= {1,2,3,4 }
'dim as single c[4]= {1,2,3,4 }
'dim as single x[4]= {1,2,3,4 }

print " a[4]+b[4]+c[4]+x[4] " + a[4]+b[4]+c[4]+x[4] cr ' ok 40

' how does redim works?

' ReDim single a[5],b[5],c[5],x[5] 
ReDim single a[5] '',b[5],c[5],x[5] ' result 0, doesn't work

printl " a[5] " + ubound(a[5]) cr ' 256

k=ubound(a[5])
printl k cr  ' 256

wait


Charles Pegge

Hi Frank,

redim is a macro that does not support multiple declarations, so you need to do each variable individually. Also assign values in a separate line.

redim single a[5]
redim single b[5]
redim single c[5]

redim single x[5]
x={1,2,3,4,5}

Frank Brübach


hello charles, thanks for your reply, I have a second question:
it's possible to get same result without using 'at strptr(st)' with oxygen?

'
' pointer question with 'dim as byte ba at strptr(st)'

dim as string st = "BATMAN"
  dim as byte ba at strptr(st)
  'ba=>@st
  printl str(ba[3]) " :  " tab chr(ba[3]) cr ' 84 T

printl " next "
For i  = 0 To Len(st)
  Printl ba[i] + tab Chr(ba[i]) cr
Next i

wait

' same result possible without using 'at strptr(st)' possible with oxygen?

dim as string st = "BATMAN"
  'dim as byte ba at strptr(st) ' original
  'ba=>@st
  ' my idea below but doesn't work
  dim as byte ba=>strptr(st) ' @st
  printl str(ba[3]) " :  " tab chr(ba[3]) cr 

wait

Charles Pegge

strptr can be used on all string types. It will automatically return the string pointer, But for string and wstring types that are not parameters passed byval, you can use *st instead of strptr(st). However a null string will cause a GPF. So its not worth the risk.

Frank Brübach

Hello Charles must nerving again with this example .. I dont understand the Handling of *st

uses console

' pointer question 2 with 'dim as byte ba at strptr(st)'

' 1) works very well
'
int i
string cr = chr(13)+chr(10)

dim as string st = "BATMAN"
  dim as byte ba at strptr(st)
  printl str(ba[3]) " :  " tab chr(ba[3]) cr ' 84 T

printl " next "
For i  = 0 To Len(st)
  Printl ba[i] + tab Chr(ba[i]) cr
Next i

wait

' 2) doesnt work very well
'
' same result possible like above without using 'at strptr(st)' possible with oxygen?
'
' charles: "you can use *st instead of strptr(st)"
'
' how does it work correct below?
'
dim as string st2 = "BATMAN2"
  'dim as byte ba at strptr(st) ' original ok
 
  dim as byte ba2 *st2 'strptr(st)  ' doesnt work here, sorry
  printl str(ba2[3]) " :  " tab chr(ba2[3]) cr 

wait

'  strptr can be used on all string types. It will automatically return
'  the string pointer, But for string and wstring types that are not
'  parameters passed byval, you can use *st instead of strptr(st).
'  However a null string will cause a GPF. So its not worth the risk


Charles Pegge

#5
uses console
  dim as string st2 = "BATMAN2"
  '
  'dim as byte ba2 *st2 'strptr(st)  ' doesnt work here, sorry
  'correction:
  dim as byte ba2 at *st2
  'equivalent:
  dim as byte *ba2 : @ba2=*st2
  '
  printl str(ba2[3]) " :  " tab chr(ba2[3]) cr '84
wait