-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi,
i created my first snippet using the new snippetcreator ... Oliver - -- GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEL9IUTiyrQM/QSkURAt/zAKCrGm+DVUYye8LWoVLpO54MEGWlIQCdFeOy eBD3+42PEihqwy3l0x+VT+k= =M72d -----END PGP SIGNATURE-----
<?xml version="1.0"?> <!-- $RCSfile: $ last change: $Revision: $ $Author: $ $Date: $ (c)2003 by the copyright holders listed with the author-tags. If no explicit copyright holder is mentioned with a certain author, the author him-/herself is the copyright holder. All rights reserved. Public Documentation License Notice: The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at http://www.openoffice.org/licenses/PDL.html The Original Documentation can be found in the CVS archives of openoffice.org at the place specified by RCSfile: in this header. The Initial Writer(s) of the Original Documentation are listed with the author-tags below. The Contributor(s) are listed with the author-tags below without the marker for being an initial author. All Rights Reserved. --> <snippet language="OOBasic" application="Office"> <keywords> <keyword>ini</keyword> <keyword>file</keyword> <keyword>fileaccess</keyword> <keyword>read</keyword> </keywords> <authors> </authors> <question heading="ReadIniFile">How to read an ini file using oo basic ? <p> </p> </question> <answer> <p>the macro will read an ini file into a multidimensional array ...</p> <p>to acces the entries within the sections use:</p> <p></p> <p> [DATA] mIni(0,0,0) -> [DATA]</p> <p> X=1 mIni(0,0,1) -> X / mIni(0,0,2) -> 1</p> <p> Y=2 mIni(0,1,1) -> Y / mIni(0,1,2) -> 2</p> <p> [HELP] mIni(1,0,0) -> [HELP]</p> <p> INFO=YES mIni(1,0,1) -> INFO / mIni(1,0,2) -> YES</p> <p></p> <listing>OPTION EXPLICIT Sub Main() Dim mIni() as String Dim sMsg as String Dim i as Integer Dim j as Integer mIni() = ReadIniFile("E:\temp\test.ini", "", 20, 50) For i = 0 To uBound(mIni()) sMsg = sMsg & mIni(i,0,0) & Chr(13) For j = 0 To 50 If mIni(i,j,1) <> "" Then sMsg = sMsg & mIni(i,j,1) & " = " & mIni(i,j,2) & Chr(13) EndIf Next j MsgBox sMsg sMsg = "" Next i End Sub Function ReadIniFile(ByVal sFile as String, ByVal sEncoding as String,_ ByVal nMaxSection as Integer, ByVal nMaxEntry as Integer) as Variant On Local Error Goto ErrorHandler Dim oFileAccess as Variant Dim oFile as Variant Dim oStream as Variant Dim mTmp() as String Dim sTmp as String Dim i as Long Dim j as Long Dim bFlag as Boolean Dim mArray(nMaxSection, nMaxEntry, 2) as String If sEncoding = "" Then sEncoding = "ISO-8859-1" EndIf oFileAccess = createUnoService("[EMAIL PROTECTED] com.sun.star.ucb.SimpleFileAccess}") If oFileAccess.exists(sFile) and Not oFileAccess.IsFolder(sFile) Then oFile = oFileAccess.openFileRead(sFile) oStream = createUnoService("[EMAIL PROTECTED] com.sun.star.io.TextInputStream}") oStream.setInputStream(oFile) oStream.setEncoding(sEncoding) i = 0 j = 0 mArray(0, 0, 0) = "[]" bFlag = True While Not oStream.isEOF sTmp = oStream.readLine() If sTmp <> "" and Left(sTmp, 1) <> ";" Then ' ignore comments ... If Left(sTmp, 1) = "[" Then If bFlag = True Then bFlag = False Else j = j + 1 i = 0 EndIf mArray(j, i, 0) = Trim(sTmp) Else mTmp() = Split(sTmp, "=", 2) If uBound(mTmp()) = 1 Then mArray(j, i, 1) = Trim(mTmp(0)) mArray(j, i, 2) = mTmp(1) Else mArray(j, i, 1) = Trim(sTmp) EndIf i = i + 1 EndIf EndIf Wend oStream.closeInput() oFile.closeInput() EndIf Redim Preserve mArray(j, nMaxEntry, 2) as String ReadIniFile = mArray() Exit Function ErrorHandler: mArray(0, 0, 0) = "-1" ReadIniFile = mArray() MsgBox Err() & Chr(13) & Error() & Chr(13) & Erl() End Function</listing> </answer> <versions> <version number="1.1.x" status="tested"/> <version number="2.0.x" status="tested"/> </versions> <operating-systems> <operating-system name="Win32"/> </operating-systems> <changelog> </changelog> </snippet>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]