User Tools

Site Tools


arrays_20of_20structures_20_28lbb_29

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

arrays_20of_20structures_20_28lbb_29 [2018/03/31 13:19]
127.0.0.1 external edit
arrays_20of_20structures_20_28lbb_29 [2018/04/17 15:10] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //by Richard Russell, December 2014//\\ \\  One of the language extensions provided by [[http://​www.lbbooster.com/​|LB Booster]] is native **arrays of structures**. These can be useful for structured data storage within a program, or when calling a Windows API function (for example [[http://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd162814.aspx|Polygon]]) which requires an array of structures as one of its parameters.\\ \\  The syntax for declaring an array of structures is very similar to that for declaring a single structure; the only difference is the addition of the dimension(s) in parentheses:​\\ ​ //by Richard Russell, December 2014//\\ \\  One of the language extensions provided by [[http://​www.lbbooster.com/​|LB Booster]] is native **arrays of structures**. These can be useful for structured data storage within a program, or when calling a Windows API function (for example [[http://​msdn.microsoft.com/​en-us/​library/​windows/​desktop/​dd162814.aspx|Polygon]]) which requires an array of structures as one of its parameters.\\ \\  The syntax for declaring an array of structures is very similar to that for declaring a single structure; the only difference is the addition of the dimension(s) in parentheses:​\\ ​
 +<code lb>
   STRUCT sname(dims),​ member1 AS type, member2 AS type... ​   STRUCT sname(dims),​ member1 AS type, member2 AS type... ​
 +</​code>​
 Arrays of structures may have any number of dimensions, limited only by available memory. As with ordinary numeric and string arrays the index value runs from 0 to the specified maximum dimension.\\ \\  Accessing an individual member, in order to change or read its value, again uses a syntax very similar to that used for a single (scalar) structure:​\\ ​ Arrays of structures may have any number of dimensions, limited only by available memory. As with ordinary numeric and string arrays the index value runs from 0 to the specified maximum dimension.\\ \\  Accessing an individual member, in order to change or read its value, again uses a syntax very similar to that used for a single (scalar) structure:​\\ ​
 +<code lb>
   sname(index).member.struct = newvalue   sname(index).member.struct = newvalue
   PRINT sname(index).member.struct   PRINT sname(index).member.struct
 +</​code>​
 \\  To pass the entire array of structures as a parameter to an API function use the following syntax:​\\ ​ \\  To pass the entire array of structures as a parameter to an API function use the following syntax:​\\ ​
 +<code lb>
   sname() AS struct   sname() AS struct
 +</​code>​
 Note the use of a pair of parentheses with nothing in between.\\ \\  Here are a couple of examples of the use of arrays of structures. Firstly an adaptation of the program by Dennis McKinney at the [[http://​lbpe.wikispaces.com/​ArraysAndStructs|Lliberty BASIC Programmer'​s Encyclopedia]]:​\\ ​ Note the use of a pair of parentheses with nothing in between.\\ \\  Here are a couple of examples of the use of arrays of structures. Firstly an adaptation of the program by Dennis McKinney at the [[http://​lbpe.wikispaces.com/​ArraysAndStructs|Lliberty BASIC Programmer'​s Encyclopedia]]:​\\ ​
 +<code lb>
   '​define array of 100 structures   '​define array of 100 structures
        ​struct test(99),_        ​struct test(99),_
Line 44: Line 51:
   [quit]   [quit]
        end        end
 +</​code>​
 \\  Secondly, an example of passing an array of structures to an API function:​\\ ​ \\  Secondly, an example of passing an array of structures to an API function:​\\ ​
 +<code lb>
       nomainwin       nomainwin
       open "​Structure array" for graphics as #w       open "​Structure array" for graphics as #w
Line 64: Line 73:
       close #w       close #w
       end       end
 +</​code>​
arrays_20of_20structures_20_28lbb_29.1522502345.txt.gz ยท Last modified: 2018/03/31 13:19 by 127.0.0.1