Click here to Skip to main content
15,885,045 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have this problem in crystal report. I get this error the string is no numeric. How can I solve this problem?
VB
if {SelOperActivityView.UserActivity} like "Added Card : *" then
    ToNumber (mid ({SelOperActivityView.UserActivity},26,11))
 else if {SelOperActivityView.UserActivity} like "Modified Card*" then
        ToNumber(mid({SelOperActivityView.UserActivity},29,(instr (29,{SelOperActivityView.UserActivity},":")-29)))
 else if {SelOperActivityView.UserActivity} like "Deleted Card :*" then
    ToNumber(mid({SelOperActivityView.UserActivity},28,8));
Posted
Updated 2-Feb-15 2:18am
v2
Comments
CHill60 2-Feb-15 8:18am    
For what value of SelOperActivityView.UserActivity is it failing?
Member 11420569 2-Feb-15 8:28am    
the {SelOperActivityView.UserActivity}is an text and number so I use this function to get only the number ToNumber (mid ({SelOperActivityView.UserActivity},26,11)). there is were it fails.
CHill60 2-Feb-15 8:33am    
As I said - what is the value of that at the time it is failing?
Member 11420569 2-Feb-15 8:40am    
the string is non numeric. And this the value exp mid({SelOperActivityView.UserActivity},26,11):"19571111,0"
CHill60 2-Feb-15 8:44am    
Well that comma will make it non-numeric unless you have your culture set up as one that uses commas for decimal point

1 solution

The problem is in your ToNumber function and the way you are extracting the numbers.

There are a few ways of doing it - these samples are in C# but you should get the idea...

If you are able to use Linq then
C#
private string ToNumber1(string parm)
{
    var num = parm.ToCharArray().Where(c => Char.IsDigit(c)).ToArray();
    return new String(num);
}

If you are able to use Regex then
C#
private string ToNumber2(string parm)
{
    //You will need using or imports System.Text.RegularExpressions or the equivalent
    var num = Regex.Match(parm, @"\d+").Value;
    return num;
}

Worst case scenario you can step through the string extracting the numbers "manually"
C#
private string ToNumber3(string parm)
{
    //NB as strings are immutable this is not really a good way of doing this
    //If you are able then use the StringBuilder class instead
    string num = string.Empty;
    for (int i = 0; i < parm.Length; i++)
        if (char.IsDigit(parm[i]))
            num += parm[i];
    return num;
}

Alternatively, post the code for your ToNumber function and I'll see if I can fix it.

In Crystal Syntax the function would look something like this (Warning - not tested nor syntax checked)
//parm is the input string

Local StringVar num  := "";
Local NumberVar i;
For i := 0 To Length(Parm) - 1 Do
(
    Local StringVar parmChar := parm [i];
    Local BooleanVar isDigit := parmChar in "0" to "9";
    If IsDigit Then
    (
        num := num + parmChar;
    )
);
num
 
Share this answer
 
v2
Comments
Member 11420569 2-Feb-15 14:55pm    
I really don't understand, because the to number function was working good until I change the database from 2005 to 2008 R2. I test your solutions but or am doing something wrong or it don't work in crystal reports.

The code to my toNumber function is :
if {SelOperActivityView.UserActivity} like "Added Card : *" then
ToNumber (mid ({SelOperActivityView.UserActivity},26,11))
else if {SelOperActivityView.UserActivity} like "Modified Card*" then
ToNumber(mid({SelOperActivityView.UserActivity},29,(instr (29,{SelOperActivityView.UserActivity},":")-29)))
else if {SelOperActivityView.UserActivity} like "Deleted Card :*" then
ToNumber(mid({SelOperActivityView.UserActivity},28,8));
CHill60 3-Feb-15 4:44am    
That's the code that is calling the ToNumber function.
It's probable that my solutions won't work in Crystal Reports as they stand as they are in C# and I don't have Crystal Reports to check any conversion I might try (I won't pay that much money). I'll have a go at it although there may be bugs in what I post.
If everything was fine until you changed database are there any differences in the table schema that could account for these problems?
CHill60 3-Feb-15 5:03am    
I've added a function to my solution since the comment above

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900