Announcement

Collapse
No announcement yet.

Problem with RIGHT$

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

  • Tom Hanlin
    replied
    As George and Peter hint, it appears that there may be "invisible"
    characters in your string that are interfering with the test. You
    might print out the string in question, by taking the ASC of each
    character, and make sure that it really is what you think it is.
    If the problem is not in the string itself, you may have a nastier
    problem, such as program corruption from a bad error earlier in the
    code.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Fred Katzel
    replied
    Hi

    I have tried all your suggestions with no results. However, I
    found that by converting the numbers from their character form
    to their numerical form and checking for their desired positions
    did work. I still don't know why, IF RIGHT$(n$(i), 1) = "0" ...
    doesn't work.

    Fred K

    ------------------

    Leave a comment:


  • Peter Lameijn
    replied
    Make sure n$ isn't right-filled with space or zero character, or test will fail.
    Code:
    Trim$(n$(i), Any Chr$(32,0))
    ------------------
    Regards,
    Peter

    Leave a comment:


  • keith shelton
    replied
    Fred why not use
    Code:
    a$ = (the desired number)
    FOR i = 1 TO n
      IF RIGHT$(N$(I),1)="0" THEN ITERATE
      IF LEFT$(n$(i), 1) = a$ THEN a = a + 1
    NEXT
    This should do it.
    Keith

    ------------------

    Leave a comment:


  • George Bleck
    replied
    Clay, without formatting it looks that way, but it is ok.

    Fred, Logically speaking your code is saying:

    The b variable only gets incremented if the current array item begins with "magic number" and ends with 0.

    Are you sure that the last character in the array item is REALLY a number though (is there a space, a null, etc.)?

    ------------------
    Every day I try to learn one thing new,
    but new things to learn are increasing exponentially.
    At this rate I’m becoming an idiot faster and faster !!!
    ------------------
    George W. Bleck
    Lead Computer Systems Engineer
    KeySpan Corporation
    My Email

    Leave a comment:


  • Clay Clear
    replied
    Fred,

    Maybe I read it too quickly, but I am pretty sure that I saw
    TWO "IF" statements, but only ONE "END IF" statement. I'll go back
    after I post this and see if I misread it. If I did misread it,
    please accept my apologies.


    ------------------

    Leave a comment:


  • Fred Katzel
    started a topic Problem with RIGHT$

    Problem with RIGHT$

    Hi
    I have a program that determines how many numbers in an array
    begins with a given number, however, if the number ends in zero
    I want to exceed it. The part of the program that does this is
    as follow:

    a$ = (the desired number)
    FOR i = 1 TO n
    IF LEFT$(n$(i), 1) = a$ THEN
    a = a + 1
    IF RIGHT$(n$(i), 1) = "0" THEN b = b + 1
    END IF
    NEXT

    Later I subtract b from a to obtain the number that are accept-
    able. In some test data "a" was correct but the one number that
    ended in a zero the program failed to pickup.

    I tried the following one line:

    IF LEFT$(n$(i), 1) = a$ AND RIGHT$(n$(i), 1) = "0" THEN b = b + 1

    This one line had the same results or should I say the same lack
    lack of results.

    Fred K



    ------------------
Working...
X