JasonAsh
asked on
Accessing .ini files from Visual BAsic 6.0
In Visual Basic 6.0
I have a form, a string varibale and a button.
When I click the button I want to look in a ini file that is on my C drive.
C:\Tickets.ini
and inside the Tickets.ini file I have
[Net_Location]
Location = K:\Tickets\Jobs
I want to put K:\Tickets\Jobs into my string variable.
How can I access the ini file in VB 6.0 and put K:\Tickets\Jobs into My_Variable.
Thanks,
Jason.
I have a form, a string varibale and a button.
When I click the button I want to look in a ini file that is on my C drive.
C:\Tickets.ini
and inside the Tickets.ini file I have
[Net_Location]
Location = K:\Tickets\Jobs
I want to put K:\Tickets\Jobs into my string variable.
How can I access the ini file in VB 6.0 and put K:\Tickets\Jobs into My_Variable.
Thanks,
Jason.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah, sorry about that, that works if you put the function in a module (which I always do with my functions).
If you want to use it straight on your form itself (in other words, the object module the error blabbers about), you need to make it a Private function instead of a Public one, so you get
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal SectionName As String, ByVal KeyName As String, ByVal Default As String, ByVal ReturnedString As String, ByVal StringSize As Long, ByVal FileName As String) As Long
If you want to use it straight on your form itself (in other words, the object module the error blabbers about), you need to make it a Private function instead of a Public one, so you get
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Make sure that you put this in a MODULE
not in a form
not in a form
ASKER
Sorry Guys I am getting my knickers in a right twist over this one !
If I put either of the codes into a module do I call the module from my button command ?
So for example I want the string from the ini file to go into text1.text
I put all the code above into a Module then under my button command I
have a call then have text1.text = my_variable or getsetting ?
If I put either of the codes into a module do I call the module from my button command ?
So for example I want the string from the ini file to go into text1.text
I put all the code above into a Module then under my button command I
have a call then have text1.text = my_variable or getsetting ?
You have to put the function in a module, once it's there your forms will automaticly be able to use whatever is in it.
ASKER
Thank you both I have sussed out from your tips and got it working.
ASKER
I have copied onto my form:
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA"
and I get the following error::
Compile error:
Constants, fixed-length strings, arrays, user-defined types and Declare
statements not allowed as Public members of object modules.
Any Ideas ?