Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 105,415 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,860 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



.INI in VS2005!?

 
Reply to this topicStart new topic

.INI in VS2005!?, How do I manipulate a .INI in VS05

Smudge202
post 2 Jul, 2008 - 08:12 AM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 15


My Contributions


Hey Fellas,

I have a nice set of code snip's for VB6, but I recently upgraded to Visual Studio 2005, and its throwing me off something chronic.

I used to get/put to .ini using the following code:

Declarations:
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


Procedure to get would be the very common:

CODE
Function GetFromINI(sSection 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 = GetPrivateProfileString(sSection, 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


And to put, the good ol':

CODE
Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
    Dim lRet As Long
    ' Call DLL
    lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
    AddToINI = (lRet)
End Function


Of course, with the new structure in '05 the above doesn't work. Its whinges about the 'Any' file type in the declarations, and it doesn't like using the String$(#,#) function and I haven't found a suitable replacement for that either.

Do I honestly need to copy paste all the above stuff freely available on the net to prove I'm not doing "homework"? biggrin.gif

Thanks in advance guys.

Tommy.
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 2 Jul, 2008 - 08:20 AM
Post #2


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,002



Thanked 45 times

Dream Kudos: 7600

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI

My Contributions


Moved to VB.NET
User is offlineProfile CardPM

Go to the top of the page

Smudge202
post 2 Jul, 2008 - 08:41 AM
Post #3


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 15


My Contributions


QUOTE(PsychoCoder @ 2 Jul, 2008 - 08:20 AM) *

Moved to VB.NET


Lol, a similar post on a different forum was just moved to VB.Net, tried to get back to this one in time to move it but you beat me to it. smile.gif

Cheers PsychoCoder

------------------------------------------------

EDIT:

Found it,

Linked below for any one fed up with Microsoft trying to stop us using the .INI file format wink2.gif

http://www.developer.com/net/asp/article.php/3287991

This post has been edited by Smudge202: 2 Jul, 2008 - 08:41 AM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 2 Jul, 2008 - 09:50 AM
Post #4


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,716



Thanked 19 times

Dream Kudos: 2800

Expert In: C, C++, VB, VB.NET, C#, Java, x86 Assembly, Win32 API, Reversing

My Contributions


Since it's not a homework problem, you could use my INI Class in VB.NET that I wrote for the same purpose.

Reuse code as much as possible to save time and effort.

It's pretty straight-forward and fairly documented.

You know where to turn to if you have any problems wink2.gif

EDIT:
I checked Smudge202's link. His code is similar to mine so you might as well use that.


Attached File(s)
Attached File  INI_File_class.zip ( 1.15k ) Number of downloads: 17
User is offlineProfile CardPM

Go to the top of the page

Smudge202
post 3 Jul, 2008 - 01:59 AM
Post #5


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 15


My Contributions


Nice one born2code,

thanks for the download and the reply. wink2.gif

I've already stuck the code in from the link I posted but will keep yours for future ref.

Smudge
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/20/08 05:59AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month