View previous topic :: View next topic |
Author |
Message |
Sarek
Joined: 15 Oct 2009 Posts: 72
|
Posted: Fri Oct 09, 2015 8:51 am Post subject: wish for BASCOM future versions => user defined stuctures |
|
|
here an example for my wish "user defined stuctures"
Code: |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' User defined variable structures
' with optional preset values
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Define Pos_xy as Struct
X as Word : X = 50
Y as Word : Y = 10
End_Struct
Define Dimension_wh as Struct
width as Word : width = 20
height as Word : height = 100
End_Struct
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' User defined variable structure
' with substructures
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Define Box_var as Struct
Pos as Pos_xy
Dimension as Dimension_wh
Line_width as Byte : Line_width = 16
End_Struct
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' DIM a variable Structures
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim My_Box_1 as Box_var
Dim My_Box_2 as Box_var
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' example Accessing variable Structures
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My_Box_1.Pos.X = 20
My_Box_1.Pos.Y = 100
...
...
My_Box_2.Pos.X = 200
My_Box_2.Pos.Y = 180
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Sub with variable Structures
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Draw_Box (Box as Box_var)
If Box.Pos.X > 150 Then ...
...
...
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Call Subs
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Call Draw_Box (My_Box_1)
Call Draw_Box (My_Box_2)
...
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Oct 12, 2015 2:51 am Post subject: |
|
|
If you can confine your structures to contain only variables of one data type ( words ), you could use an array. By naming the element indexes as constants, you can achieve almost exactly the same result.
But yes, now that the bigger AVRs have plenty of SRAM memory, it could be useful to implement the Basic TYPE construction. One issue still is that its not obvious to the programmer how much memory is being used, and its very easy to create structures which use far more memory than some AVRs have. At least with arrays, a glance at the relevant DIM statement shows how much memory is allocated.
Not sure about nested structures like you want, that is another level of complexity.
Mark ? _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Wed Oct 14, 2015 10:30 pm Post subject: |
|
|
when you type :
Type Test
Aa As Byte
Bb As Word
End Type
and look at the code explorer you know this wish is already on the todo list. when it is actually released for the compiler i can not tell. a matter of priorities. _________________ Mark |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Thu Oct 15, 2015 12:17 am Post subject: |
|
|
As usual Mark, you are way ahead of us mere mortals ! _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
Sarek
Joined: 15 Oct 2009 Posts: 72
|
Posted: Thu Oct 15, 2015 12:24 pm Post subject: |
|
|
albertsm wrote: | when you type :
Type Test
Aa As Byte
Bb As Word
End Type
and look at the code explorer you know this wish is already on the todo list. when it is actually released for the compiler i can not tell. a matter of priorities. |
Cool!
|
|
Back to top |
|
|
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Fri Oct 23, 2015 9:09 pm Post subject: |
|
|
I feel stupid. What is a struct? and whats its importance?
I see it ALL the time in C, and I am not a C developer so it eludes me. |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Oct 26, 2015 7:43 am Post subject: |
|
|
The equivalent basic term is a TYPE. Ie a collection of lower order variables of different sorts, but treated together into one variable name. Useful, but can be done with arrays and overlays in Bascom. _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Mon Oct 26, 2015 1:54 pm Post subject: |
|
|
so TYPE is just a pointer in memory to those variable locations defined under it? |
|
Back to top |
|
|
AdrianJ
Joined: 16 Jan 2006 Posts: 2483 Location: Queensland
|
Posted: Mon Oct 26, 2015 10:46 pm Post subject: |
|
|
Yes, you could look at it like that. The advantage is in the way you reference any of the components. See a full description of TYPE in Visual Basic ( or soon in Bascom ! ) _________________ Adrian Jansen
Computer language is a framework for creativity |
|
Back to top |
|
|
techknight
Joined: 21 Apr 2008 Posts: 231
|
Posted: Tue Oct 27, 2015 3:29 pm Post subject: |
|
|
I never knew it even existed, and ive wrote alot of stuff. But the stuff I write have all been control systems related with no games, etc.. So maybe I never needed it for anything. |
|
Back to top |
|
|
Sarek
Joined: 15 Oct 2009 Posts: 72
|
Posted: Fri Jun 07, 2019 8:18 am Post subject: |
|
|
@Mark
any news with this feature? |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Fri Jun 07, 2019 7:07 pm Post subject: |
|
|
it's frustrating
as Mark told you: It's a matter of time and it will be there if you can see it it newer version...
you can't speed up the process by asking multible times...
clear now?
German language:
Mark macht wirklich alles Menschen mögliche und bemüht sich sehr.
Wenn er sagt, dass es kommt, dann kommt es auch.
Weil er aber an den neuen Programmieralgos hängt, was einfach wichtiger ist, dauert es eben noch.
Es ist ohnehin eine kostenlose Leistung!
Geduld junger Padawn _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Sat Jun 08, 2019 8:58 am Post subject: |
|
|
six1 wrote: | multible times... |
Is this what a multiviprator does? |
|
Back to top |
|
|
six1
Joined: 27 Feb 2009 Posts: 553
|
Posted: Mon Jun 10, 2019 7:20 pm Post subject: |
|
|
maybe
english isn't my native language and sometimes i can be very creative _________________ For technical reasons, the signature is on the back of this message. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2259
|
Posted: Mon Jun 10, 2019 9:01 pm Post subject: |
|
|
six1 wrote: | english isn't my native language | I know, but I was not able to resist.
Quote: | sometimes i can be very creative | Be creative all the time |
|
Back to top |
|
|
|