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!

Saving both numeric and character data type format

Status
Not open for further replies.

jhed

Programmer
Apr 21, 2014
33
PH
here is what i want to save in my table '00-00-00' where the zeroes starting from the right are increments whenever the user saves the data. so when there's a lot of data later on, the format of my number should be '01-99-99'.

so far i tried this setup but i cannot save the '-' sign only the numbers..
*field type = numeric
*in the builder of my textbox, i placed an input mask as '##-##-##' and remains the numeric as data type
*the syntax that i used was 'thisform.NameofTextbox.value = thisform.NameofTextbox.value + 1'

 
What's the value of storing the dashes in this field, they are always at positions 3 and 6.

You want an incrementing field, then use int autoinc. This will be a readonly field. If you APPEND BLANK or INSERT INTO yourtable (field2, field3) VALUES ( field2value, field3value) you skip the autoinc integer field, as it's populated with the next value automatic.

You don't put database counters into a form, you have it in the database. There is nothing easier to get an incrementing value than autoinc, you don't have to maintain your own counter and it's reliable. Use it.

Now to show the number with dashes in text boxes you simply use that input mask and that's it.

In a report control you can also use the expression Transform(autoincfieldname,"@RL ##-##-##"), eg try out ? Transform(12345,"@RL ##-##-##") in the command window. Also refer to the help topic on TRANSFORM. @ says the following characters are Formats, R means a mask is following (after the next space) and L says to add leading zeros, ##-##-## is the mask you already know. More formats are explained in the help topic on TRANSFORM, which overall is the only converion function you need in VFP to convert from any data type to strings.

Bye, Olaf.
 
here is what i want to save in my table '00-00-00'

Can't do it. Not in a numeric field. The - is not a number.

As Olaf says, this sort of thing shouldn't be stored anyway. Store the number only.
 
There are a couple of problems with what you are asking to do.

increments whenever the user saves the data.
'thisform.NameofTextbox.value = thisform.NameofTextbox.value + 1'

Depending on where you executed this code, this could increment the numeric value whenever the textbox was Entered, and not be limited to when the value is Saved.

And, like has already been said above, you do not want the number itself stored as a Character and include the dashes ("-").
Instead you need to store the number as an Integer which you can increment on a Save of the New Form values.

Remember to check to see if one or more of the Form values have been changed upon Exiting the Form.
Sometimes a Form is used to merely View the data and Not Change it.
If the data was Not changed, then you need to Not increment this value.

Good Luck,
JRB-Bldr


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top