Enum value inside a case

Xawtor

Member
Licensed User
Longtime User
Good afternoon All,

Is it possible to create a enum variable then using it in a case.
After moving to the next case with a increment of that variable.

Cheer:D,
Xawtor

B4X:
Type SeasonsType (Summer As Int, Fall As Int, Winter As Int, Spring As Int)
Dim Seasons As SeasonsType
Seasons.Summer = 0:Seasons.Fall = 1:Seasons.Winter = Seasons.Spring = 3
   
   Select Seasons
      Case 0: Seasons++ 'Summer
      Case 1: Seasons++ 'Fall
      Case 2: Seasons++ 'Winter
      Case 3: Seasons++ 'Sping
   End Select

Or

B4X:
Type SeasonsType (Summer As String, Fall As String, Winter As String, Spring As String)
Dim Seasons As SeasonsType
Seasons.Summer = "Summer":Seasons.Fall = "Fall":Seasons.Winter = "Winter":Seasons.Spring = "Spring"
   
   Select Seasons
      Case "Summer":Seasons++ 'Summer
      Case "Fall":  Seasons++ 'Fall
      Case "Winter":Seasons++ 'Winter
      Case "Spring":Seasons++ 'Sping
   End Select
 

mc73

Well-Known Member
Licensed User
Longtime User
I would choose to define an array
B4X:
dim seasons()
seasons(0)="spring":seasons(1)="summer" 'and so on
and then I would run a loop
B4X:
 dim season as int
for season=0 to 3
'do what you want with seasons(season)
next
If of course I understood correctly what you want to achieve.
 
Upvote 0

Xawtor

Member
Licensed User
Longtime User
Of course, I forgot to precise what I want to achieve sorry that's my bad. I need a state machine structure, I used to do it like that with VHDL code. Do you think that for loop stay the best way.

Cheers,
Xawtor
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You have a state, call it 'summer'. From what I understand you want to move on to 'autumn'. Independently of what the intermediate processes are or can be, what I think is needed is simply a variable containing an index to the current state. We call it 'season'. So, every time you need to change 'season', you can add 1 to this state. If of course, again, I understand correctly, since I know nothing about vhdl. The thing is, which event will get to increase the state. As a reminder, b4a is an event driven language. If for some reasons you want changes to be performed without an event triggered, I think you can use a timer-based code.
 
Upvote 0

Xawtor

Member
Licensed User
Longtime User
Hi mc73,

Thanks for fast reply, I've tried the code, and It's complied well, but always my app crashes. Do you have any ideas why it did that? The time isn't a problem for my app because I want to decode a protocol through the a buffer, so I just want finished decoding before leaving that process.

Cheers,
xawtor
 
Upvote 0
Top