I'm learning JAVA..

Erel

B4X founder
Staff member
Licensed User
Longtime User
Btw, is it possible to add in an if statement ":" like in vb?
No. This is by design.

And also what could be a great update to the next version is to be able to test a code without to install on the phone. Like i can do in java or xcode. Sometimes i only want to test a code and get the result to the log so no need to connect phone to run it... would be great to have such a feature.
It is already implemented with Debug (rapid) mode.
 

sorex

Expert
Licensed User
Longtime User
it installs once and then updates code parts. (untill you stop the app)

so it's not really a valid answer :)
 

sorex

Expert
Licensed User
Longtime User
if it is just a code sub it could build to a plain java jar. if it involved GUI stuff that would be harder ofcourse.
 

ilan

Expert
Licensed User
Longtime User
You need to install the app. But later when you modify the code it doesn't need to be reinstalled (not in all cases).

Didn't you notice it in B4i? That you don't need to approve the installation each time you run?

oh, i didnot mean that option, i noticed it of course, i only wonder after watching some java tutorials if it could be possible to do simple code without install the app.

like i have a list and want to get to the log the item in index 12 but dont want to install now the app only see if code if working or to get a true false, ..

also to explain maybe b4x with simple code snippets it would be very good to have such an option, it could be also a different app no need to implement it in b4a/b4i.
something where i can put a code and test if it is working and if not to find the error..

https: //www.youtube.com/watch?v=jWTjHmuuvJs


EDIT: this could be a great tool to make b4x tutorials...
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
Longtime User
This would be like the Immediate window in VB6 or the shell in MySQL. It would be a great addition to be able to test simple subs.
 

sorex

Expert
Licensed User
Longtime User
which part of that 3 hours movie are you refering too? I don't have that much time at work to look at all of that ;)
 

ilan

Expert
Licensed User
Longtime User
which part of that 3 hours movie are you refering too? I don't have that much time at work to look at all of that ;)

see in the middle how he put codes and test it and get result in log.
 

sorex

Expert
Licensed User
Longtime User
I like the idea.

eiter a seperate code panel that compiles to a JAR and outputs to the log

or

use something like in MS (transact)SQL where you select the lines of code and press execute


now I have a _test folder with a lot of mini projects just because of small routines I wrote to help the forum users.
 

ilan

Expert
Licensed User
Longtime User
I like the idea.

eiter a seperate code panel that compiles to a JAR and outputs to the log

or

use something like in MS (transact)SQL where you select the lines of code and press execute


now I have a _test folder with a lot of mini projects just because of small routines I wrote to help the forum users.

exactly. this is what i meant...
 

Troberg

Well-Known Member
Licensed User
Longtime User
it seems that from the moment when ELSE is used it forces you to use multiline.

this works then

B4X:
If x<=10 Then
Log(1):Log(2)
Else
Log(3):Log(4)
End If
End Sub

I don't remember if B4X has IIf or not. If not, it's very easy to write one yourself:

B4X:
Sub IIf(Condition as boolean, TruePart as object, FalsePart as object) as object
  If Condition then
    Return TruePart
  Else
    Return FalsePart
  End If
End Sub

Then, just call it like this for an inline if:

Log(IIf(ErrorString="", "OK", ErrorString))

That call will log the content of ErrorString if there is an error, or "OK" if it is empty (which I assume, in this context, means no error). Very neat, very useful for such things as providing default values or simple ifs (such as placing something at different positions depending on screen orientation).
 

sorex

Expert
Licensed User
Longtime User
actually the point was to be able to use the : to concatenate command or even end up in a 1 line if then/else statement like other languages allow you to do.
 

Troberg

Well-Known Member
Licensed User
Longtime User
Yeah, several commands on one line is useful. My favourite is:

B4X:
Select x
  Case 0 : Difficulty=5 : StartGame
  Case 1 : Difficulty=8 : StartGame
  Case 2 : Difficulty=9 : StartGame
  Case 3 : Difficulty=11 : StartGame
  Case 4 : GameWon
End Select

However, in many cases, the inline if allows you to achieve what you want. Not all cases, but many.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Many languages allow stacking statements on a single line. I personally never use it simply because it makes the code so much harder to read (for me at least) later on. I rarely even use single line IF statements hehe.

--- Jem
 

Troberg

Well-Known Member
Licensed User
Longtime User
Many languages allow stacking statements on a single line. I personally never use it simply because it makes the code so much harder to read (for me at least) later on. I rarely even use single line IF statements hehe.

I agree, I seldom use them myself. My excetions are the Select variant above, where the contents of the Case is trivial and similar for each Case, and when I have similar repeating sequences of lines, such as:

B4X:
txtInput1.Visible = True : txtInput1.Text = ""
txtInput2.Visible = True : txtInput2.Text = ""
txtInput3.Visible = True : txtInput3.Text = ""
txtInput4.Visible = True : txtInput4.Text = ""

It groups things together, so that the pattern is clearer. I get a clear block of similar lines, and it would be easy to spot a mistake. If I hadn't stacked the statements like this, I would have gotten a zig-zag pattern which hid the "same-ness" of the lines:

B4X:
txtInput1.Visible = True
txtInput1.Text = ""
txtInput2.Visible = True
txtInput2.Text = ""
txtInput3.Visible = True
txtInput3.Text = ""
txtInput4.Visible = True
txtInput4.Text = ""
 

ilan

Expert
Licensed User
Longtime User
just wrote this in my new b4i game

B4X:
If finishCD = 210 Then Player_Jump(-Player.Jump_Velocity * 0.33) : If soundon = 1 Then mpjump.Play

isn't it simpler like this?

ok, this is not working like it should... it handle it like there are 2 different if statements...
 
Last edited:
Top