Android Question Sgn() equivalent in B4A?

Midimaster

Active Member
Licensed User
Hi, sorry for ask this simple question, but I cannot find it...

I'm searching the B4A keywords for the function, which returns TRUE on negativ values. like Sgn() in other languages.

And is there a language referencce not sorted alphabetic but by topics, f.e. "Variables", "String Manipulation", etc
 

Sandman

Expert
Licensed User
Longtime User
I'm searching the B4A keywords for the function, which returns TRUE on negativ values. like Sgn() in other languages.
I don't think there exist one, but you can easily create your own in a code module with something like this
B4X:
Sub Sgn(theValue As Int) As Boolean
    return theValue < 0
End Sub

And is there a language referencce not sorted alphabetic but by topics, f.e. "Variables", "String Manipulation", etc
Yes: https://www.b4x.com/android/forum/threads/b4x-documentation-booklets.88985/
 
Upvote 0

Midimaster

Active Member
Licensed User
thanks... it really does not exist...ok!
I know this documentations, but they are more organized like tutorials, but not like a "all about..."
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub Sgn(theValue As Int) As Int
    return theValue/abs(theValue)
End Sub

or

B4X:
Sub Sgn(theValue As Int) As Int
    if theValue<>0 then return theValue/abs(theValue)
    return theValue
End Sub



WARNING
NB.
To remove doubts, the first example works correctly and does not generate any errors. Even I was amazed when I tried it. I attach the image.

Maybe @Erel would say it's not a good way, but it works
But in doubt I suger the second

The same in B4J. If you log(0/0) it returns NaN. But if you use log(sgn(0)) it returns 0
 
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
And is there a language referencce not sorted alphabetic but by topics, f.e. "Variables", "String Manipulation", etc

Yes, there is, but it is a book - ISBN 9781512296259. The index in my edition shows "Variables, 165, 228" and "String functions, 300". I have been using B4A for six years but I still turn to this book almost every week.

I find documentation to be the one weakness of this site, but I think that this is a personal thing; there are plenty of Users who seem to be able to find everything.
 
Upvote 0

Midimaster

Active Member
Licensed User
Thanks to all! Intensive discussion. Of course I was able to create my own SGN() function, only want to know, where the B4X function is hidding itself.

@Brian:
A good documentation is the best way to create a successfull app, tool, language or whatever...
People are tired exploring things tot long or getting frustated by finding no way to continue.

The documentation of B4A is really good if I'm already a programmer . I know languages, which I could not beginn because of the bad/non existing documentation. The "how to start" is amazing and the possibility of immediately transfer/test apk to the smartphone frees you from understanding the packing process.
And where informations are missing...the people in the forum are amazing helpful. So it could be a good language for very starters....

But, I think there is no document "Learning B4X from Zero" at the moment. This could add schools and students to B4X
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…