Ik ben al een tijdje aan het leren programmeren. Nu moet ik een oefening maken op Text files etc. Dit is de opdracht:
En dit heb ik al de fouten staan in de commentaar:
Wie kan mij helpen? Het moet niet de volledige oplossing zijn hoor, ik snap alleen niet wat ik mis doe. Alvast bedankt voor de antwoorden.
Met vriendelijke groeten,
Dieter
Part One
There is a text file to download called “dictionary”. (The download location can be
found at the start of this book). This contains Texting English followed by it’s Real
English translation. For example:
LOL = Laughing out loud
Each line uses an equals sign to separate the Texting English from it’s Real English
translation. When a button is clicked on your form, you job is to write the code that
opens this “dictionary” text file and read its contents. Once the text file is opened, write
code to place the Texting English in one List Box and the Real English in a second List
Box.
That’s clearly not enough, though. When a user clicks on a term in a List Box, display
the translation in a Textbox. So if LOL was selected from your List Box, the translation
“Laughing out loud” should appear in the textbox. But if “Laughing out loud” was
selected, the Texting version, LOL, should appear in the textbox.
Part Two
Add two new textboxes and a button. Write code so that the user can add a new
Text/Real English pair to the dictionary.
En dit heb ik al de fouten staan in de commentaar:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLezen.Click
Dim dictionary As String = "C:\Documents and Settings\Eigenaar\Bureaublad\dictionary.txt"
Dim objReader As New System.IO.StreamReader(Dictionary)
Dim arry() As String
Dim text As String = ""
Do Until objReader.Peek() = -1
text = objReader.ReadLine
text = text.Trim
arry = text.Split("=")
ListBox2.Items.Add(arry(1)) 'hier krijg ik volgende melding: Index was outside the bounds of the array.
ListBox1.Items.Add(arry(0))
Loop
objReader.Close()
End Sub
Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Click
Dim x As Integer
x = ListBox1.SelectedIndex
txtOmgekeerde.Text = ListBox2.Items.Item(x)
End Sub
Private Sub ListBox2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.Click
Dim x As Integer
x = ListBox2.SelectedIndex
txtOmgekeerde.Text = ListBox1.Items.Item(x)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles schrijven.Click
Dim dictionary As String = "C:\Documents and Settings\Eigenaar\Bureaublad\dictionary.txt"
Dim objWriter As New System.IO.StreamWriter(dictionary, True)
Dim arry(1) As String
Dim text As String
arry(0) = TextBox1.Text.Trim
arry(1) = TextBox2.Text.Trim
text = text.Join("=", arry) 'met het deel na de = krijg ik volgende foutmelding:Warning 1 Access of shared member, constant member, enum member 'or nested type through an instance; qualifying expression will not be evaluated.
objWriter.Write(vbNewLine, text)
objWriter.Close()
MsgBox("gelukt")
'hier wordt er nooit naar de textfile geschreven.
End Sub
End Class
Wie kan mij helpen? Het moet niet de volledige oplossing zijn hoor, ik snap alleen niet wat ik mis doe. Alvast bedankt voor de antwoorden.
Met vriendelijke groeten,
Dieter