|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi,
I wanna generate a report of a text file in vb. I am attaching my text file with this. My text file is of Tab delimited. I can even use a Comma Delimiter also. So please help me in generating a report in a very good format, that may be for a Tab de limited or comma Delimited. Thanks in advance, bye |
|
#2
|
||||
|
||||
|
what format do you want to report to be in?
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
hi,
Thanks for your reply, I am trying for a report that has columns and each column is seperated by vertical line. And also if possible each row is also seperated by a horizontal line. If You have so idea plz let me know that. I am in urgent, as the dead line has approached, so please help me. Thanks, bye |
|
#4
|
|||
|
|||
|
U can open this file with excel!Try it!If u will generate a report,u can use vba or vb with office reference!.
|
|
#5
|
||||
|
||||
|
There are two main ways to input text. One is to read the information in one line at a time into a variable, and then split that variable into arrays using the split() function and the appropriate variable. This is the best way to do it if you have variable length lines. If you know that each record in your text file will have the same format, with all fields in the same order, then you can read the line into specific variables. Here are both methods displayed, and you can pick which one suits you best.
Code:
Private Sub Form_Load()
Dim strLine As String
Dim strArray() As String
Dim i As Integer
Dim Var1 As String, Var2 As String, Var3 As String, Var4 As String
Open App.Path & "\MyText.txt" For Input As #1
Do Until EOF(1)
strLine = input(LOF(1), #1)
Loop
Close #1
strArray = Split(strLine, ",")
For i = 0 To UBound(strArray)
MsgBox strArray(i)
Next i
Open App.Path & "\MyText.txt" For Input As #2
Do Until EOF(2)
Input #2, Var1, Var2, Var3, Var4
Loop
MsgBox Var1 & " " & Var2 & " " & Var3 & " " & Var4
End Sub
|
|
#6
|
||||
|
||||
|
To follow that up, once you have the variables into an array in memory, you can write them to any type of file you want.
|
|
#7
|
|||
|
|||
|
hi,
thanks for the help u r doing to me. I did all the job of reading a file using the second type of method u mentioned in ur last reply. That is my text file has the fixed format records, so i read them into different variables and I got that. But now the problem I facing is, The text file I have generated using the print #1, var1, var2... is a tab delimited text file. But that text file, eventhough it is tab delimited, so some fields are of less length and some are ofgreater lenghts, they are not appearing in the actual columns they have to be in, eventhough they are seperated by the tab space. So I was asked to generate a printable format of that text file, which should look good, like each column seperated by a line and (ach row seperated by a line if possible). So please look over this, and help me in generating a printable format of the file. since i have to give an option of printing the text file that is of a very good allignment, like all the respective data should be printed exactly under their respective columns. That is like, if we have three columns in the text file, and three rows under it should look like, as shown below. LastName FirstName Age abc xyz 22 def ghi 21 jkl mno 25 and so on.. with the lastname seperated with a vertical line from the FirstName and FirstName seperated by a vertical line from Age and their respective rows should also fall under those column headers only... Please reply me if u have any doubt my specification... Thanking you, bye |
|
#8
|
|||
|
|||
|
hi,
in the past mail, i gave the format there abc is the lastname. xyz is the first name and 22 is the age. That abc should be preinted exactly under the lastname and xyz should be printed exaclty under the firstname and 22 should be preinted exactly under age. In that way all the rows how many it be, all should be printed in a exact format... ok bye |
|
#9
|
||||
|
||||
|
OK - so you have to variables in memory, and now the problem is that you need to print them out to a file in the format that you specified, with even spacings between the columns? This is not as hard as you might think, but you need to do something first. You need to come up with a print-spacing chart that will designate the column width of each column in the report. This needs to be wide enough to accomodate your data (wide enough to handle the longest string you might have in a field). Usually, generalizations are made and any data that might be longer than your assumed length is truncated. Therefore, you might come up with your assumed print spacings like this.
FirstName=Spaces 1-20 buffer=Spaces 21-23 LastName=Spaces 24-44 buffer=spaces 45-47 ZipCode=Spaces 48-59 buffer=spaces 60-62 and so on.. let me know what you come up with, and I'll try to show you how to use it. |
|
#10
|
|||
|
|||
|
hi
hi,
Thanks for ur reply. Here I am going to printout the data of a file to a paper. So I am worrying about " if the row length is greater than the size of the A4 or A3 size paper then what to do. And also i should print that out with even spacing, i think u got it. Thanks, bye |
|
#11
|
||||
|
||||
|
just out of curiosity, is there any way that you can use excel to help you on that? I'm working on the problem right now, but I'm a little confused. You have to read data in from one file, and then place it in another file in the exact same format?
|
|
#12
|
|||
|
|||
|
hi
hi,
yah i am going to print my input .doc file to another .doc file. Such way that all the data is displyed in a tabular form. So that even if a field is of larger length, that can adjusted in the same cell itself in that table. That is I got this worked when I directly used the table option from the word. I selected all the rows in my MS word file and in that I took the table option and in that convert + Text to Table then i got it exactly what I want, But the problem is I have to print that format from the vb code itself. If I am not clear, then please open a microsoft word file and then type some words that are seperated by commas and then select the entire line and then go to Table options menu and in that, then go to the Conver Option and then select the Text to Table option, then u can get all the data that has been comma delimited into the tables. In that you can see that if a feild in the row is of larger lenth than the size of that field, then it is adjusted in that cell itself by enlarging the cell size by itself automatically. I think I am clear now. To be frank, I donno much vb programming. I think U understood my problem. i am expecting help from u. I hope u would help me as early as possible, Thanking You, Bye |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > how to generate a report of a text file in vb |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|