Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA - extracting parameters from an ini file. 1

Status
Not open for further replies.

vegasrockstar

Programmer
Sep 25, 2006
12
GB
Hi

I have an ini file that I am reading to get parameters for my VBA macro. For set length values I have no problem using the code below to extract the string from the ini file. However, if I want to extract a file path that may have different lengths I do not know how to handle that. Any ideas you very smart people?

Public sFileContents As String
Public strExample As String
Public point As Integer

point = 0
point = InStr(sFileContents, "Example=")
If point > 0 Then
strExample = Mid(sFileContents, (point + 8), 4)
Else
GoTo ErrHandle
End If


Many thanks in advance ;)
 
I know that people will suggest using a different method to access the data in the ini file - I'm not proud - as long as I find a method that works i am happy! Just tell me what it is! (-:
 



Hi,

Check out the Split function
Code:
dim a
a = split(sFileContents, "=")
msgbox trim(a(0)) & " is the parameter"
msgbox trim(a(1)) & " is the value"


Skip,

[glasses] [red][/red]
[tongue]
 
Hi Skip,

Thanks for that. It would probably work but I don't have 'split' available in my object library. I have tried adding Excel 9.0 object library (the only Excel library available on this server) but it still does not compile.

Also, this looks OK if I have only 1 parameter but I have many. The sFileContenets contains all the text from the file and so would not be able to discriminate where one value ended and one parameter started, surely?

For example:
Name=Fred
Age=32

Would return:
Name is the parameter
FredAge is the value

Or am I barking up the wrong tree? (or just barking!) :)
 

A very recent thread in VB6, but I think would work 4 u
writing and reading to text file thread222-1279342
 
That looks like it should do the trick. I shall give it a go.

Many thanks Jerry!
 


BTW, Split is not part of the Excel Object model. It is a VB function.

Skip,

[glasses] [red][/red]
[tongue]
 
Split is a VBA function since office2000.
Any chance you could post your actual code reading the INI file ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the interest guys but I have moved on from the SPLIT idea and have used the resolution from thread222-1279342 to great effect. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top