locked
How to split text in lines in VFP Edit Box RRS feed

  • Question

  • Dear All,

    I'm using character type field (size-255) in my foxpro table and want to split text in lines after lenth of each 50 characters, for this I'm using some code but its not working properly, but when I start deleting characters using backspace after exceeding length of 50 characters it crashes in unwanted lines. Can you please suggest me what appropriate code should I use.

    Code in InteractiveChange event:

    lcAddress=This.Value
    lnLength=LEN(lcAddress)
    IF MOD(lnLength,50)=0
       FOR mPrev=lnLength TO 1 STEP -1
          IF SUBSTR(lcAddress,mPrev,1)=' '
             lcAddress=STUFF(lcAddress,mPrev,1,CHR(13)+CHR(10))
             KEYBOARD '{END}'
             EXIT
          ENDIF
       ENDFOR
       This.Value=lcAddress
    ENDIF

    With Best Regards

    ShahidSQL (India)



    • Edited by ShahidSQL Friday, January 19, 2018 3:33 PM
    Friday, January 19, 2018 3:10 PM

Answers

  • Hi ShahidSQL,

    you could do something like this:

    c1=[This is a very long string and it is long just because I want to demonstrate how to work with looooong strings and get them split up automatically in VFP.]
    ?c1
    SET MEMOWIDTH TO 40
    ?MEMLINES( c1 )
    ?MLINE( c1 , 1 )
    ?MLINE( c1 , 2 )
    ?MLINE( c1 , 3 )
    ?MLINE( c1 , 4 )
    ?MLINE( c1 , 5 )

    Using those functions might be helpful. BTW, MEMLINES() can be used in a loop.

    HTH


    Gruss / Best regards
    -Tom
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible,
    you are, by definition, not smart enough to debug it. 010101100100011001010000011110000101001001101111011000110110101101110011

    • Marked as answer by ShahidSQL Sunday, January 21, 2018 11:16 AM
    Saturday, January 20, 2018 10:31 PM
    Answerer

All replies

  • Mainly notice CHR(13) and CHR(10) are counting for LEN(), even though these are contol characters only. What you are doing here with MOD therefore is too simple and you would need to check whether you are at 50 printable charactersby removing all non printable and control characters.

    The two additional bytes you add by adding CHR(13)+CHR(10) make it so, that you are at 52 characters and deleting 2 of them you get back to 50, which means another line break is added, and so lines split at single words.

    A simple way to fix that would be ignoring the InteractiveChange, if LASTKEY() was DEL or backspace.

    But the whole problem needs another way to adress this, as you could coyp&paste any length of text and if that doesn't make the length a multiple of 50 wouldn't cause a line break, whereas you could even need multiple line breaks to be introduced at the same time.

    So actually with any change (also programmatic) you would need to split whatever current text into lines shorter than 50 chars each.

    Bye, Olaf.


    Olaf Doschke - http://www.doschke.name

    Saturday, January 20, 2018 1:30 PM
  • Hi ShahidSQL,

    you could do something like this:

    c1=[This is a very long string and it is long just because I want to demonstrate how to work with looooong strings and get them split up automatically in VFP.]
    ?c1
    SET MEMOWIDTH TO 40
    ?MEMLINES( c1 )
    ?MLINE( c1 , 1 )
    ?MLINE( c1 , 2 )
    ?MLINE( c1 , 3 )
    ?MLINE( c1 , 4 )
    ?MLINE( c1 , 5 )

    Using those functions might be helpful. BTW, MEMLINES() can be used in a loop.

    HTH


    Gruss / Best regards
    -Tom
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible,
    you are, by definition, not smart enough to debug it. 010101100100011001010000011110000101001001101111011000110110101101110011

    • Marked as answer by ShahidSQL Sunday, January 21, 2018 11:16 AM
    Saturday, January 20, 2018 10:31 PM
    Answerer
  • Thanks Olaf Doschke ... Thanks Tom Borgmann ...

    Its working ... :) Actually I wanted just like this. It is more useful because in this way whole text size would not matter and I could split by any size.

    Thanks Again ... :)

    Sunday, January 21, 2018 11:22 AM