Fixed Lenght String Array in Structure [Solved]

Just starting out? Need help? Post your questions and find answers here.
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Fixed Lenght String Array in Structure [Solved]

Post 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
Last edited by alxfrnds on Thu Jul 13, 2017 11:53 pm, edited 1 time in total.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Fixed Lenght String Array in Structure

Post 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
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Fixed Lenght String Array in Structure

Post 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)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Re: Fixed Lenght String Array in Structure

Post by alxfrnds »

Thanks guys, I will try tonight
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Re: Fixed Lenght String Array in Structure

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Fixed Lenght String Array in Structure

Post 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.
alxfrnds
User
User
Posts: 10
Joined: Fri Jun 30, 2017 1:13 am

Re: Fixed Lenght String Array in Structure

Post 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.
Post Reply