Text Field Insanity!

I have two text fields, they are identical in set up and formatting. One holds a cash gross value the other the total daily gross value. They get the exact same inputs and yet the text field that holds the daily gross value will NOT display any digits on the right of the decimal.

Example:
I calculate a gross value of 12.45 then put that value in both text fields, the cash text field will display correctly the daily gross will only display 12.00. BUT it gets better, when I go to another calculation THAT will update the gross field correctly. I am pulling my hair out trying to figure this out!

To explain, I have a Window set up with multiple fields. The user enters an integer value (count of money ex: the user counts 10 $1.00 bills they enter 10 in the $1.00 bill field and so forth.) when the user presses the TAB, ENTER or RETURN key a method is called that will calculate total values then assign the results into the appropriate fields for display.

When it comes to calculating the change when I step through the code in debug mode it’s working as designed and one of the two Text Fields is updating correctly while the other is not. But when I move to entering credit card and checks the field that doesn’t update with the cash entries works fine. It’s making me crazy trying to find where the issue is


You’ve restarted the computer? Xojo is prone to bouts of insanity, especially when it has been running for a long time. Whenever I get something weird like that I restart and the issue is usually gone.

3 Likes

It must be your code, especially if you have separate calculation routines .
Can you post the code here?

If you create a method that takes two parameters and updates the text boxes, then pass your output values into that, you can be sure that the code is always the same.

2 Likes

Do you have by any chance a mask set on the textfield that isn’t working?

Could be one has ###.## and the other ###.00

2 Likes

Linux OS
 only time I reboot is for a kernel update that requires it. Otherwise I have a memory routine that flushes cache and recycles memory regularly.

// Variable declarations...
Var A As Integer // This holds the count...
Var B As Currency // Holds the cash total for additional calculation...
Var C As Currency // The Total for a given entry...
Var D As Currency // Hold the  last value...
Var E As Currency // Hold the value of the opening till amount...
Var F As Currency // Test value...
Var curConvert As Currency // Convert the text field value to currency value for calculations...
Var strJulien As String = modSysFunc.mthJulianCalc // Get the Julien date....
Var recSet As RecordSet = modSel.mthSelTill( strJulien, "" ) // IdxField( 25 ).DoubleValue

// Function(s)...
E = recSet. IdxField( 25 ).DoubleValue // Opening till amount
txtOpenTotal.Value = E.ToText // Display the opening till amount for validation...

// Start with ones...
If( btnAddUpd.Caption = "Open Till" ) Then
  frmTillCnts.mthCalculateOpenTill
  Exit
Else
  curConvert = txtOnes.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtOnes.Value.ToInteger
B = 1.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  // Next with Fives...
  curConvert = txtFives.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtFives.Value.ToInteger
B = 5.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  // Next with Tens...
  curConvert = txtTens.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtTens.Value.ToInteger
B = 10.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  // Next with Twenties...
  curConvert = txtTwenties.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtTwenties.Value.ToInteger
B = 20.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  // Next with Fifties...
  curConvert = txtFiftys.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtFiftys.Value.ToInteger
B = 50.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  // Next with Hundreds...
  curConvert = txtHundreds.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtHundreds.Value.ToInteger
B = 100.00
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =  txtCashGross.Value
  End If
  
  //*****************************************************
  ' Change calculations...
  //*****************************************************
  // Next with Quarters...
  curConvert = txtQuarters.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtQuarters.Value.ToInteger
B = 0.25
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value =C.ToText
  End If
  
  // Next with Dimes...
  curConvert = txtDimes.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtDimes.Value.ToInteger
B = 0.10
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value = C.ToText
  End If
  
  // Next with Nickles...
  curConvert = txtNickles.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtNickles.Value.ToInteger
B = 0.05
C = A * B + D
D = C

txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtTotal.Value = txtCash.Value
txtDailyGross.Value = C.ToText
  End If
  
  // Next with Pennies...
  curConvert = txtPennies.Value.ToDouble
  If( curConvert >= 1 ) Then
A = txtPennies.Value.ToInteger
B = 0.01
C = A * B + D
txtTotal.Value = C.ToText
txtCash.Value = C.ToText
C = C - E
D = C

txtCashGross.Value = C.ToText
txtDailyGross.Value = C.ToText

  End If
  
  // Credit Card list box...
  For i As Integer = 0 To lstBoxCreditPurch.LastRowIndex
B = lstBoxCreditPurch.CellValueAt(lstBoxCreditPurch.SelectedRowIndex, 1 ).ToDouble
C = B + D
D = C

txtTotal.Value = txtCash.Value
txtDailyGross.Value = C.ToText
  Next

Nope, all fields that are updated by code have no mask settings but do have a format setting of:

-00,.00

Not at my computer but try

A = txtQuarters.Value.ToInteger
B = 0.25
C = A * B
C = C + D

and follow along in the debugger to see the value of C

It would help if we know WHICH textfield is the problematic one.

My immediate reaction is
.ToInteger
Somewhere you may be losing the decimals.

C = A * B
could easily be returning an integer to C

If you really want to test the TEXT Fields, just insert this code at the end:

C = 12.34
txtTotal.Value = C.ToText
txtCash.Value = C.ToText
txtCashGross.Value = C.ToText
txtDailyGross.Value = C.ToText

What do the text boxes show?

Let’s assume for this example C = 10.23

txtCashGross.Value = C.ToText <-- Will display 10.23
txtDailyGross.Value = C.ToText <-- Will display 10.00

Both text boxes are set up identical and as you can see there is no change to C that would justify the dropping of the right of decimal digits.

I have even tried this set up:

txtCashGross.Value = C.ToText
txtDailyGross.Value = txtCashGross.Value

So for shiggles I deleted the txtDailyGross field and copied a working text field then named is txtDailyGross and
 the problem still exists?!

Try deleting txtDailyGros, duplicating the working txtCashGross, and renaming the copy to txtDailyGros

1 Like

In that case try the Val function instead of .value.toInteger

1 Like

What did

A = txtQuarters.Value.ToInteger
B = 0.25
C = A * B
C = C + D

show?

And search the project for txtDailyGros - maybe there is code somewhere that rounds or floors it that you have forgotten about 


Such as in the change event.

I am stumped, I just finished a line by line review and cannot find anything anywhere that would account for this. I even deleted the field and created a new one from scratch


So the properties of these fields, as seen in the Inspector, are identical?

Your code follows a rigid structure like this for everything:

// Next with Nickles...
curConvert = txtNickles.Value.ToDouble
If( curConvert >= 1 ) Then
  A = txtNickles.Value.ToInteger
  B = 0.05
  C = A * B + D
  D = C
  
  txtCash.Value = C.ToText
  txtCashGross.Value = C.ToText
  txtTotal.Value = txtCash.Value
  txtDailyGross.Value = C.ToText
End If

except pennies where it becomes

// Next with Pennies...
curConvert = txtPennies.Value.ToDouble
If( curConvert >= 1 ) Then
  A = txtPennies.Value.ToInteger
  B = 0.01
  C = A * B + D
  txtTotal.Value = C.ToText
  txtCash.Value = C.ToText
  C = C - E
  D = C
  
  txtCashGross.Value = C.ToText
  txtDailyGross.Value = C.ToText
  
End If

I leave it to you to decide if this is correct (it just seems weird to me).

Pennies are the end of all cash calculations so I close out that section there with a couple changes. From there it moves to credit cards then checks then petty cash deductions.

What is strange is the credit card code and check code and petty cash code all will display the correct values. It’s only in the cash section that I am having this discrepancy.

I think I am going to revise the code completely and use a different approach. See if that corrects the issue. I am already working on the pseudocode for the new method.