ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

problem char to decimal

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem char to decimal

    i need to take a char variable to decimal. what i am doing is using scanning the field into the program but it can also be entered in manually. if entered in manually it will be in number format with zeros in front of it, but if i scan it may have a 'Q' in the field. i know that i can scan for a 'Q' and %subst the number portion back out of the field. so if my scan number is 000Q85 i can get the 85 out but when i go to move it to the number field it becomes 85000. i am currently using v5r1 software and writing this mostly in rpg free format.

    thanks for all your help in advance.

    don

    here is the code using. or is there a way to iniz a variable to be any number but 0

    result = *zeros;
    reslt = *zeros;
    qtytmp = qty1;
    result = %scan('Q':qty1:1);
    reslt = 7 - result;
    qty = %dec(qty2: 6 : 0);
    /end-free
    c move(p) qty2 qty
    /free

  • #2
    Re: problem char to decimal

    Input = '000Q85';
    Pos = %Scan('Q':Input);
    Input = %Replace('0':Input:Pos:1);

    // Input now contain 000085
    // even if Input = 000085 then it won;t find the Q and you're still ok

    Bill
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: problem char to decimal

      thanks bill i knew that i have done it before but for life of me i couldn't remeber how or what i did.

      Comment


      • #4
        Re: problem char to decimal

        Even better because your are scanning and getting either 'Q85 ' or '000085'

        d Input s 6a
        d Number s 6 0
        d Pos s 2 0

        // Remove any'Q'
        Pos = %Scan('Q' : Input);
        If Pos > 0;
        Input = %Replace(' ':Input:Pos:1);
        Endif;

        // Remove all 0 (zeros) DON"T DO HTIS CAUSE IF Input is 80 then you'll end up with 8
        // Excuse my dumbness
        // DoU Pos = 0;
        // Pos = %Scan('0' : Input);
        // If Pos > 0;
        // Input = %Replace(' ':Input:Pos:1);
        // Endif;
        // Enddo;

        Number = %Dec(Input : 6 : 0);

        // Now Number contains the numeric info


        More generic.

        Bill

        PS: Remove the removal of zeros
        Last edited by Billw; November 7, 2006, 02:04 PM.
        Bill
        "A good friend will bail you out of jail,
        A true friend would be sitting beside you saying,
        'Wow, that was fun.'"

        Comment

        Working...
        X