|
-
Feb 24th, 2000, 11:25 PM
#1
Thread Starter
New Member
Whats the comand to read an INI file?
Whats the command to write to INI file?
Thanks for you help.
-
Feb 24th, 2000, 11:44 PM
#2
Junior Member
Add the MS Scripting Runtime component
Here's the code to open the file and then write a line of code to the bottom of it.
Option Explicit
Dim oFso As New FileSystemObject
Dim oFile As TextStream
Private Sub Form_Load()
oFso.OpenTextFile ("C:\your file.INI"), ForReading ' open the ini file
oFile.ReadAll ' read all the ini file
oFile.Close
End Sub
Sub Addline()
oFso.OpenTextFile ("C:\your file.ini"), ForAppending
oFile.WriteLine ("C:\your new line here")
oFile.Close
End Sub
-
Feb 25th, 2000, 12:59 AM
#3
New Member
That method will work, but the much easier method is to use the following API's:
** Getting Private ini (your application ini)
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public 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
**Writing your private ini
Public Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Public 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
** getting public ini (win.ini file)
Public Declare Function GetProfileInt Lib "kernel32" Alias "GetProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Long) As Long
Public Declare Function GetProfileSection Lib "kernel32" Alias "GetProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Public Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
** writing public ini (win.ini
Public Declare Function WriteProfileSection Lib "kernel32" Alias "WriteProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String) As Long
Public Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
-
Feb 25th, 2000, 07:22 AM
#4
Lively Member
In my app, I used some of the source from VBWorld, and some of my own to make it easier on myself... here it is...
Public Function IniString(Heading As String, Key As String, file As String) As String
Dim ret As Long
Dim Temp As String * 50
ret = GetPrivateProfileString(Heading, Key, App.Path & "\" & file, Temp, Len(Temp), App.Path & "\" & file)
If ret = 0 Then
Beep
Else
IniString = Trim(Temp)
End If
End Function
-------
So, for an example, say you wanted what data was in the .ini file wowyzowy.ini under section Wow and string Zowy.
Dim Value as string
Value = Inistring("Wow", "Zowy", "wowyzowy.ini")
MsgBox Value
----
This would popup a message box with the value in that. Here's how wowyzowy.ini should be structured:
[Wowy]
Zowy=Boo!
So, the code above would display a message box saying Boo!. Hehe... k... Thats to read, to write simply do the same thing, but with an added value peramiter...
Public Sub StoreIni(Heading As String, Key As String, Value, file As String)
Dim ret As Long
ret = WritePrivateProfileString(Heading, Key, Value, App.Path & "\" & file)
If ret = 0 Then
Beep
End If
End Sub
This would work the same way, just use something like...
StoreIni "Wowy", "Zowyzoo", "You're not all that and a bag of potato chips", "wowyzowy.ini"
And the ini file would now look like....
[Wowy]
Zowyzoo=You're not all that and a bag of potato chips
Ok, hope i helped you out! Oh yes, it will beep using the computers speaker if something is wrong.
-Xero
Edited by Xero on 02-25-2000 at 07:25 PM
-
Aug 25th, 2000, 02:15 AM
#5
Junior Member
Windows 2000
Hi,
I'm using the WriteProfileString api to set the default printer from code.
This works fine in WinNT but not in Windows 2000.
Does anyone know which api call I should use?
Thanks
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
|