Results 1 to 11 of 11

Thread: [Resolved] Need your help to read the stiring

  1. #1

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Resolved [Resolved] Need your help to read the stiring

    Hi everyone!

    I need your help with my sample project to read the ini string for listview but I couldn't find a sample one. If I had one for myself then I wouldn't have posting my request on the forum, I would have build one for myself. I need your help with this. It have to be reading one line in each sentence only.




    You still have the rights to open my sample string to rewrite and send it back.


    Thanks,
    Mark
    Last edited by Mark103; Nov 1st, 2007 at 05:17 PM.

  2. #2
    Junior Member
    Join Date
    Sep 2007
    Posts
    29

    Re: Need your help to read the stiring

    Don't remember where I came across these functions, but here they are:
    vb Code:
    1. 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
    2. 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
    3.  
    4. Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String)
    5.     Dim sBuffer As String, lRet As Long
    6.     sBuffer = String$(255, 0)
    7.     lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
    8.     If lRet = 0 Then
    9.         If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
    10.         GetFromINI = sDefault
    11.     Else
    12.         GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
    13.     End If
    14. End Function
    15.  
    16. Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
    17.     Dim lRet As Long
    18.     lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
    19.     AddToINI = (lRet)
    20. End Function

  3. #3

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: Need your help to read the stiring

    Thanks for that, I have pasted the code on my form but it didn't read the ini string. Please help???????????

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need your help to read the stiring

    Your supposed to call those functions (which are just wrappers of the APIs).

  5. #5

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: Need your help to read the stiring

    Ok, I have sort that out but I made a mistake and choose the wrong box which string I would like to read. Really I should have chose listbox even not listview.



    Code:
    Private Sub Form_Load()
      Dim FNum, a$, s$()
      FNum = FreeFile
      List1.ListItems.Clear
      Open App.Path + "\test.ini" For Input As #FNum
      Do
          Line Input #FNum, a$
      Loop Until EOF(FNum) Or a$ = ""
        While Not EOF(FNum)
        Line Input #1, a$
        If a$ <> "" Then
           If InStr(a$, "=") Then 'if there's an "="
              s = Split(a$, "=")
              List1.ListItems.Add , , s$(1)
           End If
      End If
      Wend
      Close #FNum
      FreeFile FNum
      Close #FNum
    End Sub


    It won't read the string for my listbox as I have received the following error "compile error: Method or data member not found". I have no idea how to solve this problem. Is there any other way to get my problem resolving??




    Thanks,
    Mark
    Last edited by Mark103; Oct 24th, 2007 at 07:05 PM.

  6. #6
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Need your help to read the stiring

    If List1 is a listbox then it won't have a ListItems collection, which is found in a listview control. List1.AddItem is the method for adding items to a listbox.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: Need your help to read the stiring

    Quote Originally Posted by leinad31
    If List1 is a listbox then it won't have a ListItems collection, which is found in a listview control. List1.AddItem is the method for adding items to a listbox.

    Thanks, I tried to exchange the code but still received the same error. I am still trying to use listbox. What is the correct code??



    Sorry about that but I picked out the lesson I was meant to learn.


    Thanks,
    Mark
    Last edited by Mark103; Oct 24th, 2007 at 08:33 PM.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need your help to read the stiring

    What line is causing the error?

  9. #9

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: Need your help to read the stiring

    Code:
      List1.ListItems.Clear
      List1.ListItems.Add , , s$(1


    what can i do?????


    Hope you can help me out with this.

    Thanks,
    Mark

  10. #10
    Member jeruelx5d's Avatar
    Join Date
    Jun 2006
    Posts
    39

    Re: Need your help to read the stiring

    I downloaded your code and try to fix it... I just copy the code posted by Mark103...

    Try this... See attached code...
    Attached Files Attached Files

  11. #11

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: Need your help to read the stiring

    Quote Originally Posted by jeruelx5d
    I downloaded your code and try to fix it... I just copy the code posted by Mark103...

    Try this... See attached code...


    thanks. it's awesome

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