Android Question Text_Changed Issue

Darren Llewellyn

Member
Licensed User
Longtime User
while using the text changed event to pass the information from the text box to a temporary store I have an issue with the way the number comes out for example if I enter the number 10 I get 01 in the box I'm using the code to pass it along
B4X:
Sub TxtReal_TextChanged (Old AsString, New AsString)

If old<>new Then

       TmpStore = TxtReal.Text

Else

       'Do Nothing

EndIf

End Sub

the box is set for decimal numbers every thing else is default settings

any help would be appreciated
 

Darren Llewellyn

Member
Licensed User
Longtime User
The Log shows 1 then 01 it seems to be the orientation change that may be the issue ant Idea why if I pass this variable back if the orientation changes it could cause this to happen?
 
Upvote 0

Darren Llewellyn

Member
Licensed User
Longtime User
here is the code from the activity
B4X:
#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
'Variables used in the app
    Dim StrRealW As String
    Dim StrScaleM As String
    Dim FltRealWorld As Float
    Dim FltScaleModAns As Float
    Dim TmpStore As String
    Dim TmpAnswer As String
    Dim TmpScalePos As Int
    Dim TmpScale As Int
    Dim ScaleChanged As Boolean
    Dim DblScaleAns As Double
    Dim IntScale As Int
    Dim ScaleUp As Boolean
    Dim Orientation As PhoneOrientation
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
'sets up the variables used in the Layout
    Dim PnlModelSize As Panel
    Dim PnlBg As Panel
    Dim PnlControls As Panel
    Dim ImgLogo As ImageView
    Dim ImgBanner As ImageView
    Dim LblReal As Label
    Dim LblScale As Label
    Dim LblScaleMod As Label
    Dim LblScaleAns As Label
    Dim TxtReal As EditText
    Dim CmdBack As Button
    Dim CmdExit As Button
    Dim CmdCalc As Button
    Dim LstRealWorld As Spinner
    Dim LstScale As Spinner
    Dim lstScaleMod As Spinner
    Dim CmdOtherScale As Button
'Sets Up the Variables For The Pop Up Panel  
    Dim PnlAddScale As Panel
    Dim LstAddScale As Spinner
    Dim LblAddScale As Label
    Dim CmdAddScale As Button
    Dim TxtAddScale As EditText
    Dim CmdCancelScale As Button
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("ModelSize")
'Sets up Images for the layout
    PnlBg.SetBackgroundImage(LoadBitmap(File.DirAssets, "steel-pasnel-pics.gif"))
    PnlControls.SetBackgroundImage(LoadBitmap(File.DirAssets, "steel-centre-panel.gif"))
    PnlModelSize.SetBackgroundImage(LoadBitmap(File.DirAssets, "steel-centre-paneldown.gif"))
    PnlAddScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "steel-centre-paneldown.gif"))
    CmdExit.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonRed.gif"))
    CmdBack.SetBackgroundImage(LoadBitmap(File.DirAssets, "Arrow-LeftGreen.gif"))
    CmdCalc.SetBackgroundImage(LoadBitmap(File.DirAssets, "EqualsGreen.gif"))
    CmdOtherScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "AddScaleGreen.gif"))
    CmdAddScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Tick-ButtonGreen.gif"))
    CmdCancelScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonRed.gif"))
    ImgBanner.Bitmap = LoadBitmap(File.DirAssets, "scal-calc-banner.gif")
    ImgLogo.SetBackgroundImage(LoadBitmap(File.DirAssets, "scalefind-logogreen.gif"))
    TxtReal.SetBackgroundImage(LoadBitmap(File.DirAssets, "TxtBg.gif"))
    TxtAddScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "TxtBg.gif"))
    LblScaleAns.SetBackgroundImage(LoadBitmap(File.DirAssets, "TxtBg.gif"))
    LstScale.Color = Colors.White
    LstScale.DropdownTextColor = Colors.White
'Adds data to ListViews
    LstRealWorld.Add("mm")
    LstRealWorld.Add("cm")
    LstRealWorld.Add("M")
    LstRealWorld.Add("Inch")
    LstRealWorld.Add("Foot")
    LstRealWorld.Add("Yard")
  
    LstScale.Add("200:1")
    LstScale.Add("150:1")
    LstScale.Add("100:1")
    LstScale.Add("75:1")
    LstScale.Add("50:1")
    LstScale.Add("25:1")
    LstScale.Add("10:1")
    LstScale.Add("9:1")
    LstScale.Add("8:1")
    LstScale.Add("7:1")
    LstScale.Add("6:1")
    LstScale.Add("5:1")
    LstScale.Add("4:1")
    LstScale.Add("3:1")
    LstScale.Add("2:1")
    LstScale.Add("1:1")
    LstScale.Add("1:2")
    LstScale.Add("1:3")
    LstScale.Add("1:4")
    LstScale.Add("1:5")
    LstScale.Add("1:6")
    LstScale.Add("1:8")
    LstScale.Add("1:9")
    LstScale.Add("1:10")
    LstScale.Add("1:12")
    LstScale.Add("1:24")
    LstScale.Add("1:25")
    LstScale.Add("1:35")
    LstScale.Add("1:48")
    LstScale.Add("1:72")
    LstScale.Add("1:144")
    LstScale.Add("1:288")
  
    lstScaleMod.Add("mm")
    lstScaleMod.Add("cm")
    lstScaleMod.Add("M")
    lstScaleMod.Add("Inch")
    lstScaleMod.Add("Foot")
    lstScaleMod.Add("Yard")
  
    LstAddScale.Add("ScaleUp")
    LstAddScale.Add("ScaleDown")
'Sets the Standards to Thier Base Settings
    StrRealW = "mm"
    StrScaleM = "mm"
    IntScale = 1
    LstScale.SelectedIndex = 15
  
    PnlAddScale.Visible = False
    TxtAddScale.Enabled = False
  
    TxtReal.RequestFocus
End Sub

Sub Activity_Resume
    Orientation.StartListening("orientation")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Orientation.StopListening
End Sub

Sub CmdBack_Down
    CmdBack.SetBackgroundImage(LoadBitmap(File.DirAssets, "arrow-leftpressed.gif"))
End Sub
Sub CmdBack_Up
    CmdBack.SetBackgroundImage(LoadBitmap(File.DirAssets, "Arrow-LeftGreen.gif"))
End Sub
Sub CmdBack_Click
    StartActivity(ScaleCalc)
    Activity.Finish
End Sub
Sub CmdExit_Down
    CmdExit.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonPressed.gif"))
End Sub
Sub CmdExit_Up
    CmdExit.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonRed.gif"))
End Sub
Sub CmdExit_Click
    Dim result As Int
    'Checks to See if you want to quit - Displays a message box
    result = Msgbox2("Are you Sure You Want To Exit?", "Close Application", "Yes", "", "No", LoadBitmap(File.DirAssets,"PS-Geekbot-Logo-5.gif"))
        If result = DialogResponse.Positive Then
            Activity.Finish
        Else
            'Exit
        End If
End Sub

Sub CmdCalc_Down
    CmdCalc.SetBackgroundImage(LoadBitmap(File.DirAssets, "EqualsRed.gif"))
End Sub
Sub CmdCalc_Up
    CmdCalc.SetBackgroundImage(LoadBitmap(File.DirAssets, "EqualsGreen.gif"))
End Sub

Sub LstRealWorld_ItemClick (Position As Int, Value As Object)
'loads the text Value of the Listbox to the Variable
    If Position = 0 Then
        StrRealW = "mm"
    Else If Position = 1 Then
        StrRealW = "cm"
    Else If Position = 2 Then
        StrRealW = "M"
    Else If Position = 3 Then
        StrRealW = "Inch"
    Else If Position = 4 Then
        StrRealW = "Foot"
    Else If Position = 5 Then
        StrRealW = "Yard"
    Else
        Return
    End If
End Sub
Sub LstScale_ItemClick (Position As Int, Value As Object)
'loads the text value of the list box to the variable and sets the scale up or down function
    If Position = 0 Then
        IntScale = 200
        ScaleUp = True
    Else If Position = 1 Then
        IntScale = 150
        ScaleUp = True
    Else If Position = 2 Then
        IntScale = 100
        ScaleUp = True
    Else If Position = 3 Then
        IntScale = 75
        ScaleUp = True
    Else If Position = 4 Then
        IntScale = 50
        ScaleUp = True
    Else If Position = 5 Then
        IntScale = 25
        ScaleUp = True
    Else If Position = 6 Then
        IntScale = 10
        ScaleUp = True
    Else If Position = 7 Then
        IntScale = 9
        ScaleUp = True
    Else If Position = 8 Then
        IntScale = 8
        ScaleUp = True
    Else If Position = 9 Then
        IntScale = 7
        ScaleUp = True
    Else If Position = 10 Then
        IntScale = 6
        ScaleUp = True
    Else If Position = 11 Then
        IntScale = 5
        ScaleUp = True
    Else If Position = 12 Then
        IntScale = 4
        ScaleUp = True
    Else If Position = 13 Then
        IntScale = 3
        ScaleUp = True
    Else If Position = 14 Then
        IntScale = 2
        ScaleUp = True
    Else If Position = 15 Then
        IntScale = 1
        ScaleUp = True
    Else If Position = 16 Then
        IntScale = 2
        ScaleUp = False
    Else If Position = 17 Then
        IntScale = 3
        ScaleUp = False
    Else If Position = 18 Then
        IntScale = 4
        ScaleUp = False
    Else If Position = 19 Then
        IntScale = 5
        ScaleUp = False
    Else If Position = 20 Then
        IntScale = 6
        ScaleUp = False
    Else If Position = 21 Then
        IntScale = 8
        ScaleUp = False
    Else If Position = 22 Then
        IntScale = 9
        ScaleUp = False
    Else If Position = 23 Then
        IntScale = 10
        ScaleUp = False
    Else If Position = 24 Then
        IntScale = 12
        ScaleUp = False
    Else If Position = 25 Then
        IntScale = 24
        ScaleUp = False
    Else If Position = 26 Then
        IntScale = 25
        ScaleUp = False
    Else If Position = 27 Then
        IntScale = 35
        ScaleUp = False
    Else If Position = 28 Then
        IntScale = 48
        ScaleUp = False
    Else If Position = 29 Then
        IntScale = 72
        ScaleUp = False
    Else If Position = 30 Then
        IntScale = 144
        ScaleUp = False
    Else If Position = 31 Then
        IntScale = 288
        ScaleUp = False
    End If
    ScaleChanged = True
    TmpScale = IntScale
    TmpScalePos = LstScale.SelectedIndex
End Sub
Sub lstScaleMod_ItemClick (Position As Int, Value As Object)
'loads the text Value of the Listbox to the Variable
    If Position = 0 Then
        StrScaleM = "mm"
    Else If Position = 1 Then
        StrScaleM = "cm"
    Else If Position = 2 Then
        StrScaleM = "M"
    Else If Position = 3 Then
        StrScaleM = "Inch"
    Else If Position = 4 Then
        StrScaleM = "Foot"
    Else If Position = 5 Then
        StrScaleM = "Yard"
    Else
        Return
    End If
End Sub

Sub CmdCalc_Click
    Dim Result As Int
'Checks That a valid data has been entered into the TxtReal Box
    If TxtReal.Text = "" Then
        Result = Msgbox2("A Value Must Be Enterd For This Calculation", "Incorrect Data Entered", "OK", "", "", LoadBitmap(File.DirAssets,"geekbot-no2red.gif"))
        If Result = DialogResponse.Positive Then
            TxtReal.Text = ""
            TxtReal.RequestFocus
            Return
        Else
            Return
        End If
    Else If TxtReal.Text <1 Then
        Result = Msgbox2("Only Positive Numbers Are Allowed", "Incorrect Data Entered", "OK", "", "", LoadBitmap(File.DirAssets,"geekbot-no2red.gif"))
        If Result = DialogResponse.Positive Then
            TxtReal.Text = ""
            TxtReal.RequestFocus
            Return
        Else
            Return
        End If
    Else
        FltRealWorld = TxtReal.Text
    End If
'calls the subroutine and displays the answer
    If ScaleUp = True Then
        DblScaleAns = FltRealWorld*IntScale
    Else
        DblScaleAns = FltRealWorld/IntScale
    End If
    Calcs.GetModSize
    LblScaleAns.Text = FltScaleModAns
    TmpAnswer = LblScaleAns.Text
End Sub
Sub CmdOtherScale_Up
    CmdOtherScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "AddScaleGreen.gif"))
End Sub
Sub CmdOtherScale_Down
    CmdOtherScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "AddScalered.gif"))
End Sub
Sub CmdOtherScale_Click
    LstAddScale.SelectedIndex = 1
    ScaleUp = False
    PnlAddScale.Visible = True
    TxtAddScale.Enabled = True
    TxtAddScale.RequestFocus
End Sub


Sub CmdAddScale_Click
    Dim Result As Int
'Checks That a valid data has been entered into the TxtReal Box
    If TxtAddScale.Text = "" Then
        Result = Msgbox2("A Value Must Be Enterd For This Calculation", "Incorrect Data Entered", "OK", "", "", LoadBitmap(File.DirAssets,"geekbot-no2red.gif"))
        If Result = DialogResponse.Positive Then
            TxtAddScale.Text = ""
            TxtAddScale.RequestFocus
            Return
        Else
            Return
        End If
    Else If TxtAddScale.Text <1 Then
        Result = Msgbox2("Only Positive Numbers Are Allowed", "Incorrect Data Entered", "OK", "", "", LoadBitmap(File.DirAssets,"geekbot-no2red.gif"))
        If Result = DialogResponse.Positive Then
            TxtAddScale.Text = ""
            TxtAddScale.RequestFocus
            Return
        Else
            Return
        End If
    Else
        IntScale = TxtAddScale.Text
    End If
    PnlAddScale.Visible = False
    TxtAddScale.Enabled = False
    TxtReal.RequestFocus
End Sub
Sub CmdAddScale_Up
    CmdAddScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Tick-ButtonGreen.gif"))
End Sub

Sub CmdAddScale_Down
    CmdAddScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Tick-ButtonPressed.gif"))
End Sub

Sub LstAddScale_ItemClick (Position As Int, Value As Object)
    If Position = 0 Then
        ScaleUp = True
    Else
        ScaleUp = False
    End If
End Sub
Sub CmdCancelScale_Down
    CmdCancelScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonPressed.gif"))
End Sub
Sub CmdCancelScale_Up
    CmdCancelScale.SetBackgroundImage(LoadBitmap(File.DirAssets, "Close-ButtonRed.gif"))
End Sub
Sub CmdCancelScale_Click
Dim Result As Int
    If TxtAddScale.Text = "" Then
        PnlAddScale.Visible = False
    Else
        Result = Msgbox2("A scale has been entered Are you Sure you want to Cancel", "Incorrect Data Entered", "OK", "","NO", LoadBitmap(File.DirAssets,"geekbot-no2red.gif"))
        If Result = DialogResponse.Positive Then
            PnlAddScale.Visible = False
            TxtAddScale.Enabled = False
        Else
            Return
        End If
    End If
  
End Sub
Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
    LblScaleAns.Text = TmpAnswer
    TxtReal.Text = TmpStore
    If ScaleChanged = True Then
        LstScale.SelectedIndex = TmpScalePos
        IntScale = TmpScale
    Else
        'do nothing
    End If
  
End Sub

Sub TxtReal_FocusChanged (HasFocus As Boolean)
    If HasFocus = True Then
        TxtReal.Text = ""
    Else
    End If
End Sub
Sub TxtAddScale_FocusChanged (HasFocus As Boolean)
    If HasFocus = True Then
        TxtAddScale.Text = ""
    Else
        'do nothing
    End If
End Sub


Sub TxtReal_TextChanged (Old As String, New As String)
    If Old<>New Then
        TmpStore = TxtReal.Text
        LblScaleAns.Text = TmpStore
        Log(New)
        TxtReal.Text = TmpStore
    Else
        'Do nothing
    End If
End Sub
Hope this helps as the complete file was too large to upload
 
Upvote 0

Darren Llewellyn

Member
Licensed User
Longtime User
What is the purpose of this code:
B4X:
Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
   LblScaleAns.Text = TmpAnswer
   TxtScale.Text = TmpScale
   TxtInput.Text = TmpStore
End Sub
it passes the variables to the variation when the screen goes from portrait to landscape and vice versa, it works for a project with a single activity but not with more than one.
 
Upvote 0
Top