Public Class frmH15Oef7
Inherits System.Windows.Forms.Form
'declaratie
Private mintBestandsNr As Integer = FreeFile()
Private mstrBestandsnaam As String = "StudentAdressenFile.txt"
Private Sub frmH15Oef7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'tekstvak leegmaken
txtInhoud.Clear()
End Sub
Private Sub btnInput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInput.Click, btnLineInput.Click
'declaratie
Dim strTekst As String
'tekstvak leegmaken
txtInhoud.Clear()
'bestand openen
FileOpen(mintBestandsNr, mstrBestandsnaam, OpenMode.Input)
'lus
Do While Not EOF(mintBestandsNr)
Select Case -1
Case sender.text = "Input"
Input(mintBestandsNr, strTekst)
txtInhoud.ForeColor = Color.Brown
Case sender.text = "LineInput"
strTekst = LineInput(mintBestandsNr)
txtInhoud.ForeColor = Color.CornflowerBlue
End Select
txtInhoud.Text &= strTekst & ControlChars.NewLine
Loop
'bestand sluiten
FileClose(mintBestandsNr)
End Sub
Private Sub btnReadToEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReadToEnd.Click, btnReadLine.Click, btnReadBlock.Click
'declaratie
Dim intAantalBytes, intLoper, intLoperBis As Integer
Dim strTekst() As Char
Dim strBestandsNaam As String = "StudentAdressenStream.txt"
Dim objLeesBestand As New System.IO.StreamReader(strBestandsNaam)
'tekstvak leegmaken
txtInhoud.Clear()
Do While objLeesBestand.Peek >= 0
Select Case -1
Case sender.text = "ReadToEnd"
txtInhoud.ForeColor = Color.Purple
txtInhoud.Text = objLeesBestand.ReadToEnd
Case sender.text = "ReadLine"
txtInhoud.ForeColor = Color.Red
txtInhoud.Text &= objLeesBestand.ReadLine & ControlChars.NewLine
Case sender.text = "ReadBlock"
txtInhoud.ForeColor = Color.BurlyWood
intAantalBytes = (intLoper + 1) * 50
ReDim Preserve strTekst(intAantalBytes)
objLeesBestand.ReadBlock(strTekst, intLoperBis, 50)
intLoper += 1
intLoper += 50
End Select
Loop
'voorwaarde
If sender.text = "ReadBlock" Then
'50 chars per lijn afdrukken
For intLoper = strTekst.GetLowerBound(0) To strTekst.GetUpperBound(0)
txtInhoud.Text &= strTekst(intLoper)
If intLoper Mod 50 = 0 Then
txtInhoud.Text &= ControlChars.NewLine
End If
Next
End If
'bestand sluiten
objLeesBestand.Close()
objLeesBestand = Nothing
End Sub
Private Sub btnInit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInit.Click
'tekstvak leegmaken
txtInhoud.Clear()
End Sub
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
'declaratie
Dim strBestandsNaam As String = "StudentAdressenStreamKort.txt"
Dim objLeesBestand As New System.IO.StreamReader(strBestandsNaam)
'tekstvak leegmaken
txtInhoud.Clear()
'lus
Do While objLeesBestand.Peek >= 0
txtInhoud.Text &= Chr(objLeesBestand.Read) & ControlChars.NewLine
Loop
'bestand sluiten
objLeesBestand.Close()
objLeesBestand = Nothing
End Sub
End Class