I want to lock the date for the promotion based from start and end date.
the list item in listbox is based from today’s date. If the date start is match then promotion start and stop when the end date is over.
this code seem to works, but not covering all. still has some items are passed.
dim dd as new date
if ListPromo.cell(gg,8)>=str(dd.SQLDate) or ListPromo.cell(gg,7)>=str(dd.SQLDate) then 'cell 8 = end date cell 7=start date
Select case ggg
case "D1"
Listbox1.cell(o,4)=format(a,"###,##0")
case "D2"
Listbox1.cell(o,4)=format(b,"###,##0")
case "D3"
Listbox1.cell(o,4)=format(c,"###,##0")
case "D4"
Listbox1.cell(o,4)=format(d,"###,##0")
End Select
Your are using an older version of Xojo with API1, so Listbox.Cell() returns Text. What you are doing in your code is comparing a text with a string. This can’t work as expected.
A better approach may be working with dates, in detail with totalseconds.
dim dd as New Date
dim dStart as New Date
dim dEnd as New Date
dStart.SQLDate = ListPromo.cell(gg,7) // content of cell 7 must be a date in SQL-Format
dEnd.SQLDate = ListPromo.cell(gg,8) // content of cell 8 must be a date in SQL-Format
if dd.Totalseconds >= dStart.Totalseconds And dd.TotalSeconds <= dEnd.TotalSeconds then
Hi, Thanks for the help, but still not covering. My Goals is like this pict,
Promo A,B,C are active, because the end date still going till 2023-05-10
and Promo D is not active, because promo just started by tomorrow (2023-05-04) based from todays’date.
Everything you need to get your desired result is mentioned in my post. You only have to adopt it to your way of putting data into the listbox. The calculation has to be done for every row…
It would be helpful if you show your code, how you fill the listbox…
This is the code in the button (converted TextField1.Text to date just to use date and not the TextField contents):
Dim dd As New date
dd.SQLDate = TextField1.Text
For i As Integer = 0 To 3
If Listbox1.Cell(i, 2) <=dd.SQLDate And dd.SQLDate <= Listbox1.Cell(i, 3) Then
Listbox1.Cell(i, 4) = "Active"
Else
Listbox1.Cell(i, 4) = "Not Active"
End If
Next
Used Xojo 2018r3
I guess your problem is not with the If statement. Can you create a sample project and illustrate the wanted result? someone can review your code that way.
Note: I changed the If order because that way is more clear for me to:
Date Start <= Date to check <= Date End
This is the code in the button (converted TextField1.Text to date just to use date and not the TextField contents):
I am forgot to check the datatype, yes it was text, changing the datatype into date solved the problem.
I am using Sqlite data browser for linux and there is no Date Datatypeoption. So I edited the database on windows and work.