Android Question Time

Discussion in 'Android Questions' started by Pilar-JLSineriz, Jul 9, 2015.

  1. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    Hello

    I want to do anything that I think that it's simply; to write the time (p.e. 23:10) in an edittext and to storage as date..
    Thanks
     
  2. sonicmayne

    sonicmayne Member Licensed User

    This will take a 24 hour string and parse it to a date, then write the result to a file.
    Code:
    Dim date As String = "23:10"
        
    Dim format As String = "HH:mm"
        
    Dim oformat As String = DateTime.DateFormat
        
    DateTime.DateFormat = format
        
    Dim parseddate As Long = DateTime.DateParse(date)
        
    DateTime.DateFormat = oformat
        
    File.WriteString("yourpath","yourfile",parseddate)
     
    lemonisdead and DonManfred like this.
  3. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    Thanks
    .. I use your code.. I see that transform HH:mm in ticks.. but have I the possibility to put a mask in the edittext so the user only can write in format "HH:mm"???
     
  4. sonicmayne

    sonicmayne Member Licensed User

    I haven't been able to test this, but this should work (requires the IME library):
    This will set the mask.
    Code:
    Dim IME As IME
        
    IME.SetCustomFilter(Txt,Txt.INPUT_TYPE_TEXT,"0123456789:")
    And when you are ready to validate the input:
    Code:
    Dim Matcher As Matcher = Regex.Matcher("(\d\d):(\d\d)",txt.Text)
        
    Do While Matcher.Find
            
    Dim hour As Int = Matcher.Group(1)
            
    Dim minute As Int = Matcher.Group(2)
            
    If hour < 0 OR hour > 23 Then
                
    Log("Invalid Hour!")
                
    Return
            
    End If
            
    If minute < 0 OR minute > 59 Then
                
    Log("Invalid Minute!")
                
    Return
            
    End If
            
    'Valid time! Do somthing here.
        Loop
     
    DonManfred likes this.
  5. sonicmayne

    sonicmayne Member Licensed User

    I just tested it, it works.
     
  6. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    thanks thanks I am going to test now!
     
  7. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    ... but if the user writes, for example, 2315 (without ":") there isn´t log with the error.. thanks for your help!!
     
  8. sonicmayne

    sonicmayne Member Licensed User

    Code:
    Dim Matcher As Matcher = Regex.Matcher("^(\d\d):(\d\d)$",txt.Text)
        
    Do While Matcher.Find
            
    Dim hour As Int = Matcher.Group(1)
            
    Dim minute As Int = Matcher.Group(2)
            
    If hour < 0 OR hour > 23 Then
                
    Log("Invalid Hour!")
                
    Return
            
    End If
            
    If minute < 0 OR minute > 59 Then
                
    Log("Invalid Minute!")
                
    Return
            
    End If
            
    'Valid time! Do somthing here.
            Return
        
    Loop
        
    Log("Invalid format!")
     
  9. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    ja ja ja............ I was writting sentences with split, ...............
     
  10. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    Thanks... always I look for difficulties!!
     
  11. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    .. I have problems if I write "return" between end if and Loop :oops:
     
  12. sonicmayne

    sonicmayne Member Licensed User

    What happens?
    It works here.

    Is it the Unreachable code detected warning? If so add 'ignore at the end of the Loop line.

    So it reads: Loop 'ignore
     
  13. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    it's Ok... thanks thanks... I am going to try sleep... the temperature is so high in Madrid (during the day 41ºC....)

    (your code with sentences in spanish!!!)
    Dim Matcher As Matcher = Regex.Matcher("(\d\d):(\d\d)",txtHORA.Text)
    Do While Matcher.Find
    Dim hour As Int = Matcher.Group(1)
    Dim minute As Int = Matcher.Group(2)
    If hour < 0 Or hour > 23 Then
    ToastMessageShow("HORA NO Válida, tiene que estar comprendida entre 0 y 23.",True)
    txtHORA.Text=DateTime.Time(DateTime.Now)
    Return
    End If
    If minute < 0 Or minute > 59 Then
    txtHORA.Text=DateTime.Time(DateTime.Now)
    ToastMessageShow("MINUTOS NO Válidos, tienen que estar comprendidos entre 0 y 59.",True)
    Return
    End If
    Return
    Loop
    ToastMessageShow("Formato de hora inválido",True)
     
    sonicmayne likes this.
  14. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    Hi... could you help me again???? thanks

    If I have one edittext with a date, p.e. 9/07/2015 and other with one time, p.e. 10:12, and two more editexts, with 10/07/2015 and 15:13, how I can calculate the minutes that there are between de dates???? Diference in minutes between 10/07/2015 15:13 and 9/07/2015 15:13
     
  15. Eumel

    Eumel Active Member Licensed User

    Take a look at THIS tutorial.
     
    sonicmayne likes this.
  16. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    ... I am reading the tutorial all the morning and I don´t get it.. I am crying!!!
     
  17. Eumel

    Eumel Active Member Licensed User

    Code:
    Dim startdate As String
        
    Dim starttime As String
        
    Dim enddate As String
        
    Dim endtime As String
        
    Dim start As Long
        
    Dim finish As Long
       
        
    Dim per As Period
       
        
    DateTime.DateFormat = "dd/MM/yyyy"
        
    DateTime.TimeFormat = "HH:mm"
       
        startdate = 
    "09/07/2015"
        starttime = 
    "10:12"
        enddate = 
    "10/07/2015"
        endtime = 
    "15:13"
       
        per = DateUtils.PeriodBetween(
    DateTime.DateTimeParse(startdate, starttime), DateTime.DateTimeParse(enddate, endtime))
       
        
    Log(per)
        
    Log((per.Days*24*60)+(per.Hours*60)+(per.Minutes)) 'calculates from given days/hours/minutes to minutes
       

       
        
    'another way
       
        start = 
    DateTime.DateTimeParse(startdate, starttime)
        finish = 
    DateTime.DateTimeParse(enddate, endtime)
       
        
    Dim difference As Long = finish - start 'here the ticks from difference
       
        
    Dim dif As Int = difference / 1000 / 60 'seconds = 1000 milliseconds
                                                'minutes = 60 seconds
       
        
    Log(dif)

    quick and dirty but i hope it helps
     
    sonicmayne and DonManfred like this.
  18. DonManfred

    DonManfred Expert Licensed User

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("Layout1")
        
    DateTime.DateFormat = "dd/MM/yyyy"
        
    DateTime.TimeFormat = "HH:mm"
    End Sub
    Sub Button1_Click
        
    Dim startdate As Long = DateTime.DateTimeParse(editStartDate.Text,editStartTIME.Text)   
        
    Dim enddate As Long = DateTime.DateTimeParse(EditEndDATE.Text,EditEndTIME.Text)   
        
    Dim p As Period = DateUtils.PeriodBetween(startdate,enddate)
        LabelResult.Text = 
    $"${p.Hours}H, ${p.Minutes}minutes"$
    End Sub
     

    Attached Files:

    sonicmayne likes this.
  19. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    Thanks Manfred...!! I am going to try now!!!
     
  20. Pilar-JLSineriz

    Pilar-JLSineriz Active Member Licensed User

    I've solved as follow (lblADP and lblADP1 are labels from AnotherDatepicker)

    Sub btnMinutos_Click

    Dim IniHORA As String = txtHORA.Text
    Dim FinHORA As String = txtHORA1.Text

    Dim IniDIA As Long = lblADP.Text
    Dim FinDIA As Long = lblADP1.Text

    Dim lngTimeFrom As Long = DateTime.DateTimeParse(DateTime.Date(IniDIA),IniHORA)
    Dim lngTimeTo As Long = DateTime.DateTimeParse(DateTime.Date(FinDIA),FinHORA)

    Dim TimeDiff As Period= DateUtils.PeriodBetween(lngTimeFrom, lngTimeTo)

    Dim intDias As Int = TimeDiff.Days
    Dim intHoras As Int = TimeDiff.Hours
    Dim intMinutos As Int= TimeDiff.Minutes

    lblTimeP1.Text=intDias*24*60 + intHoras*60+ intMinutos
    End Sub
     
    sonicmayne likes this.
Loading...