Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 14, 2018 11:43 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Thu Dec 04, 2008 3:59 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You must use recSet.Edit before you make your changes to the recordset.
// Load the Edit Field values into the Record Set vars to load into the DB.
recSet.Edit
recSet.Field("billingRate").StringValue = Trim(txtBillingRate.Text)
...


Also, your comment on the line
' Test to make sure I am connected to the database.
If dBse.Connect = True Then

is incorrect. You are not testing to see if you're connected. You are actually connecting. You don't have a connection until this point. Perhaps you really should make one connection to the db and hold onto it in a global variable. That way, you're not connecting and closing the database all the time.

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Fri Dec 05, 2008 12:36 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
Next Question... How to I clear out old data in a listbox so I can load new data? I have a listbox set up that when I select a meter it will populate with that meter's use history. This is so I can select errant readings and perform calculations. The problem is I noticed that when I select a meter, it works great, but when I select a new meter the previous meters history is still in the list box as well as the new meters history.

I have tried the following without any luck.
// Clear the edit fields.
txtRecId.Text = ""
// Assign cleared edit field values to list box
lstBxMeterHistory.Cells(lstBxMeterHistory.LastIndex,0) = Trim (txtRecId.Text)


Other method I tried was

lstBxMeterHistory.Cells(lstBxMeterHistory.LastIndex,0) = ""


Neither worked. Thanks again! I am getting faster at coding and better at solving problems! Next on the plate is to go out to a directory on another PC and pull a text file in and perform calculations on the data then insert it into the database. But that is for next week I think and I will fiddle with it using the book. It seems to be pretty detailed on what I need to do for the next phase.

Thanks again!


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Fri Dec 05, 2008 12:41 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
The online Language Reference is your friend. Help -> Language Reference (or press F1). Type in "Listbox" into the Location field (it will autocomplete to help you out). In the Methods section you will find
lstBxMeterHistory.DeleteAllRows

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Fri Feb 20, 2009 12:08 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
Back again! Trying to subtract one date from another. The deal is I have a start date and and end date. From there I get use days. What I am going for and have pretty much figured and working... except the subtracting of the start date from the end date, is to get the 3 highest use per day then test to see if a reading exceeds that value.

Here is the Crystal Report Code
--------------------------------- High Error Check -----------------------
if
NthLargest (3,{@UsePerDay},{Actnums.ID_CODE})<
.75*NthLargest (2,{@UsePerDay},{Actnums.ID_CODE})
then
NthLargest (3,{@UsePerDay},{Actnums.ID_CODE})
else
NthLargest (2,{@UsePerDay},{Actnums.ID_CODE})

---------------------------------- Low Error Check -----------------------
if NthSmallest (2,{@UsePerDay},{Actnums.ID_CODE})=0 then
if
NthSmallest (4,{@UsePerDay},{Actnums.ID_CODE})<
1.25*NthSmallest (3,{@UsePerDay},{Actnums.ID_CODE})
then
NthSmallest (4,{@UsePerDay},{Actnums.ID_CODE})
else
NthSmallest (3,{@UsePerDay},{Actnums.ID_CODE})
else
if
NthSmallest (3,{@UsePerDay},{Actnums.ID_CODE})<
1.25*NthSmallest (2,{@UsePerDay},{Actnums.ID_CODE})
then
NthSmallest (3,{@UsePerDay},{Actnums.ID_CODE})
else
NthSmallest (2,{@UsePerDay},{Actnums.ID_CODE})


Now I have this all figured out but I am getting killed on the days calculation that I need.

Here is how I am trying to calculate number of days.
intNumDays = dtEndDate.LongDate - dtStartDate.LongDate


But the error is telling me I have used an operator that is not compatible with the data types specified. And if I try to change type then I get 0's

intNumDays = CDbl(dtEndDate.LongDate) - CDbl(dtStartDate.LongDate)


Not sure how to do this...


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Fri Feb 20, 2009 12:48 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
LongDate is a string, so you can't do math on it. Use TotalSeconds and adjust the result to get days.

intNumDays = Floor( (dtEndDate.TotalSeconds - dtStartDate.TotalSeconds) / (24*60*60) )

(That's 24 hours * 60 minutes * 60 seconds)

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Fri Feb 20, 2009 12:59 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
Thanks Tim, I wasn't even in the ball park on that one!


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Sun Mar 01, 2009 5:17 pm 
Offline

Joined: Fri Sep 14, 2007 5:00 pm
Posts: 408
Okay, actually I fixed one issue but still can't figure out how to do what I want to do.

So I am refining my application now that I have most of it working pretty well. The area I am working on now is date formatting. I use a specific format that isn't readily available so I create it myself using the Edit Field format. So I have a field that has a format set to "##->?<??-####" and that works great. It constrains the input to 12-Dec-2008. That's great, but I have to wait until the user is done entering data to test it. I am trying to figure out how to test the user input and allow it as they go.

I have it sort of partially working, but have finally run into a road block.

txtDateInstalled.KeyDown

Dim SS, SL As Integer
Dim stHold As String

' Use this to constrain the text entered
Select Case Mid(Me.Text, 4, 1)

Case Else

Select Case Key
Case Chr(8) //Backspace
Case Chr(28) //Left
Case Chr(29) //Right
Case Chr(127) //Delete
' Upper Case
Case Chr(65) // A
Case Chr(68) // D
Case Chr(70) // F
Case Chr(74) // J
Case Chr(77) // M
Case Chr(78) // N
Case Chr(79) // O
Case Chr(83) // S

' Lower Case
Case Chr(97) // a
Case Chr(98) // b
Case Chr(99) // c
Case Chr(101) // e
Case Chr(103) // g
Case Chr(108) // l
Case Chr(110) // n
Case Chr(111) // o
Case Chr(112) // p
Case Chr(114) // r
Case Chr(116) // t
Case Chr(117) // u
Case Chr(118) // v
Case Chr(121) // y

' Numbers
Case Chr(48) // 0
Case Chr(49) // 1
Case Chr(50) // 2
Case Chr(51) // 3
Case Chr(52) // 4
Case Chr(53) // 5
Case Chr(54) // 6
Case Chr(55) // 7
Case Chr(56) // 8
Case Chr(57) // 9

Else
Beep
Return True
End Select

End Select


txtDateInstalled.Text Change
If Me.Text = "" Then
Me.BackColor = &c07EAF0 ' Sets Backcolor to Cyan Blue
Me.Bold = True
Me.SelLength = 0 ' Set the cursor at the beginning of the field
Else
Me.BackColor = &cF7FF00 ' Sets Backcolor to Yellow
Me.Bold = True
Me.SelLength = 0 ' Set the cursor at the beginning of the field
End If

Select Case Mid(Me.Text, 4, 1)
Case "J"

Case "F"
Me.Text = Left(Me.Text, 4) + "eb"
Me.SelLength = 8
Case "M"
Case "A"
Case "S"
Case "O"
Case "N"
Case "D"
Case Else

End Select


It's not quite working as I had hoped. once I update the field the SelLength function won't work and I can move on to enter the year to complete the date. Essentially I am trying to set this field so that I can control as the user types what month is entered.

So if they type F then the next available letter is only e then the next after that is b. Same with J, with J they would have either a or u then based on which one they selected they would have either l or n and so forth, then they can enter the 4 digit year.

Right now they can enter any text they want in the field (that is where the format allows text the field format is set to "##->?<??-####" and I have a test built to catch it AFTER the user has completed entering the field. I want to not even have to catch it, but set the field so that as the user types they are constrained to only valid possible combinations. Microsoft Access does this automatically in it's field formatting so that as you type you can only enter valid months and it does it while you are typing which is what I am trying to figure out.


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Sun Mar 01, 2009 7:22 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
You're fighting against the editfield and its formatting. If you're going to do this level of validation, you should do the whole thing yourself in KeyDown. Make an EditField subclass that is a date entry field and implement your own validation in the KeyDown event.

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatting Date in Edit Field
PostPosted: Mon Dec 27, 2010 3:45 pm 
Offline

Joined: Wed Jul 15, 2009 2:27 pm
Posts: 3
npalardy wrote:
##/##/#### will only allow a date like 12/31/2008 and will not accept 1/12/2008

It seems that what you really need / want is one that has several masks like

#/#/####
#/##/####
##/#/####
##/##/####

and it can validate against any of them

Correct ?


I found this thread via Google while searching for "realbasic date field", and what you suggest above is exactly what I'm looking for. I want a TextField to accept dates with four digits for years and one or two digits for the month and day. I ended up using #9/#9/####, which seems to work. Just placing that solution here in case someone else is looking for it.

Thanks,
Chuck


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group