Android Question Edit Text Box Filtering

Gavin O'Connor

Member
Licensed User
Hi All,

I have a string I receive in an Edit Text Box from a Bluetooth device, I have the receiving and sending working 100%, now I am trying to "Filter out the data" by using a date function. I have a Start date and an End Date using the Date Dialog which is working 100% on the application, my only issue is how do I filter out my date in the string below?, so I can choose to save the info between the Start and End Date in a separate Edit Text Box.

Is there some sort of special "intring command" or special filter I can use?

Any help would be greatly appreciated...;-)

Received:: 19/09/2017 09:34:18 Warning:N Hazard:Y RemoteStop:N CommsCheck:N MaintMode:N Gen1CommsErr:N Gen2CommsErr:N Gen3CommsErr:N Gen4CommsErr:N Gen1LowVolt:N
 

DonManfred

Expert
Licensed User
Longtime User
get the first 30 chars ("Received:: 19/09/2017 09:34:18"), remove the "Received:: ", split sthe string on SPACE, Use the resulting two strings and parse them with the date methods (Datetime.ParseDateTime(datestr,timestr))... Note to check the dateformat first.
 
Upvote 0

Gavin O'Connor

Member
Licensed User
Hi Don,

Thanks for the mail,

I am still a beginner at this and can I assume the following?...:)

Button one (Start Button)

B4X:
Dim StartTime As Long
    StartTime = DateTime.DateParse ( Dd)

Button Two (end time)

B4X:
Dim EndTime As Long
    EndTime = DateTime.DateParse (Dd)

Dd being the Date Dialog
 
Upvote 0

Gavin O'Connor

Member
Licensed User
Hi Erel, my apologies as I am still battling with this,

I am saving the received information in a .txt format and then importing the "saved" data using an import button. Please see code below: I have this working for the exception that I am not sure where/how to parse the Date information. I also assume I can export this data to a Database and then too "search" specific dates to retrieve this info?

B4X:
If EditText4.Text.Trim = "" Then
        MsgboxAsync ("Please Enter Serial Number for the Import Function", "Strata 360" )
    Else
        Dim in As InputStream
        in = File.OpenInput(File.DirDefaultExternal, EditText4.Text & ".txt")
        Dim reader As TextReader
        reader.Initialize(in)
        Dim line As String
        line = reader.ReadAll
        Msgbox(line, "Downloaded Data")
        EditText3.Text = line
        reader.Close
    End If

Do you perhaps think it might be easier to modify the AsyncStreamText in the Bluetooth module code than to do as above?, so I can then choose from which date the info can be downloaded from?

Any help would be greatly appreciated,
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Never use TextReader unless you need to read a non-utf8 file.
2. Use Log instead of Msgbox.
3. Ignore my answer about DateDialog. It is not relevant.
4. Don't modify AsyncStreamsText.

Example of parsing this string with the help of RegexBuilder class:
B4X:
DateTime.DateFormat = "dd/MM/yyyy"
Dim s As String = "Received:: 19/09/2017 09:34:18 Warning:N Hazard:Y RemoteStop:N CommsCheck:N MaintMode:N Gen1CommsErr:N Gen2CommsErr:N Gen3CommsErr:N Gen4CommsErr:N Gen1LowVolt:N"
Dim rx As RegexBuilder
rx.Initialize.AppendEscaped("Received::").Append(rx.CharWhitespace).StartCapture.AppendAnyBut(Array(rx.CharWhitespace)).AppendAtLeastOne.EndCapture
Dim m As Matcher = Regex.Matcher(rx.Pattern, s)
If m.Find Then
   Dim DateString As String = m.Group(1)
   Dim ticks As Long = DateTime.DateParse(DateString)
   Log($"$DateTime{ticks}"$)
End If
 
Upvote 0
Top