On another forum I found this formula and it seems to work except that I keep getting 2 different errors
First Error
I get "A string is required here" error. I'm getting the error on line 8 (counting blank lines) of the code where it says
replace({ACCOUNT_CARD_DATA.CARD_NUMBER}," ","")
Second Error
If I add totext and make it say
replace(totext({ACCOUNT_CARD_DATA.CARD_NUMBER})," ","")
it will save with no errors but when I try to put it in the report it gives me a "The string is non-numeric" error. When I click ok it shows me the error in the code is on line 18 (counting blank lines) where it says
v_calc := tonumber(v_temp) * 2
I feel like I'm in a loop that can't be resolved...what am I doing wrong?
Thank you!
Entire Code
whileprintingrecords;
stringvar v_cc := "";
stringvar v_temp := "";
numbervar v_calc := 0;
numbervar v_result := 0;
numbervar v_counter := 0;
v_cc := replace({ACCOUNT_CARD_DATA.CARD_NUMBER}," ",""); //THIS IS THE 1ST PLACE I'M GETTING THE ERROR
// Double every other digit starting with the last digit.
numbervar v_counter := len(v_cc);
while v_counter > 0
do
(v_temp := mid(v_cc,v_counter,1);
v_calc := tonumber(v_temp) * 2; //THIS IS THE 2ND PLACE I'M GETTING THE ERROR
if v_calc >= 10 then v_calc := tonumber(left(totext(v_calc,"#",0),1))+ tonumber(right(totext(v_calc,"#",0),1))
else
v_calc;
v_result := v_result + v_calc;
v_counter := v_counter - 2);
// Add in the non-doubled digits
v_counter := len(v_cc) - 1;
while v_counter > 0
do
(v_temp := mid(v_cc,v_counter,1);
v_calc := tonumber(v_temp);
if v_calc >= 10 then v_calc := tonumber(left(totext(v_calc,"#",0),1)) + tonumber(right(totext(v_calc,"#",0),1))
else
v_calc;
v_result := v_result + v_calc;
v_counter := v_counter - 2);
// Calculate check digit
v_cc + right(totext(v_result * 9,"#",0),1)
Related
I have this formula field:
global numbervar TotDiff;
WhilePrintingRecords;
if {#QuantExceding} <> 0 then
TotDiff := TotDiff + ABS({#QuantExceding})
else
TotDiff := TotDiff
Initially, the if clause was not there, so I thought it was ABS erroring out when passed 0. Then I see that whatever I do with QuantExceding, when it equals 0, the reports errors out and highlights the first line of the if or whatever the line that invokes QuantExceding
Any ideas ?
change formula like this and make sure the {#QuantExceding} is evaluating first:
WhilePrintingRecords;
EvaluateAfter({#QuantExceding});
global numbervar TotDiff;
if {#QuantExceding} <> 0 then
TotDiff := TotDiff + ABS({#QuantExceding})
else
TotDiff := TotDiff
Having an issue when attempting to run a Mod formula against a field. I keep receiving the error "String is Not Numeric" and so far I have not been able to get ToNumber to correctly format the field. The field is being generated by adding a static value and three fields that have been padded. Any help would be appreciated.
Combines fields and pads
StringVar strMICR;
StringVar strMICRLINE;
strMICRLINE := Chr(13) & "0603250694";
strMICRLINE := strMICRLINE & Right("000000" & Trim(Split({CUST.C_ID_ALPHA},"-")[1]),6);
strMICRLINE := strMICRLINE & Right("00000000" & ToText({STMT.STMT_NUMBER},0,""),8);
strMICRLINE := strMICRLINE & Right("0000000000" & Replace(ToText({#Total},2,""),".",""),10);
//Uncomment below to test Mod10 Check-digit
//strMICR := mod10("0603250694084469108961440000127874");
//IF NumericText (strMICRLINE)
//THEN ToNumber (strMICRLINE);
Mod10 (strMICRLINE);
MOD10 Function
Function (StringVar input_number)
input_number := replace(input_number, " ", "");
numbervar i := length(input_number);
numbervar sum_val := 0;
stringvar position := "odd";
do (
if position = "odd" then (
sum_val := sum_val + 3*tonumber(input_number[i]);
position := "even" )
else (
sum_val := sum_val + tonumber(input_number[i]);
position := "odd" )
;
i := i-1
) while i > 0;
numbervar remainder_val := Remainder(sum_val, 10);
numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;
input_number + ToText(check_digit, 0)
You're attempting to call toNumber() on a string that is not numeric and therefore can't be converted. You need to strip all non-numeric characters out of your string first.
//Formula sample to strip non-numeric characters
local stringvar input := "78906-adf0asdf-234";
local stringvar output;
local numbervar i;
for i:=1 to length(input) do
if numerictext(input[i]) then output:=output&input[i];
output
Then I would highly suggest you use the built in mod function instead of rolling your own.
toNumber({#NumericTextOnly}) mod 10
i want to print missing records in crystal report .
i am using below formula in the report and i have placed this formula in details b section.
details a has normal report fields.
formula:
local numbervar firstemp; // first Emp#
local numbervar nextemp; // next Emp#
local numbervar diff; // difference between firstemp and nextemp
local numbervar increase; // increment for missing Emp#'s
local numbervar result;
increase := 0;
firstemp := tonumber({getRptSalesSummery;1.Bill_Id});
nextemp := tonumber(next({getRptSalesSummery;1.Bill_Id}));
nextemp := nextemp -1;
diff := nextemp - firstemp;
if nextemp = firstemp
then ""
else (
while diff >= 1
do (
diff := diff - 1;
increase := increase + 1;
result := firstemp + increase;
exit while;
);
totext (result,"0000") & chr(13);
)
this formula is not giving me range.
for example if in report there is range of 1 to 10 and 6,7,8,9 is missing records, then if i check in the report its printing 1 to 5 and 6 as missing then directly 10, but its not giving me 7,8,9.
basically i required range of missing records
Okay, I am working in a project that was originally done in D7. And I am doing double duty here as I am working on fixing bugs in the original code and attempting to port it over to XE3/4. Kinda hard when the original author used some none-open source kits for the project.
But anyways, the app is a scripting/macroing program. As part of the custome scripting/macroing language. There is a ability to create very simple basic forms for user input. The forms are created dynamically at runtime based on the script/macro the script/macro author has created. I have already fixed some bugs in the code for the creation of the forms. But, there is one that I just can not figure out.
When creating a TComboBox for the parent form and setting the Text property AT component creation. The text in the Text property is not displayed.
Here is the code to create the form:
procedure CreateForm(var wFrm: TForm; sName: String);
var
iLoop, iPos, iLen: Integer;
iFormHeight, iFormWidth: Integer;
lh, hresult1, hresult2: Integer;
sWork, sWork2, sLine, CmdName: String;
lstForm, lst: TStringList;
pnl: TPanel;
begin
iFormHeight := 80;
iFormWidth := 400;
hresult1 := 0;
lst := TStringList.Create;
iLoop := lstForms.IndexOf(Trim(UpperCase(sName)));
if iLoop < 0 then
begin
AbortError('Form "' + sName + '" could not be found!');
Exit;
end;
lstForm := TStringList(lstForms.Objects[iLoop]);
for iLoop := 0 to lstForm.Count - 1 do
begin
sLine := lstForm[iLoop];
iPos := Pos('=', sLine);
iLen := Length(sLine);
if iPos = 0 then
continue;
CmdName := Uppercase(Trim(Copy(sLine, 1, iPos - 1)));
sWork2 := Trim(Copy(sLine, iPos + 1, iLen));
if CmdName = 'FORMCAPTION' then
begin
with wfrm do
begin
Caption := Trim(Copy(sLine, iPos + 1, iLen));
Name := Trim(sName);
Height := iFormHeight;
Width := iFormWidth;
Tag := 10;
BorderStyle := bsSizeable;
BorderIcons := [biSystemMenu];
Position := poDesktopCenter;
pnl := TPanel.Create(wfrm);
with pnl do
begin
Parent := wfrm;
Caption := '';
Align := alBottom;
BevelInner := bvNone;
BevelOuter := bvNone;
Height := 30;
end;
with TButton.Create(wfrm) do
begin
Parent := pnl;
Caption := '&OK';
Default := True;
ModalResult := mrOK;
Left := 235;
Top := 0;
end;
with TButton.Create(wfrm) do
begin
Parent := pnl;
Caption := '&Cancel';
Cancel := True;
ModalResult := mrCancel;
Left := 310;
Top := 0;
end;
pnl := TPanel.Create(wfrm);
with pnl do
begin
Parent := wfrm;
Caption := '';
Align := alClient;
BevelInner := bvRaised;
BevelOuter := bvNone;
BorderWidth := 5;
end;
end;
end
else
begin
lst.Clear;
StringToList(sWork2, lst, ':');
if UpperCase(lst[0]) = 'EDITBOX' then
CreateEditBox
else if UpperCase(lst[0]) = 'CHECKBOX' then
CreateCheckBox
else if UpperCase(lst[0]) = 'COMBOBOX' then
CreateComboBox
else if UpperCase(lst[0]) = 'LABEL' then
CreateLabel;
end;
end;
with wfrm do
begin
if hresult1 > 1 then
hresult2 := 5
else
hresult2 := 9;
Tag := Tag + hresult2;
Height := Height + hresult2;
end;
lst.Free;
end;
And here is the specific code to create the TComboBox, w/ TLabel, for the form:
procedure CreateComboBox;
var
iPos: Integer;
begin
with TLabel.Create(wfrm) do
begin
Parent := pnl;
Caption := lst[1];
Left := 15;
if hresult1 > 1 then
hresult2 := 5 * hresult1
else
hresult2 := 3 * hresult1;
Top := wfrm.Tag + hresult2;
Name := 'lbl' + CmdName;
Width := 150;
WordWrap := True;
AutoSize := True;
lh := Height;
end;
hresult1 := Trunc(lh/13);
with TComboBox.Create(wfrm) do
begin
Parent := pnl;
Left := 170;
Width := 200;
if hresult1 > 1 then
hresult2 := 5 * hresult1
else
hresult2 := 3 * hresult1;
Top := wfrm.Tag + hresult2;
Style := csDropDownList;
Name := UpperCase(CmdName);
Text := 'Test Text';
sWork := lst[3];
lst.Clear;
StringToList(sWork, lst, ',');
for iPos := 0 to lst.Count - 1 do
lst[iPos] := lst[iPos];
Items.Assign(lst);
// ItemIndex := 0;
end;
wfrm.Tag := wfrm.Tag + ((hresult1 * 13)+ 13);
wfrm.Height := wfrm.Height + ((hresult1 * 13)+ 13);
TComboBox(wfrm
end;
NOTE: the above procedure is a child procedure of the CreateForm procedure.
The app uses TStringList lists to store the form definition at script/macro runtime. Then the above code retrieves that information to create to form when the author wants the form to be shown. And then creates the form and places the form object into another temporary TStringList list prior to being shown. This is done so that when the user runs the script/macro and enters the information/settings as requested in the form. The author may retrieve the requested information/settings from the form before the form is destroyed.
The form is deleted (if previously created) from tmp TStringList list, created, stored in tmp TStringList list, and shown modally with the following code:
iPos := lstForms.IndexOf(UpperCase(sWVar2));
if iPos < 0 then
begin
AbortError('Could not find form "' + Trim(sWVar2) + '" defined!');
Exit;
end;
iPos := lstFormsTMP.IndexOf(UpperCase(sWVar2));
if iPos > -1then
begin
TForm(lstFormsTMP.Objects[iPos]).Free;
lstFormsTMP.Delete(iPos);
frm.Free;
iPos := lstFormsTMP.IndexOf(UpperCase(sWVar2));
if iPos > -1 then
begin
AbortError('Form "' + Trim(sWVar2) + '" was not removed from the lstFormsTMP TStringList.');
Exit;
end;
end;
frm := TForm.Create(frmMain);
CreateForm(frm, sWVar2);
lstFormsTMP.AddObject(Uppercase(sWVar2), frm);
end;
iPos := lstFormsTMP.IndexOf(UpperCase(sWVar2));
if iPos < 0 then
begin
AbortError('Could not find form "' + Trim(sWVar2) + '" defined!');
Exit;
end;
hndHold := SwitchToHandle(frmMain.Handle);
try
Result := TForm(lstFormsTMP.Objects[iPos]).ShowModal = mrOK;
finally
SwitchToHandle(hndHold);
end;
With the above sets of code the form defined in the running script is created and shown, without to many bugs/errors. But, even though I have hardcoded the text for the TComboBox.Text property. It is not shown. Can anyone shed some lite on why this is the case for me? All other form components, TCheckBox, TEditBox, TLabel, are displayed without any issues, so far. It is just the TComboBox that is causing me to scratch my head in confusion.
NOTE: Eventually the TComboBox.Text property will be dynamically set based on the authors setting for that property in the form component's definition.
Thanks in advance.
EDITED 8/18/2013, to include the following:
The original code also includes the ability to save/load the form component's settings by way of the TIniFile object. The following code is used to save the setting for the TComboBox:
if frm.Components[i] is TCombobox then
iniWork.WriteString(frm.Name, TCombobox(frm.Components[i]).Name, TCombobox(frm.Components[i]).Text)
else
and the following to load the TComboBox setting:
if frm.Components[i] is TCombobox then
begin
TCombobox(frm.Components[i]).ItemIndex := TCombobox(frm.Components[i]).Items.IndexOf(
iniWork.ReadString(frm.Name, TCombobox(frm.Components[i]).Name, TCombobox(frm.Components[i]).Text));
end
With the above code it looks to me like the setting is being save from and loaded back into the TComboBox's Text property. Now when the TComboBox setting is loaded, the form is changed after it has been created and placed, as an object, into the tmp TStringList list and prior to being shown modally. Yet, when the form is shown the Text property, as set by the above load code above, is shown.
It is because of the above that I am confused. Why does it work at this point, after the form is created. Yet not when the form is created?
This is a drop down list because you set the style to csDropDownList. That means that the edit control of the combo box can only display items that are contained in its list control.
For a drop down list combo, setting the Text property has no effect. Instead of using the Text property, you should be specifying ItemIndex.
I have put a formula to display the value of a field after masking it in crystal reports. but it shows me an error 'The string is non-numeric' in cardno variable. Following is code of my formula:
StringVar cardno;
NumberVar current_len;
NumberVar card_len;
NumberVar start;
NumberVar last;
StringVar ca;
card_len := ToNumber (Mid ({#lens},1,2));
start := ToNumber (Mid ({#lens},3,2));
last := ToNumber (Mid ({#lens},5,2));
current_len := Length (Trim (ToText({CA.CA}, 0 ,'')));
ca := ReplicateString("0",card_len-current_len) + Totext({CA.CA},0,'');
If card_len > current_len Then
If start = 0 Then
If last <= 1 Then
cardno := Mid(ca, last, card_len)
Else
cardno := ReplicateString("X",last-start-1) + Mid(ca, last, card_len)
Else
cardno := Mid (ca,1,start) + ReplicateString("X",last-start-1) + Mid(ca, last, card_len);
Please provide a solution to avoid this error. Thanks in advance.
Why don't you do something like this:
Select Len({table.field})
//AmEx
Case 15: Picture({table.field}, "XXXX XXXXXX XXXXX")
//Visa
Case 16: Picture({table.field}, "XXXX XXXX XXXX XXXX")
Default: {table.field}
** edit **
Replace(Space(Len({table.field})-4), " ", "X") + Right({table.field},4)