[futurebasic] Re: [FB] Print text in a window the user created

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2006 : Group Archive : Group : All Groups

From: Stu Cram <stu@...>
Date: Thu, 29 Jun 2006 16:04:14 -0600
Brian;

Your BASIC interpreter program has to decode commands from your  
'instructions' window but when the PRINT instruction is encountered,  
then the interpreter needs to switch to the desired output window, do  
the printing, --AND-- switch back to the 'instructions window before  
getting the next instruction. If that last step is not done, then  
your interpreter will try to get an instruction from an edit field in  
to output window as it is still active. The easiest way to solve this  
is to have a window command for the instructions window at the the  
start of the function.

example:
    WINDOW _myInstructionWnd     '<--- add a line like this
    efH = TEhandle( efID )

and here as well...
    FOR i = 1 TO numLines
      WINDOW _myInstructionWnd     '<--- add a line like this
      lineStr = EDIT$( efId, i )


Other comments...

1. Your wariable 'id' is used for the output window's id
It is set by CASE "OUTPUTWIN" in your program.
You do NOT have to change windows at that time, only just before  
printing.

2. Set the value for 'id  more accurately like this:
    id = VAL( restOfCommand$ )
not
    id = RIGHT$( restOdCommand$, 10 )

3. You have more code than needed for printing; this is shorter:
    case "PRINT"
      WINDOW OUTPUT #id
      PRINT restOfCommand$

4. Sometimes you have 'restOfCommand' and other times 'restOfCommand$'.
      It's best to be consistent with variable names and types;
	- some versions of BASIC may treat them as different variables.

5. Variable 'id' should be set to some initial default value (maybe  
1?) in case the user tries to print before using your OUTPUTWIN  
command. Or maybe set it to 0 initially and check for that and issue  
a warning like 'No window to print in' if id is still zero when the  
user tries to print.


Hope this helps;
-Stu

==================================================
On Jun 26, 2006, at 5:13 PM, Brian Heibert wrote:

> I have this local fn to parse my edit field
> See below
>
> and I have this
> case "PRINT"
> WINDOW #id
> WINDOW OUTPUT #id
> PRINT restOfCommand$
>
> but it doesn't print the text the user types into the window the  
> user created
> how do I fix this?
>
> Brian
>
>
> local fn ParseEFLines( efID as long )
> dim as handle  efH
> dim as long    i, numLines
> dim as str255  lineStr
> dim as str255 lineStr2
> dim PositionOfSpace
> dim keyWord$
> dim restOfCommand$
> // Obtain handle to selected edit field
> efH = TeHandle( efID )
>
> // Test for valid handle
> long if ( efH != 0 )
> numLines = efH..teNLines%
> // Test to see if EF contains any lines
> long if ( numLines > 0 )
> for i = 1 to numLines
> lineStr = edit$( efID, i )
> lineStr2 = lineStr + " "
> positionOfSpace = INSTR( 1, linestr2$,  " " )
> keyWord$ = UCASE$(  LEFT$( linestr2$, positionOfSpace - 1 )  )
> restOfCommand$ = MID$( lineStr, positionOfSpace + 1 )
> dim title$, num1,num2,num3,num4,id
> select case keyWord$
> case "BEEP"
> beep
> case "OUTPUTWIN"
> id = RIGHT$(restOfCommand,10)
> WINDOW #id
> case "PRINT"
> WINDOW #id
> WINDOW OUTPUT #id
> WINDOW #id
> PRINT restOfCommand$
> end select
> next i
> xelse
> // Return error if EF has no lines to parse
> numLines = -1
> end if
> xelse
> // Return error if EF is not valid
> numLines = -1
> end if
> end fn = numLines
>
>
>
> Brian Heibert
> bheibert@...
>
> --
>
>