Manipulate text documents
Manipulate text documents
Manipulate text documents
Manipulate text documents
Manipulate text documents
Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents
Manipulate text documents Manipulate text documents
Manipulate text documents
Go Back  Xtreme Visual Basic Talk > > > Manipulate text documents


Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2006, 06:17 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Question Manipulate text documents


Hi.

Im pretty new to vb.net, but im trying to make a program that converts .xls info to a .txt. Well.. the difficult part is that in the .txt dokument i should be sertain amount of numbers and spaces between the general "text" ex.

I have the personal info of a person in the .xls

Roger Rabbit 060875 etc...
and i want this to be added to a .txt file that will put in info in front and between the names. spaces ex.

000001Roger00000Rabbit0000000006087500000 etc.

Well.. i dont now if u understand this but the 0000 is used by another program(which i dont know the name of, only how it reads) and it stores personal info.


What i have done in my program is that it opens a .rtd or a .txt and reads it into a textbox or a rich text box, so to make it easier i just convert the .xls to a .txt or .rtd.
So then i want to manipulate the .rtd or .txt file to fill inn a right number and spaces in front,between and behind the name and store it to a new .txt file.

I have tried to use streamwriter with arrays, that only created a new line in the dokument.

'If System.IO.File.Exists(FILE_NAME) = True Then
' Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
' 'objWriter.Write(rtb.Text)
' For i = 0 To 4
' objWriter.WriteLine(arytext(i))

Etc..

and i have tried to use.

Dim MyLines As String()
MyLines = tb.Lines
Me.tb.Lines = MyLines
tb.Text = 1

witch only restores the text in textbox with a "number"

So i need some help to get in the right paddern.... is this coding way off or am i getting close?

If i didnt explaine my self clearly let me now, and i try to explain better.
Thx for all help!

Last edited by rpjeger; 01-26-2006 at 06:34 AM.
Reply With Quote
  #2  
Old 01-26-2006, 06:50 PM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I don't understand the whole concept of how many numbers you are trying to add, but you are making some simple mistakes in your solutions.
Quote:
I have tried to use streamwriter with arrays, that only created a new line in the dokument.
That is because you are using .WriteLine() which writes lines instead of .Write() which keeps everything in-line.

Quote:
witch only restores the text in textbox with a "number"
That is because the last line you have there sets the textbox's .Text to 1.
tb.Text = 1
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-27-2006, 08:09 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Yes. ok i know.. well the whole concept is thaht i want to put spaces and zero's between a text. ex. it says roger rabbit in the textbox/richtextbox and i want to put in automatic zero's and spaces when i push a button. Like this Roger Rabbit (then push button) 0000Roger000Rabbit00 . so simply put som "text" between the other txt.
I need a bit help to which code i should use.
Reply With Quote
  #4  
Old 01-27-2006, 07:08 PM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Have you tried actually putting 000s between words? Where do the words come from? Are you familiar with the & Operator which concatenates strings together.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 01-30-2006, 02:29 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Quote:
Originally Posted by Iceplug
Have you tried actually putting 000s between words? Where do the words come from? Are you familiar with the & Operator which concatenates strings together.

The words comes from a .txt file or a exel file. the 000 is something I define in VB. but i also have a .txt file with the proper use of the 000 if its easyer to do it that way. Im new in vb so im not familiar with so many codes.

Well.. in the .txt file or .rtf or .xls i got the names.(words)

Roger Rabbit England 060378556677 <<--personal number and then other facts.

The 000 or spaces should come in between the information over and i also need the right number of 000 and spaces because the final .txt file should be read by another program. I know the right number of 000 and spaces but i dont know the code to actually put them between the names(words,over)

Is this possible?
Reply With Quote
  #6  
Old 01-30-2006, 05:36 AM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Haved you tried actually putting 000s between words? If not, have you got the words into variables in your program yet? I have no idea how far you've got to tell you where to go next.

It may be possible to put them all in one string and replace the spaces with 000s, but If you want a different amount of 000s between words, then you should use Split() and the & with each separate string in the array to concatenate them together.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 01-31-2006, 04:10 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

well.. no i havent tried that, because i dont know the code to put 000 or text between the words. So far i only have done so that the names and their info shows up in vb. in a richtextbox.

Dim OpenFileDialog1 As New OpenFileDialog

OpenFileDialog1.Filter = "Rich Text Format|*.rtf"
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
rtb.LoadFile(OpenFileDialog1.FileName)

End If

So then i get the information and then i want it to write from the rtb to .txt in a place where the user wants to put it. And when it writes I want it to write in the proper amount of 000s into the .txt as well. yes i think its a differnt amount of 000s.
Heres where it stops up because i cant figure out how to put 000s between the info.

Thx for all help so far!

So far i have done this. So now i just need some help to put in 000s between the words i write in the textfile.. not just infront(back)

Dim FILE_NAME As String = "C:\test.txt"
Dim i As Integer

Dim arytext(2) As String

arytext(1) = TextBox1.Lines(i)
arytext(0) = "30500001003379"

If System.IO.File.Exists(FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True) '


For i = 0 To 2

objWriter.Write(arytext(i)) '
Next


objWriter.Close()

Last edited by rpjeger; 01-31-2006 at 07:06 AM.
Reply With Quote
  #8  
Old 01-31-2006, 07:54 PM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Oh, so you are writing directly to the text file? Have you tried simply using .Write to write "000"s to the text file? You can say ....Write("000") to write 000s into the file before each call to write the arytext to the file.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #9  
Old 02-01-2006, 02:00 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Quote:
Originally Posted by Iceplug
Oh, so you are writing directly to the text file? Have you tried simply using .Write to write "000"s to the text file? You can say ....Write("000") to write 000s into the file before each call to write the arytext to the file.

Yeah writing directly cause idont know any other options But what you say there wont explain how to put the 0000s between the words in the textbox.

I might have a solution in my head for it... i could use a .xls file with the information. Load it into VB.. then i have a1: firstname a2: lastname a3:company etc. Then if i could just write the a1 then some 000s, then a2 and then some more 000s and all information goes to the same line and it starts in a new line if it goes to b1. Think this is a better solution ?
Reply With Quote
  #10  
Old 02-01-2006, 04:59 AM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I'm confused, unless there's this one thing...

If you write 000s to the file and close it so that your file has 000s between each word, then if you open the file to read from it, you should also read the zeros as well... right?

Or possibly, you want to put the zeroes in the textbox when you save the file?

If so, then clear the textbox text --> TextBox.Text = ""
and then, after every time you call
objWriter.Write(stuff), just call
TextBox.AppendText(stuff) immediately afterward
so that what you write to the textfile will be exactly what you see in the textbox.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #11  
Old 02-01-2006, 08:56 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Quote:
Originally Posted by Iceplug
I'm confused, unless there's this one thing...

If you write 000s to the file and close it so that your file has 000s between each word, then if you open the file to read from it, you should also read the zeros as well... right?

Or possibly, you want to put the zeroes in the textbox when you save the file?

If so, then clear the textbox text --> TextBox.Text = ""
and then, after every time you call
objWriter.Write(stuff), just call
TextBox.AppendText(stuff) immediately afterward
so that what you write to the textfile will be exactly what you see in the textbox.


hmm... i guess ididnt explain myself very well. sorry. But what i want to do is getting automaticly the right number of zeroes when i push a button..

Ok, i have no problem writing to a .txt from a textbox. But the question is how to get in the right number of zeroes between the words i write in the textbox.

Image you have a list of information about people... firstname, lastname etc.
This you open in the textbox, so that you get the names like this:

Roger Rabbit
John Travolta
etc.

Then i want to just hit a button and then it writes to a .txt file, but it also puts in zeroes infront,between and back of the information. so it looks like this in the .txt file.

0000001Roger0000000000Rabbit0000000000
0000002John000000000Travolta000000000

the zeroes is read by another program, i dont know the name of that program. Before I just used to put in the names in the right order between the zeroes. But image the time i spend doing this when the list has over 400 names... so i tought i should try to make a program that did this automaticly..
Thank you for the time you have used trying to explain this to a n00b in vb
Reply With Quote
  #12  
Old 02-01-2006, 09:01 PM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I don't know how many zeros you want to put in between the words ... I figured you knew that...
You have 6 zeroes and a 1 or 2, a name, 10 zeroes, a last name, and 10 more zeroes.

If you're trying to put in a number that is formatted to have a certain number of leading zeroes, then use .ToString()

Number.ToString("0000000") <-- 7 digit number, with 0s at front if necessary.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #13  
Old 02-02-2006, 01:57 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Quote:
Originally Posted by Iceplug
I don't know how many zeros you want to put in between the words ... I figured you knew that...
You have 6 zeroes and a 1 or 2, a name, 10 zeroes, a last name, and 10 more zeroes.

If you're trying to put in a number that is formatted to have a certain number of leading zeroes, then use .ToString()

Number.ToString("0000000") <-- 7 digit number, with 0s at front if necessary.

I give you an example from the .txt file i used before. This is how the program i dont know the name of reads.

30500001003379*********0800000000987703010000000***0000000000000000000 000000000000000000000000000000000000000000ACHMED MOHAMED ***** Ulrikkes vei ** * OSLO

This is written on one single line. The *** are just some information i put in. Theres name and address... all the other numbers around here is used by the program i dont know the name of. The spaces also needs to be the right number, i know the right numbers to put in where, but what i dont know is how to put the numbers in automaticly between the information i have in the textbox. So if u read the first line 30500001003379, then i have the ****
wich are some personal info that i have written in the textbox.

So the first thing i need to know is how to put the "zeroes" in the .txt with the ****** information i have in the textbox. So i have in the example above in my textbox: personalid: **** , then something more ****, Achmed Mohamed, then ***' address... the personal info is in my textbox! Then i would like to push a button and then the other numbers and spaces goes infront,between and back of the information. In front, and back of i think i can manage to do, but i can figure out how to get it between the personal info. So the first question is how to automaticly put "text/info/numbers" Between a text from the textbox: ex. Roger Rabbit it says in the textbox, push button,stores info to a .txt with the following Roger000000Rabbit. Im sure i will come to more problems along in the coding but first i need to know how to put a info between the text as ex. above...
Hope this explanation was better
Reply With Quote
  #14  
Old 02-02-2006, 11:34 AM
dienerk dienerk is offline
Centurion
 
Join Date: Feb 2005
Location: Miami Florida
Posts: 102
Default

From one beginner to another, why don't you use & "00000000"
__________________
I will procrastinate tomorrow, I just don't feel like doing it today.
Reply With Quote
  #15  
Old 02-02-2006, 01:52 PM
W_Garabrandt W_Garabrandt is offline
Centurion
 
Join Date: Mar 2004
Location: Altoona, PA USA
Posts: 139
Question

I read through this entire thread, and got confused about a couple things:
1) are you generating this data yourself?
2) do you know what the data is supposed to look like?
3) do you know what all the numbers mean?

I might be able to help you if I can just get some more information...
__________________

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. - Stephen Hawking
Reply With Quote
  #16  
Old 02-03-2006, 03:46 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Quote:
Originally Posted by W_Garabrandt
I read through this entire thread, and got confused about a couple things:
1) are you generating this data yourself?
2) do you know what the data is supposed to look like?
3) do you know what all the numbers mean?

I might be able to help you if I can just get some more information...

1) yes generating this data myself. I have a list witch contains the data.
2) yes i know how the data is supposed to look like... I have a .txt file that shows all info about how the numbers is sat up. So before i just used the .txt with the numbers and put in other data between the numbers in the right order. That takes a lot of time, so i wanted to make this program to do it automaticly... if u see what i have written above, u see some of how the data should look like.

3) well.. no. But i know its used to by another program(witch i dont know the name of) to read the data.
Reply With Quote
  #17  
Old 02-03-2006, 07:13 AM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

It is starting to sound like you are throwing a random file format at us and nobody knows the format. You have to know 'exactly' what everything should look like for it to be accepted.

So, if I give you a personalid (101), name (Iceplug), and address(Falkland Islands) what would the file look like exactly? (including the correct number of zeroes and general number)

We also need to know how many zeroes you want to put in the file. I have yet to see an actual number of zeroes required or any criteria to use that determines how many zeroes to use.

Of course, if you don't know the format, then we cannot guarantee that anything that we suggest will work or even look right.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #18  
Old 02-03-2006, 10:17 AM
W_Garabrandt W_Garabrandt is offline
Centurion
 
Join Date: Mar 2004
Location: Altoona, PA USA
Posts: 139
Default

Quote:
Originally Posted by rpjeger
1) yes generating this data myself. I have a list witch contains the data.
I didn't mean generating the names/addresses, i meant generating the seemingly random numbers.

Quote:
2) yes i know how the data is supposed to look like... I have a .txt file that shows all info about how the numbers is sat up. So before i just used the .txt with the numbers and put in other data between the numbers in the right order. That takes a lot of time, so i wanted to make this program to do it automaticly... if u see what i have written above, u see some of how the data should look like.
You are copying the info verbatim? Just make your program do the same. Have it parse at any number or letter to seperate the fields.

Quote:
3) well.. no. But i know its used to by another program(witch i dont know the name of) to read the data.
Well, helping you build an unknown file format is like teaching you to speak an unknown language...it can't be done.
If you have any more info for us (like what the format is, or how it's being used..), we might be able to help then. Also, the headder of the file (before data begins) or the ending (after data) might give us clue as to wrether the numbers are encrypted data, and how to encrypt/decrypt it...
__________________

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. - Stephen Hawking
Reply With Quote
  #19  
Old 02-08-2006, 03:08 AM
rpjeger rpjeger is offline
Newcomer
 
Join Date: Jan 2006
Posts: 12
Default

Heres how the .txt file i use looks like, this is how the program i dont know the fileformat or name of reads. I just know it reads like this. Sorry im very n00b in vb but thx for all help.


The topheader starts:
Code:
30100001003379saldo-rente opplysninger recordlengde 300                                             ******************* i Norge   Youngsgt. 11                  OSLO                          23061050****** Simensen               230616782002
** = personal info This is exactly how the header is,all this info is in one line,the amount of spaces most also be there. Then we take the line under the header.
Code:
30500001003379***********000000009877030100000001860000000000000000000000000000000000000000000000000000000000000*******                       *******                                                     ***** Ulrikkes vei 12 C       OSLO
The first 11 * in the line above is personal ID, then 9877 is the employed number, 0301 is the district/city they live in. 186 is amount of loans they have in the company. Then the next * is the firstname and the lastname, then the address.

The end of the file looks like this:
Code:
3080000100337000000000000003000000000242862000000000000000000000000000000000000000000000000000000000000000000008003353000000000000000                                                                                                                                                                     .
The . at the end just marks where the spaces ends.
So for me it looks like 301 is telling the program idont know the name of to start from here. The 305 looks like its telling the program "this is a new line of info" and the 308 is "this is the end of the file"
the rest 00001003379 i dont know what is, maybe the company id or something?

Hope this explains a bit how or what the format of the file could be.
Reply With Quote
  #20  
Old 02-08-2006, 05:53 PM
Iceplug's Avatar
IceplugManipulate text documents Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Based on your description, you have:
30500001003379***********00000000____####0000000$$$0000000000000000000 000000000000000000000000000000000000000000******* ******* ***** Ulrikkes vei 12 C OSLO

I don't quite understand the firstname, lastname, and address placement, but from here, it looks possible to do a String.Format:
(The 11G, 4G, and 3G may need modifying, but that might be one step closer to a solution to our mystery question of the unknown format.)

30500001003379{0:11G}00000000{1:4G}{2:4G0000000{3:3G}00000000000000000 00 000000000000000000000000000000000000000000******* ******* ***** Ulrikkes vei 12 C OSLO
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Manipulate text documents
Manipulate text documents
Manipulate text documents Manipulate text documents
Manipulate text documents
Manipulate text documents
Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents Manipulate text documents
Manipulate text documents
Manipulate text documents
 
Manipulate text documents
Manipulate text documents
 
-->