Hello Louis,
1. You will need to re-write the FormatMoney() function in your Global Code section to insert the commas. Below is a Function that should do just that. Now it may have some problems in it, if it does just let me know
Function FormatMoney(Val as Double) as String
Var vBack as String
Var vWhole as String
Var vFrac as String
Var vDub as Double
vWhole = @Str(@Int(Val))
vFrac = @Str(@Frac(Val)) + "00"
While @Len(vWhole) > 3
{
vBack = "," + @Right(vWhole, 3) + vBack
vWhole = @Left(vWhole, @Len(vWhole) - 3)
}
vBack = vWhole + vBack
If @Instr(vFrac, ".") > 0 Then
{
vDub = @ToNumber(vFrac)
vFrac = @Str(@Decimals(@Round(vDub, 2), 2))
vFrac = @Right(vFrac, 2)
}
vBack = "$" + vBack + "." + @Left(vFrac, 2)
Return vBack
End Function
2. To Right Justify the values using Printstring you need to measure how long something is going to be when printed and then subtract that from where you want the right side of the money amounts to line up. Below is an excert from a larger routine that does just that.
//RIGHT ALIGNING THE DOLLAR FIGURE
vMoney = FormatMoney(Dollars)
//Measure how long the string will be when printed
PrintString(vMoney, 0, 0, 0, "Arial", 16, 1)
vSize = @PageExtentX()
//400 is the coordinate for the right edges to line up against
vSize = 400 - vSize
//Print the actual value to the page
PrintString(vMoney, vSize, vY, 0, "Arial", 16, 0)
3. @Newline() does not take arguements so @Newline("And") is not going to work. If you want to truncate at a certain number of characters you can use @Left(). So
@Left(vAmountText, 150)
will return the first 150 characters and you can print that out. To break on the word "And" you would need to use @InStr() to find the position of "And" and then use @Left() and @Right() along with @Newline() to create a two line amount
4. The programming can only deal with the values that you pass it. If you pass it no values then it will try to deal with no values. In the example code in the SBasicCodeLibrary if you pass in a blank date you will get "January 0, 0", the formatted value of 0000/00/00 which is a blank date variable. If you pass in a blank amount you will get "$0.00" which is the formatted value of 0 which is a blank double variable.
Also the FormatDate() function that is in that example does not use @Left() it uses @Month$(), @DOM() and @Year() to format the date value.
5. To loop through your records use @ResultSetTotal() and @ResultSetCurrentPosition(). If you have a subform you will want to use @FormResultSetTotal() and @ResultSetCurrentPosition() to avoid any confusion as to which form you wish to operate on. The code below will loop through every record in the current result set.
Var vLoop as Int
Var vCnt as Int
VLoop = 1
vCnt = @ResultSetTotal()
While vLoop <= vCnt
{
ResultSetCurrentPosition(vLoop)
//Your code goes here and it will run on every record
vLoop = vLoop + 1
}
ResultSetCurrentPosition(1)
-Ray