B4R Question If receivenumber=1 then use in next IF the number - If mydevice1=36 then...

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please for advice. It is possible to do simpliest code than this?
B4X:
receivecode=1
If receivecode=1 then
 if mydevice1=56 then "start"
 if mydevice1=153 then "stop"
End if

If receivecode=2 then
 if mydevice2=56 then "start"
 if mydevice2=153 then "stop"
 End if 
 ........

It is possible to write with B4R something like...

receivecode=1
if mydevice(receivecode)=56 then "start"
if mydevice(receivecode)=153 then "stop"

Please for advice,
best regards
p4ppc
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Sure, just add Subs below and remove QUOTES
B4X:
Sub start
    '... code to start what you want
End Sub

Sub stop
    '... code to stop what you want
Edn Sub

Also make the names a little more specific then "start" and "stop", for example "startCar" and "stopCar", you'll appreciate that later.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
William, thank you for your answer,

but (my bad english) there is another question...
I want put the number from receivecode to the IF condition ....If mydevice(receivecode)=56 then something

Is here the way?
p4ppc
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I assume that you have two devices and that

B4X:
    Dim mydevices(2) As Int
    'mydevices(0) = 56 Or 153 set by either by a direct assignment or by a Subroutine
    'mydevices(1) = 56 Or 153 set by either by a direct assignment or by a Subroutine

    'Then you use
    If mydevices(receivecode) = 56 then
        '...
    Else If mydevices(receivecode) = 153 then
        '...
    End If
    
    'Or
    Select mydevices(receivecode)
        Case 56
            '...
        Case 153
            '...
    End Select
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
There are a few important differences between B4R and other B4X products, but the language syntax is the same.
I recommend the Booklets by Klaus (see Documentation at the top of this screen), in particular...

B4X Getting Started - This booklet explains how to start with each B4X product (B4A, B4i, B4J and B4R).
B4X Basic Language - This booklet explains the Basic Language for B4A, B4i, B4J and B4R.
 
Upvote 0
Top