Android Question How to assign the value of a input GUI Edit control variable to a StringFunction variable

beelze69

Active Member
Licensed User
Longtime User
Hi !

This is regarding Margaret's StringFunctions Post on https://www.b4x.com/android/forum/threads/string-functions.10365/

Sorry if I sound too basic.

My doubt:


I have a EditText control in b4a called myEditText. I have used IME to ensure only input values '0123456789".

Now I want to check if the INPUTTED VALUE of myEditText is 0 i.e. if the inputted value is 0 then I must give a message saying 0 is not allowed etc.

Now StringFunctions has a VAL() function which will give you the Value of the inputted text.

I understand that first I must declare a StringFunction variable and then Initialize it ..

But I don't know how to assign the value of the EditText control to the StringFunction variable..


Please help.

Thanks.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private EditText1 As EditText
    Dim sf As StringFunctions
End Sub

Public Sub Initialize
    sf.Initialize
End Sub

Private Sub EditText1_FocusChanged (HasFocus As Boolean)
    If HasFocus = False Then
        If sf.Val(EditText1.Text) = 0 Then
            xui.MsgboxAsync("Zero is not allowed!", "Error")
            Return
        End If
    End If
End Sub
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
I don't recommend using StringFunctions. Just learn the simple B4X built-in string functions.

B4X:
If EditText1.Text = "0" Then
xui.MsgboxAsync("Zero is not allowed!", "Error")
End If

Sorry Erel,

I wanted to get the INSIDE NUMERICAL value meaning EditText1.Text="0" will not match with EditText1.Text="00" ; ... but the inside NUMERICAL value of both is 0 .. End-user may input "0" or "00" or "0000" etc. and it is not possible to trap all such scenarios
But the inside NUMERIC value of such cases is always zero and we can trap that...

Another different scenario - Suppose EditText1.Text="ABC" (here inside NUMERIC value is again 0);
So what is the eqvt. string function in B4X for getting the INSIDE NUMERIC VALUE of a string... ?

Thanks ..
 
Last edited:
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private EditText1 As EditText
    Dim sf As StringFunctions
End Sub

Public Sub Initialize
    sf.Initialize
End Sub

Private Sub EditText1_FocusChanged (HasFocus As Boolean)
    If HasFocus = False Then
        If sf.Val(EditText1.Text) = 0 Then
            xui.MsgboxAsync("Zero is not allowed!", "Error")
            Return
        End If
    End If
End Sub
Hi Aeric,

Thanks a lot.! Will try this out..
 
Upvote 0
Top