forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Wrap Text

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Sun Feb 24, 2002 3:46 am    Post subject: Wrap Text Reply with quote

I need a wee bit of help. I want to wrap a paragraph of text to
a specific length. By this I mean, I have an edit box to enter information
in, but I want to be able to get that info from the edit box (that I know
how to do. Laughing ), but I want to have each line only 50 characters in
length. If the line is longer, I want to have the remaining words wrap
to the next line. I'm brain dead right now, anyone have code to
do this?

Thanks.

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sun Feb 24, 2002 7:26 am    Post subject: Reply with quote

If you want the text to be only 50 chars wide in
the edit box, you can use a fixed width font and
make the edit box 50 chars wide (using the WRAP
style)...
_______________________________________________________________________________________________________________________________________________________________________________________
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test prog,-1,0,366,200
  DIALOG ADD,STYLE,Style1,Courier New,8
  DIALOG ADD,BUTTON,B1,5,5,100,20,"Chars in line 1"
  DIALOG ADD,EDIT,E1,30,5,356,165,,,MULTI,WRAP,Style1
DIALOG SHOW

:EVLOOP
  WAIT EVENT
  goto @event()

:B1BUTTON
  rem -- Get number of chars in first line --
  %z = @sendmsg(@win(~E1),$0C1,1,0)
  INFO Chars in line 1 = %z@tab()
  goto EVLOOP

:CLOSE
  EXIT


Or if you just want the retrieved text to be 50
chars per line when you copy it to a listbox, etc...
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,Test prog,-1,0,366,200
  DIALOG ADD,LIST,L1,5,5,356,190
DIALOG SHOW

rem -- A 200 char string example --
REPEAT
  %s = %s"q"
UNTIL @equal(@len(%s), 200)
INFO Length of string: @len(%s)

rem -- Insert @cr() every 50 chars --
%x = 1
%t = ""
REPEAT
  %t = %t@substr(%s,%x)
  if @equal(@mod(%x,50), 0)
     %t = %t@cr()
  end
  %x = @succ(%x)
UNTIL @greater(%x, @len(%s))

rem -- Assign new string to list --
LIST ASSIGN, L1, %t

INFO Item Lengths: @cr()@len(@item(L1, 0))@cr()@len(@item(L1, 1))@cr()@len(@item(L1, 2))@cr()@len(@item(L1, 3))

:EVLOOP
  WAIT EVENT
  goto @event()

:CLOSE
  EXIT

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Sun Feb 24, 2002 11:49 am    Post subject: Reply with quote

Oh damn!!!! I've got some code here somewhere for
wrapping text!!!

It counts the text to the amount (we'll say 50 since
that's what you mentioned) you want, and then moves
back to the the next available SPACE.

Then cuts out the text to that space and then continues
to do that until it has a list of nothing but lines of 50
characters or less without breaking words.

If that's what you mean, I'll see if I can dig that up as
soon as I possibly can.

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Sun Feb 24, 2002 2:15 pm    Post subject: Reply with quote

Garrett,

That is what I mean. Please try to find it! Sad
I'll be your best friend Exclamation Very Happy

Mac,

Thanks for your help. I knew the first one, I think I can use the second
script for another script, but the one Garrett is talking about is what I
need. I'm still your friend. Wink

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Garrett
Moderator Team


Joined: 04 Oct 2001
Posts: 2149
Location: A House

PostPosted: Mon Feb 25, 2002 10:46 am    Post subject: Reply with quote

Ok, I can't find my original code for doing this, so I just slapped
together another one rather quickly here. This is not refined or
perfect, but it does what it's suppose to, so if you want to tweak
it to work better, then you'll have to play with it a bit.

It takes the text in a variable for this example, and also set the
character count in the second variable.

It then starts looking at the character limit for @chr(32) and if
not found there, it repeats in a loop reducing the limit until it it
hits @chr(32), then adds the text from 1 to where it found the
@chr(32), and then removes that text from the main text, and
then just keeps doing that until the text left over is less than the
character limit you've set.

Code:
%%InText = "Only as an example, this resembles an address book.  But it is not a fully functional program at all.  It merely shows you how to insert and remove list items in a simple way."
%%WrapAt = 50
List Create,1
Repeat
  %%WrapCounter = %%WrapAt
  Repeat
    %A = @substr(%%InText,%%WrapCounter,%%WrapCounter)
    If @not(@equal(%A,@chr(32)))
      %%WrapCounter = @succ(%%WrapCounter)
    End
  Until @equal(%A,@chr(32))@not(@greater(@len(%%InText),%%WrapAt))
  List Add,1,@substr(%%InText,1,%%WrapCounter)
  %%InText = @substr(%%InText,%%WrapCounter,@len(%%InText))
Until @null(%%InText)
Info @text(1)

_________________
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Back to top
View user's profile Send private message
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Mon Feb 25, 2002 1:02 pm    Post subject: Reply with quote

Garrett,

I tried your code and it worked great. Before I saw your last post, I decided
to try and make my own. I'm not sure why I couldn't before (I think I
was Brain Dead!). I gut mine to work nicely. It still needs tweaked, but
here it is if you want to take a look at it. Thanks for your help. I may
just use and tweak your as it is less code.

Code:

:Wrap
    %%all = This is the code that I had made. I think that it does work nicely for what I need.@chr(13)@chr(10)It does need to be tweaked.
   list create,15
   list assign,15,%%all
   list create,14
   %%Wrap = 50
   if @greater(@count(15),0)
      %x = 0
      repeat
         %i = @item(15,%x)
         if @greater(@len(%i),%%Wrap)
            %%len = %%Wrap
            repeat
               %s = @substr(%i,%%len,%%len)
               %%len = @pred(%%len)
            until @equal(%s," ")
            %%line = @substr(%i,1,%%len)
            %%line2 = @substr(%i,@succ(%%len),@len(%i))
            if @equal(@succ(%x),@count(15))
               list add,14,@trim(%%line)
               list add,15,@trim(%%line2)
            else
               list add,14,@trim(%%line)
               %i = @item(15,@succ(%x))
               list seek,15,@succ(%x)
               list put,15,@trim(%%line2)" "@trim(%i)
            end
         else
            list add,14,@trim(%i)
         end
         %x = @succ(%x)
      until @equal(%x,@count(15))
   end
   %%all = @text(14)
   list close,15
   list close,14
   info %%all
   exit

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Mon Feb 25, 2002 10:21 pm    Post subject: Reply with quote

Hey Chris, Smile

Sorry, I really wasn't sure what you were doing, that's
why I posted two examples. I wondered if you wanted
the edit box to wrap while the user was entering the data.

My second example should also go back to the nearest
space like Garrett's example, otherwise it'll split words.

You weren't the only one brain dead on this one...Embarassed

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1751
Location: Space and Time

PostPosted: Tue Feb 26, 2002 3:01 am    Post subject: Reply with quote

No prob, Mac. It happens to the best of us! Laughing
_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group