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
Fixed Lenght String Array in Structure [Solved]
Fixed Lenght String Array in Structure [Solved]
Last edited by alxfrnds on Thu Jul 13, 2017 11:53 pm, edited 1 time in total.
Re: Fixed Lenght String Array in Structure
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"
Re: Fixed Lenght String Array in Structure
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
Re: Fixed Lenght String Array in Structure
Thanks guys, I will try tonight
Re: Fixed Lenght String Array in Structure
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
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
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.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
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
Re: Fixed Lenght String Array in Structure
Worked
Thanks



Demivec wrote: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.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 againskywalk showed these declarations (and commented them) in his code above.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