Get Database Path from path stored in .txt file?

I have an access database and I have a .txt file that has the path stored in it.
The file is already in C:/Program Files/ThisOtherProgram/Config.txt and it contains this line;  4,Z:\DataPath\Data.mdb
This is the path that I would like my program to access the database with because depending on which computer you use the path may be different to my database.

How would I open this file, find "4, X:\ThePath\To\The\Database" and use that for my database connection location when my program loads?

Thanks for any code  or help you can provide
LVL 1
Matrix1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Hi Matrix1000,

Is the line with the database information:

    4,Z:\DataPath\Data.mdb

going to be the first line in the text file? ...or do we need to "find" it as you said by looking for the "4," as the beginning of the line?

~IM
0
Matrix1000Author Commented:
Right now it is the first line in the file but potentially there could be something else as the first line (like setting 1,2 and 3) So it might be good to look for the "4"
0
RonaldBiemansCommented:
something like this

Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:/Program Files/ThisOtherProgram/Config.txt")
        Dim line As String
        Dim path As String
        line = sr.ReadLine()
        Do While Not line Is Nothing

            If line.StartsWith("4,") Then
                path = line.Substring(2).Trim
            End If
            line = sr.ReadLine()
        Loop
        sr.Close()

path should now hold your database path
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Matrix1000Author Commented:
Thanks!   How would I use "path" in the connection string...

        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""C:/Program Files/ThisOtherProgram/Data.mdb" & _
        "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

Changed to....

        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""(Path)" & _
        "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

Doesn't work...I did "Private path as String" but it doesn't like the (path) arguement in the statement
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.