home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,057 of 10,840   
   Steve Gerrard to Stefanie   
   Re: Declaring variables and file for ran   
   05 Dec 04 09:30:07   
   
   XPost: comp.lang.basic.visual, comp.lang.basic.visual.misc   
   From: mynamehere@comcast.net   
      
   "Stefanie"  wrote in message   
   news:157fd$41b32ced$513b4d44$1464@news1.zonnet.nl...   
   | Hi,   
   |   
   | I have a question about declaring variables for writing data to a file   
   for   
   | random access.   
   | I have two string variables declared in a module (user-defined types).   
   | The point is that for one of them  i can't define (hard coded) a fixed   
   | length because the application is reading data   
   | from another file (In that file they have the same lenght).   
   | Is it possible to use the lenght i obtain from reading that other file   
   to   
   | declare my variable or are there   
   | other possibilities.   
   |   
   | Thanks in advance,   
   |   
   | Stefanie   
   |   
      
   I think what you are after is how to write a string to an output file   
   with a specified field width, without using a fixed length string, since   
   you don't know the fixed length needed until run time.   
      
   If so, then you should be able to do something like this:   
       n = FixedLengthNeeded   
       j = Len(StringToWrite)   
      
       k = n - j    ' spaces needed   
      
       If k > 0 Then   
           ' print string and pad with spaces   
           Print #FileNum, StringToWrite, Space$(k)   
       Else   
           ' clip string to maximum length   
           Print #FileNum, Left$(StringToWrite, n)   
       End If   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca