Solved

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

Posted on 2004-09-06
6
365 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 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