Results 1 to 5 of 5

Thread: Trouble with a Ini Class

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Arrow Trouble with a Ini Class

    Hi all

    I am trying to read 2 values from an Ini file

    I am useing the class from this web page ( i can post the source if you dont want to download it)


    but when i use the lines
    vb Code:
    1. IniReader ini = new IniReader(@"\\filervoca\groups\edit\public\iPass\Billpass config\billpass25.ini");                    
    2. ini.Write("Section1", "KeyString", "PR AD CI GC MK ED FI IT HR DC UW UN");
    3. ini.Write("Section1", "KeyTest", @"c:/test.txt");
    4. string str = ini.ReadString("Section1", "KeyString");
    5. string tem = ini.ReadString("Section1", "KeyTest");

    And the first line (string str) works fine
    the second line (string tem) Will not pick up th evalue no mater what i do

    It writes the value fine
    if i change the varables to match STR exactly ( Section1, KeyString) it still will not pick up a value.

    If i change STR variables to the KeyTest it will pick up the correct variable


    It seems like it just doesnt like being used twice
    so i even went as far to delcare the class again in a diffrent section of code as INI2 and still it wont work.

    any ideas

    im really stuck

  2. #2

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Trouble with a Ini Class

    just as a note lines 2&3 are just for trouble shooting to show that i can write a value

    they will be removed in the actuall code

  3. #3
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Trouble with a Ini Class

    Can really see why one would act different then another maybe post the code for the readString method.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  4. #4

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Trouble with a Ini Class

    VB Code:
    1. IniFile ini = new IniFile(@"\\filervoca\groups\edit\public\iPass\Billpass config\billpass25.ini");
    2.                     //ini.Write("Info", "Department", "PR AD CI GC MK ED FI IT HR DC UW UN");
    3.                     //ini.Write("Section1", "KeyString", "PR AD CI GC MK ED FI IT HR DC UW UN");
    4.                     ini.IniWriteValue("Section1", "KeyTest", @"c:/test.txt");
    5.                     string str = ini.IniReadValue("Section1", "KeyString");
    6.                     string tem = ini.IniReadValue("Section1", "KeyTest");
    7.                     department = str.Split(' ');


    Here is the Class
    VB Code:
    1. namespace Ini
    2. {
    3.     /// <summary>
    4.     /// Create a New INI file to store or load data
    5.     /// </summary>
    6.     public class IniFile
    7.     {
    8.         public string path;
    9.  
    10.         [DllImport("kernel32")]
    11.         private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
    12.         [DllImport("kernel32")]
    13.         private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
    14.  
    15.         /// <summary>
    16.         /// INIFile Constructor.
    17.         /// </summary>
    18.         /// <param name="INIPath"></param>
    19.         public IniFile(string INIPath)
    20.         {
    21.             path = INIPath;
    22.         }
    23.         /// <summary>
    24.         /// Write Data to the INI File
    25.         /// </summary>
    26.         /// <param name="Section"></param>
    27.         /// Section name
    28.         /// <param name="Key"></param>
    29.         /// Key Name
    30.         /// <param name="Value"></param>
    31.         /// Value Name
    32.         public void IniWriteValue(string Section,string Key,string Value)
    33.         {
    34.             WritePrivateProfileString(Section,Key,Value,this.path);
    35.         }
    36.        
    37.         /// <summary>
    38.         /// Read Data Value From the Ini File
    39.         /// </summary>
    40.         /// <param name="Section"></param>
    41.         /// <param name="Key"></param>
    42.         /// <param name="Path"></param>
    43.         /// <returns></returns>
    44.         public string IniReadValue(string Section,string Key)
    45.         {
    46.             StringBuilder temp = new StringBuilder(255);
    47.             int i = GetPrivateProfileString(Section,Key,"",temp,255,this.path);
    48.             return temp.ToString();
    49.  
    50.         }
    51.     }
    52. }

  5. #5

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Trouble with a Ini Class

    bump

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width