![]() |
#1
|
||||
|
||||
![]()
I have been using the FileSystemObject to write and read a simple text file I use to save settings for forms. Here is how I write the file.
Code:
Dim fs, objTextStream Set fs = CreateObject("Scripting.FileSystemObject") Set objTextStream = fs.CreateTextFile(GMSManager.GMSPath & "OBCNconfig.ini", True) 'Creates the Preference Text File objTextStream.WriteLine txtPath ' Adds Users Preference for Path to be searched objTextStream.WriteLine chkSearchSubDir 'Adds Users Preference for Searching SubFolders objTextStream.Close Code:
Dim fs, objTextStream Set fs = CreateObject("Scripting.FileSystemObject") Set objTextStream = fs.OpenTextFile(GMSManager.GMSPath & "OBCNconfig.ini", 1, False) txtPath.Value = objTextStream.Readline chkSearchSubDir = objTextStream.Readline objTextStream.Close Shelby |
#2
|
||||
|
||||
![]()
Shelby,
I personally prefer the native VBA file functions simply because it is not dependent on the presence of the FileSystemObject library on the target machine. Here is how you open a file and write some text to it: Code:
Open "C:\File.txt" For Output As #1 Print #1, "Some text for line1" Print #1, "Some text for line2" Close #1 Code:
Dim sLine As String Open "C:\File.txt" For Input As #1 While Not EOF(1) Line Input #1, sLine ' Do something with the read line Wend Close #1 I also frequently use Windows API to read settings from INI files. This way I don't have to write any text parsers or anything to extract the data from the INI files myself. Here are the functions I use for this: 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 Public Function GetConfigData(ByVal strSection As String, ByVal strKey As String, ByVal strDefValue As String, ByVal strINIFile As String) As String Dim n As Long Dim strVal As String strVal = Space$(260) n = GetPrivateProfileString(strSection, strKey, strDefValue, strVal, Len(strVal), strINIFile) GetConfigData = Left$(strVal, n) End Function Public Sub SetConfigData(ByVal strSection As String, ByVal strKey As String, ByVal strValue As String, ByVal strINIFile As String) WritePrivateProfileString strSection, strKey, strValue, strINIFile End Sub |
#3
|
|||
|
|||
![]()
Is there a similar way to do the same thing for xml config files?
Specifically I think it could be useful to be able to change the Pansose Preferences from within a Function/Sub... These preferences are surprisingly enough stored here... C:\Documents and Settings\~\Application Data\Corel\Graphics13\User Draw\PanosePreferences.xm Best, Lukel |
#4
|
|||
|
|||
![]()
Found this via Search...
http://forum.oberonplace.com/showthr...ghlight=Panose However this still seems to be overridden by the settings in the PanosePreferences.xml file. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Finding a File in Sub Folders | shelbym | CorelDRAW/Corel DESIGNER VBA | 10 | 10-05-2004 08:02 |