Solved

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

Posted on 2004-09-06
6
361 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
Comment Utility
0
 
LVL 18

Expert Comment

by:JR2003
Comment Utility
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
Comment Utility
That won't work with eVB 3.0 !
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Expert Comment

by:imarshad
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

16 Experts available now in Live!

Get 1:1 Help Now