I have an ini file that I want to get all the dates from. Currently what I have is only getting the first date. I have tried running my function in a loop, but it was still only giving me the 1st date.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim passfail = GetIniValue("DATE", "self-test-test.ini", "FAIL")
RichTextBox3.Text = passfail
End Sub
Private Sub RichTextBox3_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox3.TextChanged
End Sub
Public Function GetIniValue(key As String, filename As String, Optional defaultValue As String = "") As String
Dim inifile As New StreamReader(filename)
Dim LineData As String
Dim textdata() As String
Dim keydata As String = defaultValue
Dim done As Boolean = False
If File.Exists(filename) Then
Do While Not done
If inifile.Peek() >= 0 Then
LineData = inifile.ReadLine()
textdata = Split(LineData, "=")
If Trim(textdata(0)) = key Then
If UBound(textdata) > 0 Then
keydata = Trim(textdata(1))
End If
done = True
End If
Else
done = True
End If
Loop
inifile.Close()
End If
GetIniValue = keydata
End Function
End Class
> ini file self-test-test.ini
[20E2SN5]
DATE=05/01/2019,15:12:12
STATUS=PASS
[20R5SN9]
DATE=06/21/2019,15:13:13
STATUS=PASS
this was one of the loops I have tried but was still only giving me the first date.
``` Dim passfail = GetIniValue("DATE", "self-test-test.ini", "FAIL")
For Each n In passfail
RichTextBox3.Text += n.ToString
Next
currently I am getting a return of
05/01/2019,15:12:12
but would like to receive a return of
05/01/2019,15:12:12
06/21/2019,15:13:13
Use Windows API
GetPrivateProfileSectionNamesto get all the section names, then useGetPrivateProfileStringto get the value for the "DATE" key.You can use the helper functions (
GetIniSectionNamesandGetIniValue) below.