Page 1 of 1

Fixed Lenght String Array in Structure [Solved]

Posted: Tue Jul 04, 2017 12:26 am
by alxfrnds
Hello, I'm starting with purebasic, what is wrong in my declaration? What is the correct way?
Fixed Length Array Strings into structure
Thanks:

Structure AcctRecord
User.s{80}
Password.s{30}
EAddress.s{80}
EPass.s{30}
USign.s{141}
AlwaysSign.i
AlwaysTag.i
Ed.s{64}
Fore.i
Back.i
intMusic.i
QuoteSymbol.s{2}
Thrd.i
Rnb.i
MDir.s{40}
DownDir.s{40}
Font.s{12}
DefMenu.i
DefOpts.i
Global.s{30} Tp(10)
Global.s{12} Dim Script(10)
Rotate.i
HNSUrn.s{4}
POP3Url.s{64}
SMTPUrl.s{64}
NNTPUrl.s{64}
ShowAll.s{1}
Global.l Dim TimeMonth(10)
LogEMail.s{32}
Defaults.i
UBirthday.s{3}
AltDNS.s{4}
RealName.s{80}
SetName.s{20}
MyIP.l
Padd.s{56}
EndStructure

Re: Fixed Lenght String Array in Structure

Posted: Tue Jul 04, 2017 1:47 am
by Lunasole
Hi. Should be something like this ^^

Code: Select all

EnableExplicit

Structure SOMESTRUCTURE
	; a dynamical array of 11 fixed strings (32 chars per string)
	; array size can be changed using Redim, unlike next one
	Array ExampleA.s{32}(10)
	
	; fixed array of 10 fixed strings (32 chars per string)
	ExampleB.s{32}[10]
EndStructure

; Also in your declaration "Global" is wrong, it's not used inside structures (it's generic keyword to declare anything in that "global scope")
Global A.SOMESTRUCTURE

; Dim also not used inside structure

Re: Fixed Lenght String Array in Structure

Posted: Tue Jul 04, 2017 3:30 pm
by skywalk
I prefer to append $ for string variables. Much easier to spot intended contents.

Code: Select all

Structure AcctRecord
  User${80}
  Password${30}
  EAddress${80}
  EPass${30}
  USign${141}
  AlwaysSign.i
  AlwaysTag.i
  Ed${64}
  Fore.i
  Back.i
  intMusic.i
  QuoteSymbol${2}
  Thrd.i
  Rnb.i
  MDir${40}
  DownDir${40}
  Font${12}
  DefMenu.i
  DefOpts.i
  Tp${30}[10]             ;<- Fixed array(0 to 9)
  Array Scripts${12}(10)  ;<- Dynamic array(0 to 10)
  Rotate.i
  HNSUrn${4}
  POP3Url${64}
  SMTPUrl${64}
  NNTPUrl${64}
  ShowAll${1}
  Array TimeMonth.l(10)  ;<- Dynamic array
  LogEMail${32}
  Defaults.i
  UBirthday${3}
  AltDNS${4}
  RealName${80}
  SetName${20}
  MyIP.l
  Padd${56}
EndStructure
Define.AcctRecord myAR
myar\Tp$[0] = "123456789012345678901234567890_1111111"
myar\Tp$[9] = "101010101010101010101010101010_1111111"
Debug myAR\Tp$[0]
Debug myAR\Tp$[9]
myar\Scripts$(0) = "123456789012345"
myar\Scripts$(10) = "101010101010101"
Debug myAR\Scripts$(0)
Debug myAR\Scripts$(10)

Re: Fixed Lenght String Array in Structure

Posted: Wed Jul 05, 2017 4:26 pm
by alxfrnds
Thanks guys, I will try tonight

Re: Fixed Lenght String Array in Structure

Posted: Thu Jul 13, 2017 11:35 pm
by alxfrnds
Guys, inside the structure is ok, but what is the right way to declare a fixed length array?

I tried:
Dim ReadIt.s{2}[100]
Global.s ReadIt{2}[100]
and
ReadIt.s{2}[100]

without success :(

thanks again

Re: Fixed Lenght String Array in Structure

Posted: Thu Jul 13, 2017 11:48 pm
by Demivec
alxfrnds wrote:Guys, inside the structure is ok, but what is the right way to declare a fixed length array?

I tried:
Dim ReadIt.s{2}[100]
Global.s ReadIt{2}[100]
and
ReadIt.s{2}[100]

without success :(

thanks again
If it is a dynamic array declare it as an array with DIM outside of a structure and ARRAY inside of a structure and enclose the dimensions in parens. If it is a fixed array inside of a structure only use the '[]' brackets to enclose the dimension.

Code: Select all

Dim ReadIt.s{2}(100)
Global Dim ReadItAgain.s{2}(100)

Structure blip
 Array ReadIt.s{2}(100) ;dynamic array
 ReadItAlso.s{2}[100] ;fixed array
EndStructure
skywalk showed these declarations (and commented them) in his code above.

Re: Fixed Lenght String Array in Structure

Posted: Thu Jul 13, 2017 11:52 pm
by alxfrnds
Worked :) :) :) Thanks
Demivec wrote:
alxfrnds wrote:Guys, inside the structure is ok, but what is the right way to declare a fixed length array?

I tried:
Dim ReadIt.s{2}[100]
Global.s ReadIt{2}[100]
and
ReadIt.s{2}[100]

without success :(

thanks again
If it is a dynamic array declare it as an array with DIM outside of a structure and ARRAY inside of a structure and enclose the dimensions in parens. If it is a fixed array inside of a structure only use the '[]' brackets to enclose the dimension.

Code: Select all

Dim ReadIt.s{2}(100)
Global Dim ReadItAgain.s{2}(100)

Structure blip
 Array ReadIt.s{2}(100) ;dynamic array
 ReadItAlso.s{2}[100] ;fixed array
EndStructure
skywalk showed these declarations (and commented them) in his code above.