|
-
Mar 1st, 2007, 04:01 PM
#1
Thread Starter
Addicted Member
save to fixed text files
Hi gurus.
New to vb so go easy on me,
I have a few string variables (Name,lastname,gender,dob) I need to save this variables to a fixed text file, for example Name variable has to be from 1 to 15 the I have a filler that starts at 16 and ends on 20, then we have lastname that starts at 21 and ends up at 51 and so on, hope I make sence
How do I go doing this, thanks for any help I can get or if you point me to the right direction.
Thanks a bunch
gurus
-
Mar 1st, 2007, 04:08 PM
#2
Fanatic Member
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.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 1st, 2007, 04:19 PM
#3
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.
-
Mar 1st, 2007, 04:35 PM
#4
Fanatic Member
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.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 1st, 2007, 04:41 PM
#5
Thread Starter
Addicted Member
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
-
Mar 1st, 2007, 04:42 PM
#6
Thread Starter
Addicted Member
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
-
Mar 1st, 2007, 05:06 PM
#7
Fanatic Member
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.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 1st, 2007, 05:16 PM
#8
Addicted Member
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()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|