1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

2 Problems from a new user

Discussion in 'Support' started by clmckay, Nov 1, 2008.

  1. clmckay

    Joined:
    Oct 31, 2008
    Messages:
    2
    Likes Received:
    0
    Hello all,

    I just started with TCC Version 9 about a month ago. I've not used a previous version of this software (unless you count the old 4DOS) so I'm still learning the new nomenclature.

    Anyway, I'm working with batch scripts, not directly from the command line. I've been using CMD from Windows XP Pro SP2.

    My existing batch program (a self-made, Checkbook-type program) appends transations to an existing text file. Fixed width fields are made by appending about 20 'spaces' (actual number of spaces is arbitrary) to the end of the variable and then extracting the first 20. This leaves the original vairable with the appropriate number of white space at the end. It's then written to a file and makes for a very nicely formatted line.

    This does not apepar to work under TCC. It seems to strip any trailing white space from the variable. That's my first question, is there an option that I'm missing. Or is there a control char that I can insert that is invisible, but that 'set' would not strip out?

    The next difficulty is harder to expain. I have this fragment from my script:

    FOR /L %%A IN (1,1,8) DO IF NOT !DS%%A!==*EMPTY* SET DS%%A=!DS%%A! &&SET DS%%A=!DS%%A:~0,20!

    (all one line)

    SET DS%%A=!DS%%A:~0,20! under CMD this variable expands and then gets trimmed correctly. This is another one of those variables that need padded in the first question. In this case though, under TCC, I cannot get it to expand/trim correctly. Left alone I get: !DS%%A:~0,20! as output. I tried adding the brackets, etc and played considerably eventually settling on this:

    FOR /L %%A IN (1,1,8) DO IF NOT %[DS%%A]==*EMPTY* ((SET DS%%A=%[DS%%A] _)&&((SET DS%%A=%@LEFT[20,%[DS%%A]]_))

    (all one line)

    which works (although with the final '_' to prevent the whitespace from dropping.) The only problem is that there are many lines like this and I would prefer not to have to rewrite the entire program just for TCC. I don't understand why it won't correctly work with the variable in the first sample. I would like the original line to work with TCC if at all possible!

    I really hope that I'm missing something that will improve the compatibility. I feel a little disappointed as I was hoping that TCC would be "99%" compatibalbe and that existing batch scripts should work without difficuty!

    Any help would be greatly appreciated!

    Chris McKay
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    clmckay wrote:
    ...

    The character string `` (two consecutive "back apostrophe", technically
    "accent grave", ASCII: 96, characters, typically on the above the "tab" and
    left of the 1! key) forces 4DOS and TCC to retain trailing blank characters
    in SET, ECHO, and other commands, without themselves being retained, just as
    the "invisible marker" you wanted.

    Look up the @FORMAT variable function! It can pad a string with spaces on
    either the left or right, until the desired width is achieved. Lok up @comma
    and @formatn as well. I typically use the function M9 I defined to display a
    monetary amount right justified in a 9-column field, with commas if needed:

    function m9=`%@format[9,%@comma[%@formatn[0.2,%1]]]`

    As I started with 4DOS, and progressed to 4NT and TCC, I never learned all
    those tricky CMD notations you used, thus I cannot figure out what you try
    to do. To parse lines of text, I typically use the variable functions:
    - @word, @field for variable width delimited fields
    - @left, @right, @instr for fixed width, not delimited fields

    Of course, one often needs to combine them, just as 3 different formating
    functions are combined in M9.

    Last, but not least, look up the way TCC can process each line of a file
    with the syntax:

    FOR %LINE IN (@FILE) ...
    or
    DO LINE IN @FILE
    ...
    ENDDO
    --
    HTH, Steve
     
  3. clmckay

    Joined:
    Oct 31, 2008
    Messages:
    2
    Likes Received:
    0
    Hi,

    Thank you very much for your response! The suggestion of using the ` ` did indeed solve the problem with creating the fixed width variables.

    The second problem still remains though. I had thought maybe ` ` around the variable would be beneficial there as well.

    For CMD this [....] SET DS%%A=!DS%%A:~0,20! would take the variable indicated by DS%%A (lets say DS1) and set it to the first 20 characters of itself. Unfortunatly TCC does not seem to know what to do with it and seems to treat it as text. The HelpFile says that TCC will understand this construct of CMD, I'm just having trouble making it do it. I had thought it would do it automatically, but it isn't. I've looked over the SETDOS command and fiddled with it, but no help.

    There are a lot of statements like the above in the script file, and as not everyone uses TCC, I can't change the whole program by using the TCC syntax. That would defeat the purpose, it is advertised to be compatible and I need to find a way to make it so.

    Thanks!

    Chris
     
  4. Peter Bratton

    Joined:
    Jul 1, 2008
    Messages:
    81
    Likes Received:
    0
    I'm convinced someone can help you, but like Steve I'm having trouble understanding CMD syntax I haven't used since my 4DOS epiphany 15 years ago. Since you say this is taken from a batch file, the do/enddo approach might help clarify it, and should work in your batch file. I have interpreted your code below, I hope correctly, does it help?

    DO a = 1 to 8 by 1
    if not defined DS%a set DS%a=%@format[-19,!DS%a]!
    :: if %a is 1, the above line defines DS%a as "!DS1" followed by 14 spaces and an exclamation mark.
    :: the line below displays the result
    echo DS%a == %[DS%a]
    ENDDO
    --
    Peter
     
  5. joshjeppson

    Joined:
    Jun 2, 2008
    Messages:
    42
    Likes Received:
    0
    The !variablename! syntax is cmd delayed variable syntax. To use it in 4NT or TCC you need to start them with the /v switch.

    See help cmdlineopts for more information.


    - Josh
     

Share This Page