Click here to Skip to main content
15,868,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a .txt file with data like following:

Student 1
name abc
age 12
section 123

Student 2
section 456
name xyz
age 13

Student 3
name dfg
age 12
section 456


My output file will be .xlsx file

student  name  age  section
student1 abc    12   123
student2 xyz    13   456
student3 dfg    12   456


I am processing this file so that details of each student comes in each row in excel.
How can I put a flag or something to differenciate between student 1 from student 2? The data between Student is constant but sequence are changed. That is not a problem. I am unable to find a way to mark flags between the individual student!!
Need some help!!

Thank you..!! :)

What I have tried:

I am unable to think of a way to change flag even if I use it.

Here is my code:
while not EOF()
   if instr(DataLine,"Student") > 0 then
      student_val=DataLine
      flag=true
   end if

   if flag=true then
      if instr(DataLine,"name") > 0 then
        name_val=rplace(DataLine,"name","")
      end if
   end if

wend


this gives values for first student. But when can I reset the flag to know that it is student2 in text file and start with new line in excel?
Posted
Updated 15-Sep-16 3:37am
v3
Comments
Patrice T 15-Sep-16 6:03am    
And you have code ?
What have you done ?
what result you want ?
MayurDighe 15-Sep-16 6:21am    
Use "Improve question" option to update your question properly. If you do code for same and stuck somewhere then show Where you have problems? What you do for it? What you want from us?
Patrice T 15-Sep-16 9:46am    
There is no way this code can process first student.
Show real code that: read input file, and fill the first line in Excel.
planetz 19-Sep-16 2:36am    
i was seeking help regarding logic...the problem is solved..i will update my proper running code...

1 solution

Well, the current student number should be a property of your parsing state machine. Each time the parser meets a 'Student <N>' line, it should change such property. The parsing of all the other lines uses the property to place the collected data into the proper excel row.
 
Share this answer
 
Comments
planetz 15-Sep-16 8:45am    
Will you please explain with a sample code. My code here goes for first student. But how can I move on to next one?
planetz 19-Sep-16 2:36am    
hey..thanks for your hint....!!
CPallini 19-Sep-16 3:06am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900