[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
Re: Need your help to read the stiring
Don't remember where I came across these functions, but here they are:
vb 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
Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String)
Dim sBuffer As String, lRet As Long
sBuffer = String$(255, 0)
lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
If lRet = 0 Then
If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
GetFromINI = sDefault
Else
GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
End If
End Function
Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
Dim lRet As Long
lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
AddToINI = (lRet)
End Function
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??????????? :(
Re: Need your help to read the stiring
Your supposed to call those functions (which are just wrappers of the APIs).
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
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.
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
Re: Need your help to read the stiring
What line is causing the error?
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
1 Attachment(s)
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...
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 :D