reading in a file

  • Thread starter Thread starter lizii
  • Start date Start date
L

lizii

i have a file - which on each line has some data i need to fill into a
box - now although reading in the data is simple enough and putting it
in the correct box will be no problem, as i can just read a lilne then
put into the corresponding box...it just seems like a task i should be
able to complete in a few lines...rather than quite a few commands.

for example what i do at the moment is:

read a line
place into first text box
read a line
place into second text box
etc...

is there an smaller version of this? I am kind of feeling there should
be something like:

while there are more lines:
read a line
place into corresponding text box.

any ideas on what i should do?


Thanks in advance!
 
Hi lizii,

lizii said:
i have a file - which on each line has some data i need to fill into a
box - now although reading in the data is simple enough and putting it
in the correct box will be no problem, as i can just read a lilne then
put into the corresponding box...it just seems like a task i should be
able to complete in a few lines...rather than quite a few commands.

for example what i do at the moment is:

read a line
place into first text box
read a line
place into second text box
etc...

is there an smaller version of this? I am kind of feeling there should
be something like:

while there are more lines:
read a line
place into corresponding text box.

Can you specify an algorithm for "corresponding text box"? If you can you
have your solution.

If you e.g. access your text boxes by a resource ID with good old Win32 you
might want to create an array or vector of IDs where you move forward
whenever you have read a line:

int controlID[] = { ID_TEXT_1, ID_TEXT_2, ID_TEXT_3 };
int i = 0;

for(int i = 0; i < 3; ++i)
{
// read your line
SetDlgItemText(hwnd, controlID, <your read line as char array>);
}

As you can see above you somehow have to ensure that the number of text
boxes and the number of read lines matches.
 
Hi SvenC,
Can you specify an algorithm for "corresponding text box"? If you can you
have your solution.

is exactly what i am sticking at - you are saying something about
ResourceID - that sounds like a perfect solution :)

i was thinking for each textbox - add a tag and somehow using unique
tags (eg TEXT_1) i could use that to refer to which textbox i want -
then for each line i read in add to corresponding textbox. If thats
possible that would solve my problem and make far less lines of code!

I know that only i will be changing the order of the text file and for
any textboxes which end up being more than one line i would add markers
like [start], [end]. Just that knowing that the third line (or that
block) i am reading in would be corresponding to the third textbox.

Will my idea about tags work?

thanks again - get step by step closer to figuring this bit out :)


Hi lizii,

lizii said:
i have a file - which on each line has some data i need to fill into a
box - now although reading in the data is simple enough and putting it
in the correct box will be no problem, as i can just read a lilne then
put into the corresponding box...it just seems like a task i should be
able to complete in a few lines...rather than quite a few commands.

for example what i do at the moment is:

read a line
place into first text box
read a line
place into second text box
etc...

is there an smaller version of this? I am kind of feeling there should
be something like:

while there are more lines:
read a line
place into corresponding text box.

Can you specify an algorithm for "corresponding text box"? If you can you
have your solution.

If you e.g. access your text boxes by a resource ID with good old Win32 you
might want to create an array or vector of IDs where you move forward
whenever you have read a line:

int controlID[] = { ID_TEXT_1, ID_TEXT_2, ID_TEXT_3 };
int i = 0;

for(int i = 0; i < 3; ++i)
{
// read your line
SetDlgItemText(hwnd, controlID, <your read line as char array>);
}

As you can see above you somehow have to ensure that the number of text
boxes and the number of read lines matches.

--
SvenC
any ideas on what i should do?


Thanks in advance!
 
Hi lizii,

lizii said:
Hi SvenC,


is exactly what i am sticking at - you are saying something about
ResourceID - that sounds like a perfect solution :)

i was thinking for each textbox - add a tag and somehow using unique
tags (eg TEXT_1) i could use that to refer to which textbox i want -
then for each line i read in add to corresponding textbox. If thats
possible that would solve my problem and make far less lines of code!

Tags sound like you use .Net controls? So you can enumerate the Controls
collection of the form your text boxes live in and use the Tags field to
find specific text boxes.
The more controls your form has the longer the search for your control with
a given tag might take. If that starts to get a performance problem, you
might consider to iterate the controls collection ones and store the
relevant text boxes in a Dictionary with your tag as key.

--
SvenC
I know that only i will be changing the order of the text file and for
any textboxes which end up being more than one line i would add markers
like [start], [end]. Just that knowing that the third line (or that
block) i am reading in would be corresponding to the third textbox.

Will my idea about tags work?

thanks again - get step by step closer to figuring this bit out :)


Hi lizii,

lizii said:
i have a file - which on each line has some data i need to fill into a
box - now although reading in the data is simple enough and putting it
in the correct box will be no problem, as i can just read a lilne then
put into the corresponding box...it just seems like a task i should be
able to complete in a few lines...rather than quite a few commands.

for example what i do at the moment is:

read a line
place into first text box
read a line
place into second text box
etc...

is there an smaller version of this? I am kind of feeling there should
be something like:

while there are more lines:
read a line
place into corresponding text box.

Can you specify an algorithm for "corresponding text box"? If you can you
have your solution.

If you e.g. access your text boxes by a resource ID with good old Win32
you
might want to create an array or vector of IDs where you move forward
whenever you have read a line:

int controlID[] = { ID_TEXT_1, ID_TEXT_2, ID_TEXT_3 };
int i = 0;

for(int i = 0; i < 3; ++i)
{
// read your line
SetDlgItemText(hwnd, controlID, <your read line as char array>);
}

As you can see above you somehow have to ensure that the number of text
boxes and the number of read lines matches.

--
SvenC
any ideas on what i should do?


Thanks in advance!

 
Back
Top