Solved

How to Read/Write to a text file in eVB 3.0

Posted on 2004-09-06
6
362 Views
Last Modified: 2008-02-01
I am trying to make my appliction use a "setup.ini" file so it can load users preferences etc...

PLEASE NOTE I AM USING eVB 3.0.

1) How do I create the file (with Default options) if it does not already exist or has been deleted ?
2) How do I read certain values from the file ?
3) How do I change/write certain values to the file ?

The format of the Setup file is just like a standard INI file:

[OPTIONS]
option1=test1
option2=test2
option3=test3

Thanks in advance...

 
0
Comment
Question by:marhk51
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 11988642
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11988648
The standard way to do this type of thing now is to use the GetSetting and SaveSetting functions to read and write to the registry instead of an ini file
0
 

Author Comment

by:marhk51
ID: 11989230
That won't work with eVB 3.0 !
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:imarshad
ID: 11989418
EVB 3.0 has a file control........You can use this control to open a text file and read its parameters (Line by Line) and then you can also write back to the file using the same control (I have used File Control for only reading but writing will not be that much difficult).......

Imran Arshad
0
 

Author Comment

by:marhk51
ID: 11989763
Thanks for that, but I need someone to write some code so that I can pick out certain lines from the INI file.
0
 
LVL 13

Accepted Solution

by:
imarshad earned 100 total points
ID: 11990486
This is a sample code from a book emBedded VB......You can read the sample chapter that deals with files reading and editing by visiting the following link.....It contains loads of source code some of which is shown below......

http://www.samspublishing.com/articles/article.asp?p=27220&seqNum=4

Public Function GetFileTextContents(Path As String) As String
    Dim filFile As FILECTLCtl.File
    Dim strInput As String

    On Error Resume Next

    ` Get our application File object
    Set filFile = GetFileObject()

    ` Open the File
    filFile.Open Path, fsModeInput, fsAccessRead

    ` Make sure the call to Open was successful
    If Err.Number <> 0 Then
        MsgBox "Open Method failed." & vbCrLf & _
            "The file could not be read.", _
            vbCritical, "Error"
    End If

    ` Loop through file, filling our input buffer
    Do While Not filFile.EOF
        strInput = strInput & filFile.Input(1)
    Loop

    ` Close the file
    filFile.Close

    ` Release the File Object
    Set filFile = Nothing

    ` Return the text
    GetFileTextContents = strInput
End Function

After using that function you can edit every line that you want to and then save it back to the File path ........
Hope this helps.....
Imran Arshad
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now