Android Question edtTextChanged, number only with try catch or isnumeric.

bodycode

Member
Licensed User
Longtime User
I have a problem! I want to assign ONLY a number to a variable, in realtime, without an error being generated, as I'm typing.

  • the TextChanged event(s) of an textedit box, needs to be able to accept anything you can throw at it from the android numeric keyboard without causing an error due to assigning the input to a float or double-type variable as you're typing a number.
  • The input MIGHT start with a minus sign. But! That's not a number when you start anything with a minus sign. So there will be an error, right? I tried this with a try/catch and tried with isnumeric. Can't figure this out. Also, a "null" or EMPTY value, can't cause an error either. And neither should the beginning of what you type, cause and error starting your input with a decimal point, a minus AND decimal point, or any combination of thereof. What to do?
 

stevel05

Expert
Licensed User
Longtime User
Have you tried setting the input type to NUMBERS or DECIMAL_NUMBERS in the designer? or in code with:

B4X:
EditText1.InputType=EditText1.INPUT_TYPE_DECIMAL_NUMBERS
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Of course! That will not prevent an error when assigning the input value to a floating-type or double-type variable!

The following causes an error when assigning:

  1. Backspacing until the field is blank (not a number, therefore, an error)
  2. Starting the field with a minus sign (a minus sign is not a number, therefore, an error)
  3. Starting the field with a decimal point, which is not a number, therefore, creating an error.
Any solutions?

Thanks

I have a problem! I want to assign ONLY a number to a variable, in realtime, without an error being generated, as I'm typing.

  • the TextChanged event(s) of an textedit box, needs to be able to accept anything you can throw at it from the android numeric keyboard without causing an error due to assigning the input to a float or double-type variable as you're typing a number.
  • The input MIGHT start with a minus sign. But! That's not a number when you start anything with a minus sign. So there will be an error, right? I tried this with a try/catch and tried with isnumeric. Can't figure this out. Also, a "null" or EMPTY value, can't cause an error either. And neither should the beginning of what you type, cause and error starting your input with a decimal point, a minus AND decimal point, or any combination of thereof. What to do?
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
I don't think that will work. Isnumber will return false as soon as a minus sign is typed it's the first character). Therefore, a negative number can never be entered? I will have to double-check this but please, let me know if I'm right or wrong about that?

Thank you.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
No technical reason. I wanted to show a user, that as they type a number, the values needed in the program are calculated in real time. Setting the input type of an editbox to decimal, then typing an input that starts with either a minus sign, a decimal point, OR a minus sign AND a decimal after the minus sign, and assigning the input to any type of number, will make make a try/catch exception come up every single time they do that. Even deleting back, and creating a blank input value, will cause an error.

I really wanted to avoid having a user first tap a button, then tap a dialog box, THEN see the keyboard also, as well.

Can I post some code here?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Is this any better?

B4X:
Sub EditText1_TextChanged (Old As String, New As String)
    If New = "" OR New = "-" OR New = "." OR New = "-." OR IsNumber(New) Then Return
    Msgbox("error in input "&New,"Input error")
    EditText1.Text=Old
End Sub
 
Last edited:
Upvote 0

bodycode

Member
Licensed User
Longtime User
Ahhhhhhhhh. A sigh of relief. Thank you so much.


BTW Steve, where can I actually LEARN everything there is to learn B4A programming, in a linear, tutorial-type fashion? I'm not really seeing that it is possible to truly learn programming B4A, from beginning to end, since it would seem to me that the docs are completely spread out, and not really focusing on exactly, how to program in this langauge?

I purchased the brand new and one-and-only B4A book, and quite frankly, though it is an improvement, it is NOT a B4A programming tutorial by any stretch of the imagination. Kind of a waste of money.

Which language does B4A match exactly? I know it doesn't match the Basic language.

For instance, the "label:" command. There's no label command that allows you to jump to a specific LINE in the old style spagetti-code fashion? I'm STILL not proficient in anything!


Looks like I'm going to have to learn Java in the final analysis of this whole thing!

Marsh

Is this any better?

B4X:
Sub EditText1_TextChanged (Old As String, New As String)
    If New = "" OR New = "-" OR New = "." OR New = "-." OR IsNumber(New) Then Return
    Msgbox("error in input "&New,"Input error")
    EditText1.Text=Old
End Sub
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Looks like I'm going to have to learn Java in the final analysis of this whole thing!

If you're lost with Basic4Android, then that will be worse with Java. IMHO, there are two important things to learn:
- object-oriented programming and event-driven programming;
- Android life cycle.
If you understand well these two things, you're ready to program with B4A. Learning the language itself is not the main difficulty.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
No, my Java, as well as OOP is coming along fine. Coherent documentation is what is needed. I'm making classes and methods, and accessing those methods in Java. What is needed is first, to understand the language completely (that includes object oriented programming the way Java does it). Then, I can proceed to write Android apps in java.

Secondly with B4A... The docs are not coherent at all! Bits and pieces spread everywhere, not one single LANGUAGE tutorial at all. I'm not giving up. I'm sticking with this.

Thanks.

Trying

If you're lost with Basic4Android, then that will be worse with Java. IMHO, there are two important things to learn:
- object-oriented programming and event-driven programming;
- Android life cycle.
If you understand well these two things, you're ready to program with B4A. Learning the language itself is not the main difficulty.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Coherent documentation is what is needed.

We all agree that the documentation is scattered and you're far from being the first to complain about it, but if people only complain and never try to do anything to improve that, things won't change. To my eyes, the Beginners' Guide written by Klaus is enough for most developers. So I don't feel any particular need to write a better documentation, but if you see clearly what's lacking (I don't), then take your pen and start writing. That being said, could you explain me what you call a language tutorial?
 
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Which language does B4A match exactly? I know it doesn't match the Basic language.

For instance, the "label:" command. There's no label command that allows you to jump to a specific LINE in the old style spagetti-code fashion? I'm STILL not proficient in anything!

There are just about as many dialects of Basic as there are computers. It might also be said the Microsoft's Visual Basic (in any version) does not match any Basic language. Basic versions tend to share the same syntax but the details depend, to a great extent, on the hardware on which they are to run.

Both Visual Basic and B4A share the fact that they are basically event driven. Beyond that there are, of course, many differences driven by the fact that they are intended to run on different operating systems so must be able to handle and support different things. Also, B4A MUST be able to be translated to Java in the end, so it cannot really do anything that cannot be done in Java - and that includes a "label:" command since Java does not support "goto" (although it is a reserved word in that language). You can simulate the effect of a "goto" some "label:" by using Select/Case statements. It takes a little planning, but it can be done.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ahhhhhhhhh. A sigh of relief. Thank you so much.


BTW Steve, where can I actually LEARN everything there is to learn B4A programming, in a linear, tutorial-type fashion? I'm not really seeing that it is possible to truly learn programming B4A, from beginning to end, since it would seem to me that the docs are completely spread out, and not really focusing on exactly, how to program in this langauge?

I purchased the brand new and one-and-only B4A book, and quite frankly, though it is an improvement, it is NOT a B4A programming tutorial by any stretch of the imagination. Kind of a waste of money.

Which language does B4A match exactly? I know it doesn't match the Basic language.

For instance, the "label:" command. There's no label command that allows you to jump to a specific LINE in the old style spagetti-code fashion? I'm STILL not proficient in anything!


Looks like I'm going to have to learn Java in the final analysis of this whole thing!

Marsh


Fundamental question:

you should write "spaghetti"! :D

and unfortunately it is difficult to develop without putting some spaghetti, sometimes
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The real BASIC part of the language really is quite straightforward, and would be recognized by anyone that has programmed in BASIC before. I'm talking about the keywords and structures here. But who wants to write apps that just count up to 100? Where it gets more complicated is when you want to interact with the Operating System ie. Android. There is no way to simplify this in any great manner.

I have been using B4A for about 2 and a half years, and looking back and remembering the learning curve, I think Erel has done a remarkable job in writing the libraries, and exposing the most important parts of the Android API's to B4A. He has made a powerful language that is not cluttered with the classes and methods that you may only really need to use once in a blue moon.

If there's something you do want to use that is not exposed, and you have or are willing to learn the Java skills required, you can write a library, or use reflection or even simpler now, use the JavaObject.

As Informatix mentioned, it's not really Basic4Android that you are learning, it's how to get the most from the Android Operating System, with it's security, lifecycles and quirks and bug's etc. The same things that plague developers on Java as well, but what we have to our advantage is that Basic4Android gives you a simpler, streamlined, very quick and effective method of developing for this platform.
 
Upvote 0
Top