Geraak er niet uit tijdens een oefening

Status
Niet open voor verdere reacties.

gieterke

Gebruiker
Lid geworden
22 apr 2008
Berichten
52
Ik ben al een tijdje aan het leren programmeren. Nu moet ik een oefening maken op Text files etc. Dit is de opdracht:
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
 
Heb je gedebugged? Zit er wel degelijk text in de variabele?

Code:
text = objReader.ReadLine

text = text.Trim

Werkt de split goed? Zijn er wel degelijk 2 delen in de string?

Code:
arry = text.Split("=")

Is de eerste lijn van het textvak een header?
 
Ik heb het gevonden. De fout zat hem in de naamgeving van de variabelen. dictonairy is een functie ofzo en ik wou dit als variabele gebruiken. Ben al een tijdje niet meer op dit forum geweest en daardoor vergeten aan te duiden dat het opgelost was. Toch bedankt voor het antwoord.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan