Topics

FNusing for strings

Ian_Wade_G3NRW
 

(Best viewed in monospace font)

I am sure this is very easy, but I haven't been able to do it.

I want to output columns of strings across the page to a file.
The strings are to be treated as containing ASCII characters, some of
which may be digits (but which are to be treated as characters).

Let's say:
string1 is to start at print position 0.
string2 is to start at print position 6.

I thought I could use FNusing something like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PRINT#handle, (FNusing "??????","r2d2") (FNusing "????","Q7")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

where ? is an (unknown to me) placeholder for each character.

Assuming the above PRINT command format is correct, what is the placeholder for a string character?

Otherwise, is there another way of tabbing to print position 6 after printing the first string?

Ian

Ian_Wade_G3NRW
 

Thanks J.G.

The BPUT example is just the job. I had forgotten about the STRING$ command.

--
Ian

On 21/04/2017 21:59, J.G.Harston wrote:
Ian_Wade_G3NRW wrote:
Otherwise, is there another way of tabbing to print position 6 after
printing the first string?
If you are printing to the screen with PRINT, then just simply use TAB(), eg:

PRINT a$;TAB(6);b$;TAB(12);c$

If you are outputing to a file, something like:

BPUT#out%,a$+STRING$(6-LENa$," ")+b$+STRING$(6-LENb$)+c$

Note that this assumes all strings are no longer than 6 characters long.

J.G.Harston
 

Ian_Wade_G3NRW wrote:
Otherwise, is there another way of tabbing to print position 6 after
printing the first string?
If you are printing to the screen with PRINT, then just simply use TAB(), eg:

PRINT a$;TAB(6);b$;TAB(12);c$

If you are outputing to a file, something like:

BPUT#out%,a$+STRING$(6-LENa$," ")+b$+STRING$(6-LENb$)+c$

Note that this assumes all strings are no longer than 6 characters long.

--
J.G.Harston - jgh@... - mdfs.net/jgh

Richard Russell
 

On Fri, Apr 21, 2017 at 01:43 pm, Ian_Wade_G3NRW wrote:
Otherwise, is there another way of tabbing to print position 6 after printing the first string?

In BBC BASIC (somewhat unusually) the formatting available when using PRINT (to the screen) is more flexible than that available when using PRINT# (to a file).  For example the TAB() and SPC() functions are available in the former case but not in the latter case.  As Jonathan says, you can (to a close approximation) emulate TAB() and SPC() using the STRING$() function but an alternative and possibly more flexible approach is temporarily to redirect the screen output to a file using *SPOOL (or *SPOOLON) and VDU 21, for example:

      VDU 21
      OSCLI "spool """ + file$ + """"
      PRINT .....

      *spool
      VDU 6

One particular thing you must be careful of is to trap errors so that if something goes wrong while the output is redirected it doesn't stick that way.  Using SEH is a good approach:

      VDU 21
      OSCLI "spool """ + file$ + """"
      ON ERROR LOCAL IF FALSE THEN
        PRINT .....
      ENDIF : RESTORE ERROR
      *spool
      VDU 6
 

That way the full set of PRINT formatting capabilities is available when outputting to a file.

Richard.

Howard
 


I would just add there is a good example of the technique Richard describes in the PROFILER Utility in the Examples/Tools folder.  I confess it took me quite a while to work out exactly how this worked and and exactly why the syntax is as it is but it was well worth doing. PROFILER shows exactly the value and power not only of this technique.but also the language generally.

More broadly, for anyone learning the more obscure bits of the language (ie all of us except Richard) going through the Example Programmes and working out how they do what they do is good way of getting beyond the basics of the language and seing how it can be put to use - even if it is a bit hard work to decode them sometimes!


Best wishes,


Howard