Announcement

Collapse
No announcement yet.

INI Dateien

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • INI Dateien

    Hallo!
    Suche Funktionen um in VB.NET INI Dateien zu lesen und zu schreiben.

    Tschüß
    Nic

  • #2
    Ich glaube mit XML komst du besser zu Recht.

    Beispiel für XML Datei < App.config >

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="Test1" value="This is the value of Test1" />
    <add key="Test2" value="This is the value of Test2" />
    </appSettings>
    </configuration>

    XML in Textbox Lesen

    Dim config As System.Configuration.ConfigurationSettings
    Dim key As String
    With Me.TextBox1
    For Each key In config.AppSettings.AllKeys
    .AppendText(config.AppSettings(key) & vbCrLf)
    Next
    End With

    XML in Textbox Schreiben

    config.AppSettings.Set("Test1", 5)

    usw

    Comment


    • #3
      Ansonsten mal was in C#
      Sollte vielleicht als einzelne Classenbibliothek (*.dll) bei VB-Net gespeichert werden.

      Gruß Mary Leipzig
      -----------------------------------------------
      //
      // Author: Uri02 [email protected]
      // U can use it but, please don't remove the author
      // If you have any question or suggest,ask me !
      //
      //
      using System;
      using System.Diagnostics;
      using System.Collections;
      using System.Collections.Specialized;
      using System.IO;
      namespace Utils.Uri.Psp.Program3
      {
      public class IniFileManager
      {
      // Thw IniFileManager class is to manipulate Standart Ini Files
      //
      // * Sections & Keys can't have spaces at the begin or at the end
      // * Sections & Keys are Case sensitive
      // * Constructors
      // - public IniFileManager(string iniFileName)
      // - public IniFileManager()
      // * Properties
      // - IniFileName (set/get)
      // * Methods:
      // - EraseSection
      // - EraseSectionKey
      // - ExistsSection
      // - ExistsSectionKey
      // - FlushToDisk
      // - ReadValue
      // - WriteValue
      // - GetAllSectionNames (TODO)
      // - GetAllKeysBySection (TODO)
      // - GetAllSectionKeys (TODO)
      //Private variables
      private string myIniFileName="";
      private bool myFileReaded = false;
      private SortedList myFileLines = new SortedList(); // This collection contains all the lines by order
      private SortedList mySectionKeysLines = new SortedList(); // SortedList to find the Sections & Keys quickly, the key is [Section]+Key and the value is the number of the line
      private long MaxFileLines =0;
      private long InsertedKeys =0;

      enum iniLineType {empty,comment,section,keyValue};
      //Constructor
      public IniFileManager(string iniFileName)
      {
      Debug.Assert ( iniFileName != null && iniFileName != "");
      myIniFileName = iniFileName;
      myFileReaded = ReadIniFile();
      }
      public IniFileManager()
      {
      myFileReaded =false;
      }
      //Properties
      public string IniFileName
      {
      get { return myIniFileName; }
      set
      {
      myFileReaded = false;
      myIniFileName = value;
      }
      }
      //Private Methods
      private string BuildSectionKeyToHKey(string section,string key) { //HKey denotes HashtableKey
      //To Build Section+Key to a sortedlist Key ([Section1]Key1)
      Debug.Assert(section != null && section!= "");
      Debug.Assert(key !=null && key!="" && key.IndexOf("=")<0);//Char "=" not permit in key Name
      return (BuildSectionToHKey(section) + key.Trim());
      }
      private string BuildSectionToHKey(string section) { //HKey denotes HashtableKey
      //To Build section to a sortedlist Key ([Section1])
      Debug.Assert(section != null && section!= "");
      return ("["+ section.Trim()+ "]");
      }
      private string BuildLineToHKey(string lineCount, string extension)
      {
      //To Build the valid index to be sorted by the SortList
      return( lineCount.PadLeft(10,"0".ToCharArray()[0]) + extension);
      }
      private bool ReadIniFile()
      {
      //It Fills the Table with the Sections and the Sections+Keys
      //If any error ocurs, it throws an exception "Error reading" and the "real" exception like a InnerException
      if (myFileReaded==true) return (true);
      if (!File.Exists(myIniFileName))
      {
      FileStream myNewFile = File.Create (myIniFileName);
      myNewFile.Close();
      }
      string line = "";
      long lineCount =0;
      myFileLines = new SortedList();
      mySectionKeysLines = new SortedList();
      string currentSection="[Default]"; // If it find Key without Section at the begining of the file
      using (StreamReader readFileStream = new StreamReader(myIniFileName) )
      {
      try
      {
      while (readFileStream.Peek() > -1) //Returns -1 when it finds the end of file
      {
      line = readFileStream.ReadLine().Trim(); //Removes all spaces
      lineCount ++ ;
      if (this.GetIniLineType(line)== (int) iniLineType.section)
      {
      currentSection = line;
      mySectionKeys

      Comment


      • #4
        Ansonsten unter http://www.planet-source-code.com/

        Gibt es eine Classe von [email protected]

        Ist aber in c# geschrieben.

        Sollte vielleicht als einzelne Classenbibliothek (*.dll) bei VB-Net gespeichert werden.

        Gruß Mary Leipzi

        Comment

        Working...
        X