(newbie - VB2005) writing to file

O

Opa Vito

Hello,

I give up .... probably I'm too stupid to understand but I cannot figure
out how to write a string to a certain place in a file.

This is what I like to do:
Somewhere in a file is a section called '[settings]', every time the
application is opened there is a veryfication to see when it was the
last date/time it was running, by reading the very first line under
'[settings]', and if the date is responding to other settings in the
program, the program will run otherwise it stays closed. If it may run,
the new rundate is written to the same place.
That's what I intend to do.
But I cannot find out how to write to that specific location. This
location can be anywhere in the file, but always under the section name.

Sorry, but I cannot explain this better, I'm not English ... I hope you
guys (and girls) can undestand what I like to do. After 2 whole days of
trying I give up :)

Many thanks in advance.

Opa Vito
 
O

Opa Vito

Cor Ligthert [MVP] schreef:
Stop calling yourself Opa and excusing you for your English, you have a
middle finger for if somebody tells you that it is not good.

OK, no problem.
But I'm a granddad, in Flemish and Dutch: an 'opa' :)

Yes, you are right, I had several American and Canadian penpals and my
English was even better than their's ...
Why do you not use the registry (register in Dutch), it is easy to use in
VB.Net so in my idea the direct solution?

No, I don't want to use registry at the moment. But I made a study and
if there is no way to do it with a file I will use reading and writing
from and to the registry. To me it must be possible to write a function
that looks first to a certain keyword in a file (like [settings]) and
write data to that place ...

All tips are very welcome.

Vito
 
G

GhostInAK

Hello Opa,

The only problem with trying to write data to the middle of a file is there
is no Insert of Delete mode. So you either have to guarantee that the data
you are writing is the EXACT length of the previous data (not shorter and
not longer), or you have to read the whole file in and replace the part you
dont like any more.

-Boo
Cor Ligthert [MVP] schreef:
Stop calling yourself Opa and excusing you for your English, you have
a middle finger for if somebody tells you that it is not good.
OK, no problem.
But I'm a granddad, in Flemish and Dutch: an 'opa' :)
Yes, you are right, I had several American and Canadian penpals and my
English was even better than their's ...
Why do you not use the registry (register in Dutch), it is easy to
use in VB.Net so in my idea the direct solution?
No, I don't want to use registry at the moment. But I made a study and
if there is no way to do it with a file I will use reading and writing
from and to the registry. To me it must be possible to write a
function that looks first to a certain keyword in a file (like
[settings]) and write data to that place ...

All tips are very welcome.

Vito
 
C

Cor Ligthert [MVP]

Vito,

Just an XML file, the most easy one in that is a dataset.

\\\
dim ds as new dataset
dim dt as new datatable
dim dc1 as datacolumn("een")
dim dc2 as datacolumn("twee")
etc
ds.tables.Add(dt)
dt.columns.Add(dc1)
dt.columns.Add(dc2)
dt.loaddatarow(new object() {"Vlaams","Nederlands"},true)
dt.loaddatarow(new object() {"Waals",French"},true)
dt.rows(2)("twee")="Frans"
ds.writeXML("C:\whatever\whatever")
///
and to read it
\\\
ds.readXML("C:\whatever\whatever")
///
I wrote this in this message so watch typos or whatever.

I hope this helps,

Cor

Opa Vito said:
Cor Ligthert [MVP] schreef:
Stop calling yourself Opa and excusing you for your English, you have a
middle finger for if somebody tells you that it is not good.

OK, no problem.
But I'm a granddad, in Flemish and Dutch: an 'opa' :)

Yes, you are right, I had several American and Canadian penpals and my
English was even better than their's ...
Why do you not use the registry (register in Dutch), it is easy to use in
VB.Net so in my idea the direct solution?

No, I don't want to use registry at the moment. But I made a study and if
there is no way to do it with a file I will use reading and writing from
and to the registry. To me it must be possible to write a function that
looks first to a certain keyword in a file (like [settings]) and write
data to that place ...

All tips are very welcome.

Vito
 
O

Opa Vito

Cor, I understand now I made a mistake by using an old fashioned sort of
ini file with my program, XML would have been better. I will now use XML
for the small 'settings' I need to write, maybe that way I also can
understand XML and re-write my other files to this kind of data storage.
Thanks for the code.

Cor Ligthert [MVP] schreef:
 
O

Opa Vito

Cor Ligthert [MVP] schreef:
Vito,

Just an XML file, the most easy one in that is a dataset.
<snip>

Small question:
do I have to use DataView to assign a field to a string, as for
retrieving a name from <name>Lisette</name> ?
It's rather confusing ...

Vito
 
O

Opa Vito

Opa Vito schreef:
Small question:
do I have to use DataView to assign a field to a string, as for
retrieving a name from <name>Lisette</name> ?
It's rather confusing ...

I found it :)
Took me almost the whole day but I can read now from a dataset that is
filled with data from an XML file ... next: writing to the xml file.

Vito
 
C

Cor Ligthert [MVP]

Vito,

See my answer, although there is a typo in it.
dt.rows(2)("twee")="Frans"
should be
dt.rows(1)("twee)="Frans"

The writing is as well in that sample.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top