Click here to Skip to main content
15,919,749 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: String comparison/search Pin
helelark1239-Apr-08 23:18
helelark1239-Apr-08 23:18 
GeneralRe: String comparison/search Pin
Steven J Jowett9-Apr-08 23:32
Steven J Jowett9-Apr-08 23:32 
GeneralRe: String comparison/search Pin
helelark1239-Apr-08 22:58
helelark1239-Apr-08 22:58 
GeneralConvert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
drexler_kk9-Apr-08 20:51
drexler_kk9-Apr-08 20:51 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
Dave Kreskowiak10-Apr-08 3:43
mveDave Kreskowiak10-Apr-08 3:43 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
drexler_kk10-Apr-08 15:22
drexler_kk10-Apr-08 15:22 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
Dave Kreskowiak10-Apr-08 16:10
mveDave Kreskowiak10-Apr-08 16:10 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
drexler_kk10-Apr-08 16:34
drexler_kk10-Apr-08 16:34 
Hello Dave Kreskowiak,

The following is the code I found from pinvoke, but there is a few error on it display on my Visual Studio 2003 developer tools:

 Private Const MaxIniBuffer As Integer = &H7FFF<br />
<br />
    Public Shared Function ReadSection(ByVal filename As String, ByVal section As String) As System.Collections.Specialized.NameValueCollection<br />
<br />
        Dim pBuffer As IntPtr<br />
        Dim bytesRead As Byte<br />
        Dim sectionData As New System.Text.StringBuilder(MaxIniBuffer)<br />
<br />
        Dim values As New System.Collections.Specialized.NameValueCollection<br />
        Dim pos As Integer ' seperator position<br />
        Dim name, value As String<br />
<br />
        If (Not System.IO.File.Exists(filename)) Then<br />
            Return Nothing<br />
        End If<br />
<br />
        ' get a pointer to the unmanaged memory<br />
        pBuffer = Marshal.AllocHGlobal(MaxIniBuffer)<br />
<br />
        bytesRead = GetPrivateProfileSection(section, pBuffer, MaxIniBuffer, filename)<br />
<br />
        If (bytesRead > 0) Then<br />
<br />
            For i As Integer = 0 To bytesRead - 1<br />
                sectionData.Append(Convert.ToChar(Marshal.ReadByte(pBuffer, i)))<br />
            Next<br />
<br />
            sectionData.Remove(sectionData.Length - 1, 1)<br />
<br />
            For Each line As String In sectionData.ToString().Split(Convert.ToChar(0))<br />
<br />
                ' locate the seperator<br />
                pos = line.IndexOf("=")<br />
<br />
                If (pos > -1) Then<br />
<br />
                    ' get values<br />
                    name = line.Substring(0, pos)<br />
                    value = line.Substring(pos + 1)<br />
<br />
                    ' add to collection<br />
                    values.Add(name, value)<br />
<br />
                End If<br />
<br />
            Next<br />
        Else<br />
            values = Nothing<br />
        End If<br />
<br />
        ' release the unmanaged memory<br />
        Marshal.FreeHGlobal(pBuffer)<br />
<br />
        ' return collection or Nothing if we weren't able to get anything<br />
        Return values<br />
<br />
    End Function


First>>
Name "Marshal" is not declared.

Second>>
Value of type 'System.IntPtr' cannot be converted to 'String'.



Do you know how to solve this? I'm not really understanding how the flow of the data goes here in the above code.

Thanks~!
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
Dave Kreskowiak11-Apr-08 1:28
mveDave Kreskowiak11-Apr-08 1:28 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
drexler_kk11-Apr-08 15:48
drexler_kk11-Apr-08 15:48 
GeneralRe: Convert VB6 code to VB.NET - Public Declare Function GetPrivateProfileSection Pin
rahul_dss29-Nov-10 0:33
rahul_dss29-Nov-10 0:33 
QuestionRegarding differnt formats Pin
vijaylumar9-Apr-08 20:08
vijaylumar9-Apr-08 20:08 
GeneralRe: Regarding differnt formats Pin
Marc Soleda9-Apr-08 20:52
Marc Soleda9-Apr-08 20:52 
GeneralRe: Regarding differnt formats Pin
Dave Kreskowiak10-Apr-08 3:41
mveDave Kreskowiak10-Apr-08 3:41 
QuestionGenerating Project Documentation for vb.net 2.0 windows application Pin
vijaylumar9-Apr-08 20:00
vijaylumar9-Apr-08 20:00 
GeneralRe: Generating Project Documentation for vb.net 2.0 windows application Pin
ilprincipe9-Apr-08 20:38
ilprincipe9-Apr-08 20:38 
GeneralRe: Generating Project Documentation for vb.net 2.0 windows application Pin
Marc Soleda9-Apr-08 20:51
Marc Soleda9-Apr-08 20:51 
Questionvbcommenter Pin
Tauseef A9-Apr-08 18:13
Tauseef A9-Apr-08 18:13 
GeneralRe: vbcommenter Pin
Marc Soleda9-Apr-08 20:58
Marc Soleda9-Apr-08 20:58 
GeneralRe: vbcommenter Pin
helelark1239-Apr-08 21:46
helelark1239-Apr-08 21:46 
GeneralRe: vbcommenter Pin
Marc Soleda9-Apr-08 21:48
Marc Soleda9-Apr-08 21:48 
GeneralRe: vbcommenter Pin
helelark1239-Apr-08 22:56
helelark1239-Apr-08 22:56 
GeneralRe: vbcommenter Pin
Marc Soleda12-Apr-08 5:57
Marc Soleda12-Apr-08 5:57 
GeneralRe: vbcommenter [modified] Pin
helelark12312-Apr-08 22:11
helelark12312-Apr-08 22:11 
Questionhelp..urgent ..insert time to database [modified] Pin
Member 44429169-Apr-08 16:46
Member 44429169-Apr-08 16:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.