Re: save to fixed text files
To get the filler you could use something like
(Name & " ").Substring(0, 15)
This will give you their name and how ever many spaces it takes to get to 15, provided that you are sure that Name will never be more than 15 characters. And this can be modified and repeated for the other ones. I don't know how to write to text files, but you could search the forums for it.
Re: save to fixed text files
Use PadRight or PadLeft function to fill up the values with blanks if they're not long enough... To limit the user to enter text longer than your length limit, set each textbox's maxlength property to the length you want.
The code 18experience showed you will error out if the actual text length is less than 15 characters.
Re: save to fixed text files
Oops. There should've been many more spaces in there, 15 in fact. That would ensure that even if Name was 0 characters long, it would still give you 15 spaces. The forum's editor removed my spaces when I posted.
vb Code:
(Name & " ").Substring(0, 15)
But, either way, I would go with what stanav said.
Re: save to fixed text files
Thanks a bunch gurus
I know the length of the field is always the same as it is coming from a database so the field name wil be 15 no matter what and not from a control on a form, so name will always be 15 no matter how long or short the name is , same with lastname and address, they will always have a fixed length, I need to save this to a text file where from 1 to 15 there is always name and from 16 to 20 filler or blanks and from 21 to 51 always lastname.
Thanks again gurus, but How do I go and save this to a text file
Re: save to fixed text files
Thanks a bunch gurus
I know the length of the field is always the same as it is coming from a database ,so the field name will be 15 no matter what and is not coming from a control on a form(extbox), so name will always be 15 no matter how long or short the name is , same with lastname and address, they will always have a fixed length, I need to save this to a text file where from 1 to 15 there is always name and from 16 to 20 filler or blanks and from 21 to 51 always lastname.
Thanks again gurus, but How do I go and save this to a text file
Re: save to fixed text files
This is a very common question. Use the search tool on the forum to look for "save to text file" or something like that. You can also use the search and index tools in the program you are using to code.
Re: save to fixed text files
Use Stream Writer like ini this example:
Code:
Dim myWriter As New IO.StreamWriter("c:\test1.txt", True) 'true in order to append rather than overwrite
Dim myString As String
myString = "hello"
myWriter.Write(myString)
myWriter.Close()