.INI in VB.Net?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?VG9tbXkgTG9uZw==?=

    .INI in VB.Net?

    I know how to do it in VB6, I have code snippets coming out my ears for VB6,
    but with the new framework in Visual Studio 2005, how do you get/put from a
    ..INI

    If I attempt to use a VB6 snippet in Studio 05 it whinges about using the
    'as Any' type in my declarations, and it whinges about using the String$()
    function when creating a buffer string variable. Infact, it whinges a whole
    lot, why my employer got VS05 I'll never know. :(

    Anyway, thanks in advance for any help.

    If people have simple alternatives for the use of .ini's for my future
    reference, that'd be handy as well. Assumably .xl?

    Cheers,
    Tommy

    --
    -------------------------------
    Please respond to my posts via the newsgroup as the e-mail provided is not
    monitored.
  • =?Utf-8?B?VG9tbXkgTG9uZw==?=

    #2
    RE: .INI in VB.Net?

    Found it,

    Never mind. Linked below:


    --
    -------------------------------
    Please respond to my posts via the newsgroup as the e-mail provided is not
    monitored.


    "Tommy Long" wrote:
    I know how to do it in VB6, I have code snippets coming out my ears for VB6,
    but with the new framework in Visual Studio 2005, how do you get/put from a
    .INI
    >
    If I attempt to use a VB6 snippet in Studio 05 it whinges about using the
    'as Any' type in my declarations, and it whinges about using the String$()
    function when creating a buffer string variable. Infact, it whinges a whole
    lot, why my employer got VS05 I'll never know. :(
    >
    Anyway, thanks in advance for any help.
    >
    If people have simple alternatives for the use of .ini's for my future
    reference, that'd be handy as well. Assumably .xl?
    >
    Cheers,
    Tommy
    >
    --
    -------------------------------
    Please respond to my posts via the newsgroup as the e-mail provided is not
    monitored.

    Comment

    • Tom Shelton

      #3
      Re: .INI in VB.Net?

      On 2008-07-02, Tommy Long <TommyLong@disc ussions.microso ft.comwrote:
      I know how to do it in VB6, I have code snippets coming out my ears for VB6,
      but with the new framework in Visual Studio 2005, how do you get/put from a
      .INI
      >
      If I attempt to use a VB6 snippet in Studio 05 it whinges about using the
      'as Any' type in my declarations, and it whinges about using the String$()
      function when creating a buffer string variable. Infact, it whinges a whole
      lot, why my employer got VS05 I'll never know. :(
      >
      Anyway, thanks in advance for any help.
      >
      If people have simple alternatives for the use of .ini's for my future
      reference, that'd be handy as well. Assumably .xl?
      >
      Cheers,
      Tommy
      >
      Hard to answer without seeing the method your using, but the basic answer is
      "the same way". Are you using API calls? VB6 File IO?

      Why don't you post a small sample of the problematic code (including api
      declarations if that's the method your using) - your more likely to get a
      correct answer that way :)
      --
      Tom Shelton

      Comment

      • =?Utf-8?B?VG9tbXkgTG9uZw==?=

        #4
        Re: .INI in VB.Net?

        I've been using the VB6 Code, I've found an answer but in the interest of
        better answers, here are the declarations:

        Private Declare Function GetPrivateProfi leString Lib "kernel32" Alias
        "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, ByVal
        lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedStrin g As
        String, ByVal nSize As Long, ByVal lpFileName As String) As Long

        Private Declare Function WritePrivatePro fileString Lib "kernel32" Alias
        "WritePrivatePr ofileStringA" (ByVal lpApplicationNa me As String, ByVal
        lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

        They both throw multiple errors for their use of the 'Any' variable type.

        Additionally, in the following 'GetFromINI' procedure:

        Function GetFromINI(sSec tion As String, sKey As String, sDefault As String,
        sIniFile As String)
        Dim sBuffer As String, lRet As Long
        ' Fill String with 255 spaces
        sBuffer = String$(255, 0)
        ' Call DLL
        lRet = GetPrivateProfi leString(sSecti on, sKey, "", sBuffer,
        Len(sBuffer), sIniFile)
        If lRet = 0 Then
        ' DLL failed, save default
        If sDefault <"" Then AddToINI sSection, sKey, sDefault, sIniFile
        GetFromINI = sDefault
        Else
        ' DLL successful
        ' return string
        GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
        End If
        End Function

        I receive an error for using the function 'String$(#, #)' which I don't know
        a replacement for in VB.NET.

        I'm not all that interested in converting to XL* files, though I may in the
        future. I believe the link I provided in my initial post contains a link
        near the bottom for implementing XL* procedures instead of INI though.

        Any help that is better for one reason or another than the class based
        solution I posted is much appreciated.

        Tommy
        --
        -------------------------------
        Please respond to my posts via the newsgroup as the e-mail provided is not
        monitored.


        "Tom Shelton" wrote:
        On 2008-07-02, Tommy Long <TommyLong@disc ussions.microso ft.comwrote:
        I know how to do it in VB6, I have code snippets coming out my ears for VB6,
        but with the new framework in Visual Studio 2005, how do you get/put from a
        .INI

        If I attempt to use a VB6 snippet in Studio 05 it whinges about using the
        'as Any' type in my declarations, and it whinges about using the String$()
        function when creating a buffer string variable. Infact, it whinges a whole
        lot, why my employer got VS05 I'll never know. :(

        Anyway, thanks in advance for any help.

        If people have simple alternatives for the use of .ini's for my future
        reference, that'd be handy as well. Assumably .xl?

        Cheers,
        Tommy
        >
        Hard to answer without seeing the method your using, but the basic answer is
        "the same way". Are you using API calls? VB6 File IO?
        >
        Why don't you post a small sample of the problematic code (including api
        declarations if that's the method your using) - your more likely to get a
        correct answer that way :)
        --
        Tom Shelton
        >

        Comment

        • Tom Shelton

          #5
          Re: .INI in VB.Net?

          On 2008-07-02, Tommy Long <TommyLong@disc ussions.microso ft.comwrote:
          Found it,
          >
          Never mind. Linked below:
          >
          http://www.developer.com/net/asp/article.php/3287991
          I wonder why the author decided to use the Ansi functions? You can simply
          declare the functions as Auto and let the runtime decide the best method for
          the system (which on NT based boxes is going to be the W functions).

          --
          Tom Shelton

          Comment

          • Tom Shelton

            #6
            Re: .INI in VB.Net?

            On 2008-07-02, Tommy Long <TommyLong@disc ussions.microso ft.comwrote:
            I've been using the VB6 Code, I've found an answer but in the interest of
            better answers, here are the declarations:
            >
            Private Declare Function GetPrivateProfi leString Lib "kernel32" Alias
            "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, ByVal
            lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedStrin g As
            String, ByVal nSize As Long, ByVal lpFileName As String) As Long
            >
            Private Declare Auto Function GetPrivateProfi leString Lib "kernel32" ( _
            ByVal lpApplicationNa me As String, _
            ByVal lpKeyName As String, _
            ByVal lpDefault As String, _
            ByVal lpReturnedStrin g As System.Text.Str ingBuilder, _
            ByVal nSize As Integer, _
            ByVal lpFileName As String)
            Private Declare Function WritePrivatePro fileString Lib "kernel32" Alias
            "WritePrivatePr ofileStringA" (ByVal lpApplicationNa me As String, ByVal
            lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
            >
            Private Declare Auto Function WritePrivatePro fileString Lib "kernel32" ( _
            ByVal lpApplicationNa me As String, _
            ByVal lpKeyName As String, _
            ByVal lpString As String, _
            ByVal lpFileName As String) As Integer
            They both throw multiple errors for their use of the 'Any' variable type.
            >
            That's because VB.NET doesn't support the As Any type. To be honest, it isn't
            often needed - and, because VB.NET supports overloading, you can declare the
            API's with multiple signitures. Yes, I'm aware that that can be a pain, but
            rarely is in practice, since it isn't common to have to declare the api call
            with more then two or three signatures.
            Additionally, in the following 'GetFromINI' procedure:
            >
            Function GetFromINI(sSec tion As String, sKey As String, sDefault As String,
            sIniFile As String)
            Dim sBuffer As String, lRet As Long
            ' Fill String with 255 spaces
            sBuffer = String$(255, 0)
            ' Call DLL
            lRet = GetPrivateProfi leString(sSecti on, sKey, "", sBuffer,
            Len(sBuffer), sIniFile)
            If lRet = 0 Then
            ' DLL failed, save default
            If sDefault <"" Then AddToINI sSection, sKey, sDefault, sIniFile
            GetFromINI = sDefault
            Else
            ' DLL successful
            ' return string
            GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
            End If
            End Function
            >
            Function GetFromINI ( _
            ByVal sSection As String, _
            ByVal sKey As String, _
            ByVal sDefault As String, _
            ByVal sIniFile As String) As String

            Dim sBuffer As New StringBuilder (255)

            Dim lRet As Integer = GetPrivateProfi leString ( _
            sSection,
            sKey,
            String.Empty,
            sBuffer,
            sBuffer.Capacit y,
            sIniFile)

            If lRet = 0 Then
            If Default <String.Empty Then
            AddToINI (sSection, sKey, sDefault, sIniFile)
            End If
            Return sDefault
            End if

            Return sBuffer.ToStrin g()
            End Function
            I receive an error for using the function 'String$(#, #)' which I don't know
            a replacement for in VB.NET.
            >
            Actually, you can do that with a string constructor:

            Dim s As String = new String (5, "#")

            --
            Tom Shelton

            Comment

            • rowe_newsgroups

              #7
              Re: .INI in VB.Net?

              On Jul 2, 12:03 pm, Tommy Long <TommyL...@disc ussions.microso ft.com>
              wrote:
              I've been using the VB6 Code, I've found an answer but in the interest of
              better answers, here are the declarations:
              >
              Private Declare Function GetPrivateProfi leString Lib "kernel32" Alias
              "GetPrivateProf ileStringA" (ByVal lpApplicationNa me As String, ByVal
              lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedStrin g As
              String, ByVal nSize As Long, ByVal lpFileName As String) As Long
              >
              Private Declare Function WritePrivatePro fileString Lib "kernel32" Alias
              "WritePrivatePr ofileStringA" (ByVal lpApplicationNa me As String, ByVal
              lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
              >
              They both throw multiple errors for their use of the 'Any' variable type.
              >
              Additionally, in the following 'GetFromINI' procedure:
              >
              Function GetFromINI(sSec tion As String, sKey As String, sDefault As String,
              sIniFile As String)
                  Dim sBuffer As String, lRet As Long
                  ' Fill String with 255 spaces
                  sBuffer = String$(255, 0)
                  ' Call DLL
                  lRet = GetPrivateProfi leString(sSecti on, sKey, "", sBuffer,
              Len(sBuffer), sIniFile)
                  If lRet = 0 Then
                      ' DLL failed, save default
                      If sDefault <"" Then AddToINI sSection, sKey, sDefault,sIniFi le
                      GetFromINI = sDefault
                  Else
                      ' DLL successful
                      ' return string
                      GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
                  End If
              End Function
              >
              I receive an error for using the function 'String$(#, #)' which I don't know
              a replacement for in VB.NET.
              >
              I'm not all that interested in converting to XL* files, though I may in the
              future.  I believe the link I provided in my initial post contains a link
              near the bottom for implementing XL* procedures instead of INI though.
              >
              Any help that is better for one reason or another than the class based
              solution I posted is much appreciated.
              >
              Tommy
              --
              -------------------------------
              Please respond to my posts via the newsgroup as the e-mail provided is not
              monitored.
              >
              "Tom Shelton" wrote:
              On 2008-07-02, Tommy Long <TommyL...@disc ussions.microso ft.comwrote:
              I know how to do it in VB6, I have code snippets coming out my ears for VB6,
              but with the new framework in Visual Studio 2005, how do you get/put from a
              .INI
              >
              If I attempt to use a VB6 snippet in Studio 05 it whinges about usingthe
              'as Any' type in my declarations, and it whinges about using the String$()
              function when creating a buffer string variable.  Infact, it whinges a whole
              lot, why my employer got VS05 I'll never know.  :(
              >
              Anyway, thanks in advance for any help.
              >
              If people have simple alternatives for the use of .ini's for my future
              reference, that'd be handy as well.  Assumably .xl?
              >
              Cheers,
              Tommy
              >
              Hard to answer without seeing the method your using, but the basic answer is
              "the same way".  Are you using API calls?  VB6 File IO?
              >
              Why don't you post a small sample of the problematic code (including api
              declarations if that's the method your using) - your more likely to geta
              correct answer that way :)
              --
              Tom Shelton
              Here's a great site to find the proper API declarations for .NET



              Also, I personally never use .ini files for my .NET applications. I
              prefer to use a custom xml file or use the My.Settings code and it's
              attached .config files.

              Thanks,

              Seth Rowe [MVP]

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: .INI in VB.Net?

                "Tommy Long" <TommyLong@disc ussions.microso ft.comschrieb:
                >I know how to do it in VB6, I have code snippets coming out my ears for
                >VB6,
                but with the new framework in Visual Studio 2005, how do you get/put from
                a
                .INI
                Complete INI library written in VB based on the Win32 INI functions:

                <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/IniLib.zip>

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • Cor Ligthert[MVP]

                  #9
                  Re: .INI in VB.Net?

                  Herfried,

                  I was waiting for this one,

                  Strange enough that there is nobody who tells not to use INI files anymore,
                  I say it here, but I don't go in the discussion, it is discussed to often in
                  past, and samples for better alternatives are easily to find on Google.

                  But it seems that the sinse this millenium better alternatives for INI files
                  are completely missed by some persons.

                  Cor


                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                  news:usi5xtK3IH A.3348@TK2MSFTN GP03.phx.gbl...
                  "Tommy Long" <TommyLong@disc ussions.microso ft.comschrieb:
                  >>I know how to do it in VB6, I have code snippets coming out my ears for
                  >>VB6,
                  >but with the new framework in Visual Studio 2005, how do you get/put from
                  >a
                  >.INI
                  >
                  Complete INI library written in VB based on the Win32 INI functions:
                  >
                  <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/IniLib.zip>
                  >
                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                  Comment

                  • =?Utf-8?B?U3VydHVyWg==?=

                    #10
                    Re: .INI in VB.Net?

                    If only Microsoft allowed you to save Application scope settings as well as
                    User ones in My.Settings!!!

                    I find it inexplicable that they don't. Maybe it is because with certain
                    deployments each user login has a separate copy of the app, so changes to
                    settings for all users on a computer can't be done this way??

                    Maybe saving/loading a dataset to XML is the way to go.

                    I've always liked .INI files, but I find the argument list of
                    GetPrivateProfi leString painful. I always end up wrapping it in another
                    function so I can get an .INI setting in one line of code.

                    --
                    David Streeter
                    Synchrotech Software
                    Sydney Australia


                    "Cor Ligthert[MVP]" wrote:
                    Herfried,
                    >
                    I was waiting for this one,
                    >
                    Strange enough that there is nobody who tells not to use INI files anymore,
                    I say it here, but I don't go in the discussion, it is discussed to often in
                    past, and samples for better alternatives are easily to find on Google.
                    >
                    But it seems that the sinse this millenium better alternatives for INI files
                    are completely missed by some persons.
                    >
                    Cor
                    >
                    >
                    "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                    news:usi5xtK3IH A.3348@TK2MSFTN GP03.phx.gbl...
                    "Tommy Long" <TommyLong@disc ussions.microso ft.comschrieb:
                    >I know how to do it in VB6, I have code snippets coming out my ears for
                    >VB6,
                    but with the new framework in Visual Studio 2005, how do you get/put from
                    a
                    .INI
                    Complete INI library written in VB based on the Win32 INI functions:

                    <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/IniLib.zip>

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                    >

                    Comment

                    • Cor Ligthert[MVP]

                      #11
                      Re: .INI in VB.Net?

                      Sutur,

                      Where you talking about, are you talking about isolated storage?



                      I doubt it.

                      Cor

                      "SurturZ" <surturz@newsgr oup.nospamschre ef in bericht
                      news:0F54B227-41BA-441F-B850-EB4335006E2B@mi crosoft.com...
                      If only Microsoft allowed you to save Application scope settings as well
                      as
                      User ones in My.Settings!!!
                      >
                      I find it inexplicable that they don't. Maybe it is because with certain
                      deployments each user login has a separate copy of the app, so changes to
                      settings for all users on a computer can't be done this way??
                      >
                      Maybe saving/loading a dataset to XML is the way to go.
                      >
                      I've always liked .INI files, but I find the argument list of
                      GetPrivateProfi leString painful. I always end up wrapping it in another
                      function so I can get an .INI setting in one line of code.
                      >
                      --
                      David Streeter
                      Synchrotech Software
                      Sydney Australia
                      >
                      >
                      "Cor Ligthert[MVP]" wrote:
                      >
                      >Herfried,
                      >>
                      >I was waiting for this one,
                      >>
                      >Strange enough that there is nobody who tells not to use INI files
                      >anymore,
                      >I say it here, but I don't go in the discussion, it is discussed to often
                      >in
                      >past, and samples for better alternatives are easily to find on Google.
                      >>
                      >But it seems that the sinse this millenium better alternatives for INI
                      >files
                      >are completely missed by some persons.
                      >>
                      >Cor
                      >>
                      >>
                      >"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                      >news:usi5xtK3I HA.3348@TK2MSFT NGP03.phx.gbl.. .
                      "Tommy Long" <TommyLong@disc ussions.microso ft.comschrieb:
                      >>I know how to do it in VB6, I have code snippets coming out my ears for
                      >>VB6,
                      >but with the new framework in Visual Studio 2005, how do you get/put
                      >from
                      >a
                      >.INI
                      >
                      Complete INI library written in VB based on the Win32 INI functions:
                      >
                      <URL:http://dotnet.mvps.org/dotnet/samples/filesystem/IniLib.zip>
                      >
                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
                      >>

                      Comment

                      • Michael Leithold, WWK

                        #12
                        Re: .INI in VB.Net?

                        You can look at this framework for reading config files:

                        Download Nini for free. Nini is an uncommonly powerful .NET configuration library designed to help build highly configurable applications quickly.


                        It's a more .NET like way to read and write ini files than win32 API.

                        Michael

                        Comment

                        • Herfried K. Wagner [MVP]

                          #13
                          Re: .INI in VB.Net?

                          "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschri eb:
                          Strange enough that there is nobody who tells not to use INI files
                          anymore, I say it here, but I don't go in the discussion, it is discussed
                          to often in past, and samples for better alternatives are easily to find
                          on Google.
                          >
                          But it seems that the sinse this millenium better alternatives for INI
                          files are completely missed by some persons.
                          Well, it seems that even in this millennium there are thousands of
                          well-tested and well-established programs in use which still rely on INI
                          files!

                          --
                          M S Herfried K. Wagner
                          M V P <URL:http://dotnet.mvps.org/>
                          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                          Comment

                          • Herfried K. Wagner [MVP]

                            #14
                            Re: .INI in VB.Net?

                            "SurturZ" <surturz@newsgr oup.nospamschri eb:
                            I find it inexplicable that they don't. Maybe it is because with certain
                            deployments each user login has a separate copy of the app, so changes to
                            settings for all users on a computer can't be done this way??
                            You are giving the reason why it's not possible to write application-scoped
                            settings. The current setting would depend on the value persisted by the
                            user who used the application for the last time. This would not make much
                            sense.
                            I've always liked .INI files, but I find the argument list of
                            GetPrivateProfi leString painful. I always end up wrapping it in another
                            function so I can get an .INI setting in one line of code.
                            Fortunately a wrapper can be written once and used several times. There is
                            no need to reinvent the wheel for each application.

                            --
                            M S Herfried K. Wagner
                            M V P <URL:http://dotnet.mvps.org/>
                            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                            Comment

                            • =?Utf-8?B?U3VydHVyWg==?=

                              #15
                              Re: .INI in VB.Net?

                              You are giving the reason why it's not possible to write application-scoped
                              settings. The current setting would depend on the value persisted by the
                              user who used the application for the last time. This would not make much
                              sense.
                              In real-world programming there are plenty of cases where this makes sense.
                              For example, if there is a report that need to be printed on special
                              stationery. If the normal "special stationery" printer breaks down, a user
                              can change the default printer for that report to another printer, and you
                              want it changed for all users of that PC.

                              Setting default save directories after installing an application is another
                              example.

                              --
                              David Streeter
                              Synchrotech Software
                              Sydney Australia


                              Comment

                              Working...