Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

leading blank spaces in text fields 1

Status
Not open for further replies.

cobweb

IS-IT--Management
May 5, 2002
95
GB
Hi there:
In Paradox 9 I need to set a default in a text field to ' 1' (ie space-space-space-1).
But each time I save the table the default resets to '1'; ie the leading blanks are removed.
Does anybody know how to set a default where there are spaces before the characters I want?

Thanks in anticipation


 
cobweb,

Unfortunately, you're running into a small conflict between two of the "sub-modules" of Paradox. While you've designed a legitimate and valid default value, the routine that processes the keyboard and submits those characters to the underlying field automatically assumes that the leading whitespace is accidentally and "helpfully" removes it.

Paradox handles default values by "submitting" them as if they'd been typed from the keyboard, triggering the helpful routine mentioned above. Most of the time, this is actually very handy.

You can, however, work around this by adding a bit of ObjectPAL code to the action() event of the field object bound to your field. In this case, something like this should help:

Code:
   if eventInfo.id() = dataInsertAction then
      doDefault 
      self.Value = "  1"
      self.touched := FALSE
   endIf

(Apparently, code submitted by ObjectPAL does not trigger the helpful routine, at least not in Paradox 9. I'd have to test this under different versions.)

This waits for any action that inserts a record from the form itself, lets the background work of that action take place, sets the default value, and then clears the flag that says, "Yup, the user actually changed the record."

That last bit was added to help prevent accidental inserts from leaving otherwise blank records in the table.

Hope this helps...

-- Lance
 
A big thanks to Footpad for pointing me in the right direction.
I did not want to have the fields on a form but the following loop script did the trick:

var
tc TCursor
endVar
tc.open("Table.db")
tc.edit()
scan tc:
tc."Field1" = " 1"
tc."Field2" = " 1"
endscan
tc.endedit()
tc.close()

I attached that to a button and now works fine.
Thanks again to footpad - and Tek-Tips forum!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top