|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
(newbie - VB2005) writing to fileI 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 >From the brackets I assume you are you using an .INI file? If so check out http://vbnet.mvps.org/index.html?code/file/pprofilebasic.htmThanks, Seth Rowe Opa Vito wrote: Show quoteHide quote > 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 rowe_newsgroups schreef:
>>From the brackets I assume you are you using an .INI file? If so check It's not exactly an .ini file but as far as I can judge it at the moment > out http://vbnet.mvps.org/index.html?code/file/pprofilebasic.htm the given URL can help me with what I try to do. Many thanks Vito "rowe_newsgroups" <rowe_em***@yahoo.com> schrieb: Note that this sample has been written for VB6.> >From the brackets I assume you are you using an .INI file? If so check > out http://vbnet.mvps.org/index.html?code/file/pprofilebasic.htm -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Vito,
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. 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? http://msdn2.microsoft.com/en-us/library/microsoft.win32.registry.aspx Cor Show quoteHide quote "Opa Vito" <gebr***@dit.niet> schreef in bericht news:ObydnZ4MDIVDzoPYnZ2dnUVZ8qCdnZ2d@scarlet.biz... > 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 Cor Ligthert [MVP] schreef:
> Stop calling yourself Opa and excusing you for your English, you have a OK, no problem.> middle finger for if somebody tells you that it is not good. 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 ... > No, I don't want to use registry at the moment. But I made a study and > 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? 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 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 Show quoteHide quote > 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 > 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 Show quoteHide quote "Opa Vito" <gebr***@dit.niet> schreef in bericht news:n9OdnQNF4PQMib3YnZ2dnUVZ8qOdnZ2d@scarlet.biz... > 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 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: Show quoteHide quote > 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 Ligthert [MVP] schreef:
> Vito, <snip>> > Just an XML file, the most easy one in that is a dataset. 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 Opa Vito schreef:
> Small question: I found it :-)> 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 ... 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 Vito,
See my answer, although there is a typo in it. >dt.rows(2)("twee")="Frans" dt.rows(1)("twee)="Frans"should be The writing is as well in that sample. Cor Show quoteHide quote "Opa Vito" <gebr***@dit.niet> schreef in bericht news:FqadneM0c6EkGbzYRVnyvw@scarlet.biz... > 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 > > > > |
|||||||||||||||||||||||