Source language: Translate to:

Updating Decimal fields In data base

Questions about our Advanced Database plug-in

Moderator: Neosoft Support

Updating Decimal fields In data base

Postby Daved » Wed Dec 04, 2013 9:07 am

I somehow seem to not get all the numeric formats correct, when updating a decimal field in the database from a Neobook variable.
What format should I use in access?
How should the variable be defined?
Access DB
DefineVar "[acres]" "Decimal" "2" "Global" ""
Math "[number_of_trees] / [treesperacre]" "2" "[Acres]"
dbpAddRecord "treecount" "planting_record"
SetVar "[treecount.planting_record.tree_acres]" "[Acres]"

All though acres has a value the record reports 0.

Thanks in advance
Dave
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm

Re: Updating Decimal fields In data base

Postby Gaev » Wed Dec 04, 2013 9:28 am

Dave:

1) You don't need to DefineVar if you are using the Math command to truncate results to 2 decimal places.

2) What Database are you using ? ... Access, MySQL etc. ?

3) Post the command you used to define the field tree_acres.

All though acres has a value the record reports 0.
How are you determining this ? ... did you do a save of the newly added record ? ... if/when you do a SetVar of other fields in the same record, do they get updated ?

Try this code to get a better picture ...
Code: Select all
Math "[number_of_trees] / [treesperacre]" "2" "[Acres]"
AlertBox "Acres" "[Acres]"
dbpAddRecord "treecount" "planting_record"
SetVar "[treecount.planting_record.tree_acres]" "[Acres]"
AlertBox "Before SaveEdits" "[treecount.planting_record.tree_acres]"
dbpSaveEdits "treecount" "planting_record"
AlertBox "After SaveEdits" "[treecount.planting_record.tree_acres]"
... and post results here.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Updating Decimal fields In data base

Postby Daved » Wed Dec 04, 2013 10:08 am

Everything is correct all the way through the process. However Access seemed to ignore decimals and would not save the value in variable [acres] to the db field.
I also tried adding a decimal value directly in the access entry mode. The field would revert to an integer.
I now changed the db field to a string value and the update worked.
Is this normal behavior?
Will math calculations in NeoBook still perform normally on string fields?

Thanks
Dave
Daved
 
Posts: 19
Joined: Mon Nov 11, 2013 3:37 pm

Re: Updating Decimal fields In data base

Postby Gaev » Wed Dec 04, 2013 11:22 am

Dave:

Everything is correct all the way through the process. However Access seemed to ignore decimals and would not save the value in variable [acres] to the db field.
I also tried adding a decimal value directly in the access entry mode. The field would revert to an integer.

What was the tree_acres field defined as ? ... Integer or Floating ? ... looks like you might have defined it as an Integer.

I modified one of the demo Apps I had developed for my client ... to include a floating field (called Amount) ... and this code works as expected ...
Code: Select all
If "[PatientsStatus]" "=" "Closed"
    AlertBox "Error" "Table Patients is not open"
Else
    ... any records in Table ?
    If "[Learn.Patients.$RecCount]" ">" "0"
        ... add empty record
        dbpAddRecord "Learn" "Patients"
    EndIf
    ...populate fields
    SetVar "[Learn.Patients.FirstName]" "Bill"
    SetVar "[Learn.Patients.LastName]" "Clinton"
    SetVar "[Learn.Patients.StartYear]" "1993"
    SetVar "[Learn.Patients.EndYear]" "2000"
    SetVar "[Learn.Patients.DateStarted]" "04/09/1992 11:53:45"

    SetVar "[Price]" "34.57"
    SetVar "[Discount]" "0.90"
    Math "[Price]*[Discount]" "2" "[Amount]"
    SetVar "[Learn.Patients.Amount]" "[Amount]"

    dbpSaveEdits "Learn" "Patients"
EndIf

I had no problem saving the value ... how is your code different ?

I now changed the db field to a string value and the update worked.
Is this normal behavior?
Will math calculations in NeoBook still perform normally on string fields?

1) No it is not normal behaviour.

2) The Math command is flexible ... as long as the variable contains a valid number, it will do the Math.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to NeoBookDBPro

Who is online

Users browsing this forum: No registered users and 2 guests