View previous topic :: View next topic |
Author |
Message |
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Mon Feb 21, 2022 12:11 pm Post subject: Select Case Syntax |
|
|
Hi,
How do you implement a multiple line/statements for a select case statement?
As shown in the example,
[code]
Select Case I
Case 1 : Print "1"
Case 2 : Print "2"
Case 3 To 5 : Print "3-5"
Case Is >= 10 : Print ">= 10"
Case Else : Print "Not in Case statement"
End Select
[/code]
There is only one line to be executed after each "case" is true, how do we implement if there needs to be a multiple lines to be executed for a "case" that is true. Example,
[code]
Select Case I
Case 1 :
Print "1"
X = X + 1
Print X
Case 2 : Print "2"
Case 3 To 5 : Print "3-5"
Case Is >= 10 : Print ">= 10"
Case Else : Print "Not in Case statement"
End Select
[/code]
The above does not work and am not sure how to handle the proper syntax.
Thanks,
Albert
[b][color=red](BASCOM-AVR version : 2.0.8.5 )[/b][/color]
Last edited by ATIU on Fri Feb 25, 2022 1:09 am; edited 5 times in total |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Mon Feb 21, 2022 4:54 pm Post subject: |
|
|
Works for me with multiple lines.
I only use one command per line.
Maybe you would try that.
Regards
Huberrt |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Tue Feb 22, 2022 7:14 am Post subject: |
|
|
Got it, what I was initially trying to do was;
[code]
Select Case I
Case 1: Print "I=1"
Case 2:
Print "I=2"
X = X + 1
Print " X=" ; X
Case Else
Print "Else"
End Select
[/code]
But as pointed out by EDC, should be this,
Select Case I
Case 1
Print "I=1"
Case 2
Print "I=2";
X = X + 1
Print " X=" ; X
Case Else
Print "Else"
End Select
No ":" after the case statement followed by the multiple lines to be executed if the case is true.
Thanks for the help,
Albert
Last edited by ATIU on Fri Feb 25, 2022 1:11 am; edited 2 times in total |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Feb 22, 2022 9:44 am Post subject: |
|
|
Not even close.
Quote: | But as pointed out by EDC, should be this, |
No. EDC pointed out, that both of his versions actually work.
Read more carefully, including this:
EDC wrote: | Please use "Code" tags when posting. |
If you do not know how code-tags work, feel free to ask. |
|
Back to top |
|
|
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Thu Feb 24, 2022 12:38 pm Post subject: |
|
|
Sorry MWS, you may have misunderstood.
I already "Got It" and understand where I went wrong using ":" after the case statements. I was trying to understand the help file samples.
Lastly, if you will be kind enough to explain how to use code tags as I am not familiar with such. Thank you,
Albert |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 24, 2022 8:51 pm Post subject: |
|
|
ATIU wrote: | Lastly, if you will be kind enough to explain how to use code tags as I am not familiar with such. |
There are several ways, I'll describe the easiest one.
Select all your code in the message editor:
Dim A As Byte
Dim B As Byte
A = 1
B = A
Then click the 'Code' button.
Code: | Dim A As Byte
Dim B As Byte
A = 1
B = A |
Code is then shown properly and does not mix into the message. |
|
Back to top |
|
|
ATIU
Joined: 15 Oct 2004 Posts: 534
|
Posted: Fri Feb 25, 2022 1:06 am Post subject: |
|
|
Thanks MWS and let me try to edit my previous post for clarity.
Albert |
|
Back to top |
|
|
|