By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,083 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,083 IT Pros & Developers. It's quick & easy.

reading in a file

P: n/a
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!

Sep 29 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi lizii,

"lizii" <cr*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>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[i], <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!

Sep 29 '06 #2

P: n/a
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 :)

SvenC wrote:
Hi lizii,

"lizii" <cr*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
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[i], <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!
Sep 29 '06 #3

P: n/a
Hi lizii,

"lizii" <cr*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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!
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 :)

SvenC wrote:
>Hi lizii,

"lizii" <cr*****@gmail.comwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
>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[i], <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!

Sep 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.