|
-
Mar 11th, 2004, 07:47 AM
#1
Thread Starter
Hyperactive Member
Using .ini files
This is gonna sound dumb (no change there then) but it's something I've never done before so please be patient!
All I want to do is store a database path and a string variable (eg: strlettercode = "SL42") in an .ini file so I can alter it whenever I need to.
I'm guessing it's simple but then again, so am I!
Cheers
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Mar 11th, 2004, 08:17 AM
#2
Fanatic Member
This will show you how to do it.sorry no vb on this pc.
The Writeprofile code will save your data to the file.
The Getprofile retreives it from the file to say a texbox for you to either alter or just view it.
VB Code:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Dim Ret As String, NC As Long
'Write the setting to the file (c:\test.ini) under
' Project1 -> Keyname
WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
'Create a buffer
Ret = String(255, 0)
'Retrieve the string
NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
'NC is the number of characters copied to the buffer
If NC <> 0 Then Ret = Left$(Ret, NC)
'Show our string
MsgBox Ret
'Delete the file
Kill "c:\test.ini"
End
-
Mar 11th, 2004, 11:07 AM
#3
A more modern way is to use the Registry. Click the Use SaveSetting and GetSetting to store and retrieve data from the Registry link in my signature for an example.
-
Mar 11th, 2004, 05:57 PM
#4
Fanatic Member
1. Open notepad and create a file called value.ini
2.Save your project and the value.ini file to same directory
3.Add a textbox to your form and 2 x command buttons and when you add any value to the textbox it will save it in the inifile.
4. You will be able to open the file with command2 and view it
5. Copy code to form
Hope this is what you require
VB Code:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWMAXIMIZED = 3
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Command1_Click()
Dim Ret As String, NC As Long
'Write the setting to the file (c:\test.ini) under
' Project1 -> Keyname
WritePrivateProfileString "HEADING", "strlettercode", Text1.Text, App.Path & "\VALUE.INI"
'Create a buffer
End Sub
Private Sub Command2_Click()
ShellExecute Me.hwnd, vbNullString, "C:\VALUE.INI", vbNullString, "C:\", SW_SHOWMAXIMIZED
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|