DateDialog Cancel Button Click

Mahares

Expert
Licensed User
Longtime User
I have 2 edittext views that hold each a certain date. I can change either dates using the below function, which is OK. But, if I click on either text box and decide to change my mind by clicking the 'Cancel' button, the dates do not revert back to what were in the boxes. They both display blank dates. Can someone please see where I falter. Thanks

B4X:
Dim strDate as string
dim ViewStartD, ViewEndD   as edittext

Sub InputBoxDD(Prompt As String, Title As String) As String  
    Dim Dd As DateDialog
    Dim ret As Int
    Dd.Year = DateTime.GetYear(DateTime.now)     
    Dd.Month = DateTime.GetMonth(DateTime.now)         
    Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)     
    ret = Dd.Show(Prompt, Title, "Ok", "Cancel", "", Null)
    If ret=-1 Then
         strDate= DateTime.Date(Dd.DateTicks)
   End If
End Sub

Sub ViewStartD_Click
      InputBoxDD("Accept or change START Date","DATE SELECTION SCREEN")
      ViewStartD.text=strDate
End Sub
Sub ViewEndD_Click
      InputBoxDD("Accept or change END Date","DATE SELECTION SCREEN")
      ViewEndD.text=strDate
      
End Sub
 
Last edited:

kickaha

Well-Known Member
Licensed User
Longtime User
I suspect strDate is being altered elsewhere.

Try setting StrDate to the relevant textbox value before the calls to InputBoxDD.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thanks Erel and Kickaha. This is how I finally solved it: I had to create a new string strDatepr where I store the original value stored in the textbox. Then, after performing InputBoxDD function, and if I decide to cancel the date, I make the textbox value revert back to strDatepr. That way, the text box date value remains unchanged. I was hoping by simply canceling, I did not have to add any more code and the date reverts back on its own.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Maybe you already tried these coding styles, but I was just tempted to reply :)

B4X:
Dim strDate as string
dim ViewStartD, ViewEndD   as edittext

Sub InputBoxDD(Prompt As String, Title As String) As Int
    Dim Dd As DateDialog
    Dim ret As Int
    Dd.Year = DateTime.GetYear(DateTime.now)     
    Dd.Month = DateTime.GetMonth(DateTime.now)         
    Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)     
    ret = Dd.Show(Prompt, Title, "Ok", "Cancel", "", Null)
    strDate= DateTime.Date(Dd.DateTicks)
    Return ret
End Sub

Sub ViewStartD_Click
      If InputBoxDD("Accept or change START Date","DATE SELECTION SCREEN") <> DialogResponse.Cancel then
            ViewStartD.text=strDate
        end if
End Sub
Sub ViewEndD_Click
      If InputBoxDD("Accept or change END Date","DATE SELECTION SCREEN") <> DialogResponse.Cancel then
             ViewEndD.text=strDate
       end if
      
End Sub


B4X:
dim ViewStartD, ViewEndD   as edittext

Sub InputBoxDD(Prompt As String, Title As String, OrigDate as String) As String  
    Dim Dd As DateDialog
    Dim strDate as String
    Dim ret As Int
    Dd.Year = DateTime.GetYear(DateTime.now)     
    Dd.Month = DateTime.GetMonth(DateTime.now)         
    Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)     
    ret = Dd.Show(Prompt, Title, "Ok", "Cancel", "", Null)
    strDate= DateTime.Date(Dd.DateTicks)
    If ret=DialogResponse.Cancel Then
            strDate= OrigDate
   End If
   Return strDate
End Sub

Sub ViewStartD_Click
        ViewStartD.text=InputBoxDD("Accept or change START Date","DATE SELECTION SCREEN",ViewStartD.text)
End Sub
Sub ViewEndD_Click
        ViewEndD.text=InputBoxDD("Accept or change END Date","DATE SELECTION SCREEN",ViewEndD.text)
End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@TDS: Thank you for your generosity with your time. I tested both of your options and they work flawlessly. Although all options are equivalent, I use a method very similar to your second option. Your first option is actually cleaner than mine.
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
:sign0085::sign0085::sign0085::sign0085::sign0085:

Whenever i use the code Dim Dd As DateDialog

i get an error as shown below

Compiling code. Error
Error parsing program.
Error description: Unknown type: datedialog
Are you missing a library reference?
Occurred on line: 51
Dim Dd As DateDialog

what should i do
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As the error message says, you are missing a library.
In this case the Dialogs libray.
If you haven't downloaded it you must download it here, unzip the file and then copy the two files *.jar and *.xml to your additional library folder.

Best regards.
 
Upvote 0
Top