Click to See Complete Forum and Search --> : Fill in the Blanks


Judgey
March 22nd, 2001, 04:51 AM
Hello Everybody, I wonder if somebody could help,

what I would like to do is have a user type a paragraph of text, on specific words or phrases put square bracketts round eg :

The [Cat] sat on the [Mat].

I would then like this to be given to another user but where there is a word with [] round substitute a blank text box.

Can anybody think of an easy way of doing this, I have achieved it by splitting the text in single charactes and using the load command to dynamically create labels and text boxes at runtime, the problem with this is formatting the layout into a picture box, especially when you have carriage returns etc in the text.

Or am I running round the houses ?

wbeetge
March 22nd, 2001, 05:07 AM
How do you supply the result ? Do you use label controls for the normal text or do you print the text to the picturebox with the autoredraw property set to True ?

Judgey
March 22nd, 2001, 05:14 AM
Thanx for you prompt interest wbeetge,

I am using the picture box just as a container for the labels and text boxes. I use basically set up a loop for the number of characters in the text.

I then use the MID and INSTR functions to split load each word, ( any text seperated by spaces ), if the word has [ ]'s round it I set the label. borderstyle to 1 if not set it to 0. then I just postion side by side until they hit the width of the picture box then increment the label.top so goes onto the next line.

When this loop is finished, I use another loop to go through each label control to see if its border style is 1. If it is place load a textbox, size and postion it to the same as the label.

very long winded i know, but I couldn't think of anyother way, but it all falls over when carriage returns are in the text.

wbeetge
March 22nd, 2001, 05:43 AM
The way I see it, you have 2 quick options.
1) Keep on using the label methods but;
- Do not split the original string by character
- Rather do an instr for "[" chacter
- Keep tabs on the position in which you found it
- Again, do an instr on "Chr$(13) & Chr$(10)" or use the defualt VB constant for Line Feed
- If the line feed characters are found after the "[" then there are no hard returns in the string up to that point.
- if not, cut the substring short, place it in the label.
- Then you measure the TEXTWIDTH of the substring and trim the substring until it will fit in the space that is available on that line on the picturebox
- By now you probably have guessed that you will be using one label per line across
- I would not replace the "[]" text with spaces, but rather use them as actual placeholders in the labels.
- Once a line is completed, I would then again instr the label for the "[" and the "]" caracters .
- With these values you can again use the TEXTWIDTH function to determine the left and width of the required text box.
- Since you already know the label name, you know the Top property that is to be used for the text box.
- Using the Top, Left, and Width properties on the textbox, you should be able to fit it on top of the "[XXXXXXXX]" text.
-----------------------------------------------
2) Use the Printer object to print the text to the picture box
- Again, use the same instr functions to wrap the text correctly.
- As the CurrentX/Y positions keep themselves updated , these positions will tell you exactly where to place the Top of your textbox.
You will have to use TEXTWIDTH again to determine how wide to make the textbox.

Judgey
March 22nd, 2001, 06:02 AM
Excellent,cheers Wimpie . . .