I am getting an error that I cannot figure out. When I select a plant from the list, the MsgBox else event triggers and my fields are not filled in. It doesn't seem to be recognizing the filename because the message box unknown field just starts reading off each letter, one by one, of the file name.
I have tested to see if it can read the file by just dumping all the file contents into one box, instead of splitting it up, and that works, but not at all what I want it to do. I have tried to rewrite using StreamReader instead, but keep coming back to this since so far it makes more sense to me.
I have given an example of data from one of the .txt files after my code.
Any help would be appreciated.
Private Sub lstPlants_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstPlants.SelectedValueChanged
Dim plant As String
Dim infofile As String
lstPlants.Items.Add("Bee Balm")
lstPlants.Items.Add("Black Eyed Susan")
lstPlants.Items.Add("Bleeding Heart")
lstPlants.Items.Add("Garden Phlox")
lstPlants.Items.Add("Maltese Cross")
lstPlants.Items.Add("Purple Coneflower")
lstPlants.Items.Add("Siberian Iris")
lstPlants.Items.Add("Strawberry Foxglove")
lstPlants.Items.Add("Sunflower")
plant = lstPlants.SelectedItem
'plantImage = lstPlants.SelectedIndex & ".jpg"
infofile = plant & ".txt"
'Dim infofile As String = System.IO.Path.Combine(plant & ".txt")
If My.Computer.FileSystem.FileExists(infofile) Then
Dim info() As String = System.IO.File.ReadAllLines(infofile)
For Each line As String In infofile
If Trim(line) <> "" Then
Dim fields() As String = line.Split(":")
Select Case UCase(fields(0))
Case "COMMON"
lblCommonName.Text = fields(1)
Case "LATIN"
lblLatinName.Text = fields(1)
Case "DESCRIPTION"
lblDescription.Text = fields(1)
Case "COLOR"
lblColor.Text = fields(1)
Case "HEIGHT"
lblHeight.Text = fields(1)
Case "WIDTH"
lblWidth.Text = fields(1)
Case "ZONE"
lblZone.Text = fields(1)
Case "MOISTURE"
lblMoisture.Text = fields(1)
Case "LIGHT"
lblSun.Text = fields(1)
Case "CULTIVATION"
lblCultivate.Text = fields(1)
Case "PROPAGATION"
lblPropagation.Text = fields(1)
Case "DISEASE"
lblDiseases.Text = fields(1)
Case Else
MsgBox("Unknown field " & fields(0))
End Select
End If
Next
End If
End Sub
bee balm.txt file data:
COMMON: Bee Balm
LATIN: Monarda didyma
DESCRIPTION: Bee balm is a lovely perennial with bright flowers on sturdy stems that grow from fast creeping runners. The pointed oval leaves give Earl Grey tea its distinctive aroma and flavor.
COLOR: Tight heads of tubular red flowers are surrounded by a whorl of colored leafy bracts (modified leaves).
FLOWERING: Summer
HEIGHT: 2-4 feet
SPREAD: 2-3 feet
TEMP:
ZONE: 4-8
MOISTURE: Evenly moist, humus-rich soil. If plants dry out, the lower foliage will be shed.
LIGHT: Full sun to partial shade.
CULTIVATION: Plants spread quickly; divide every two to three years.
PROPAGATION: Divide in spring or fall. Sow seed indoors or outdoors in spring.
DISEASE: Powdery mildew causes white blotches on the foliage and may cover the entire plant. Thin the stems for good air circulation. Cut affected plants to the ground.
LANDSCAPE: Plant in formal or informal gardens. Bee balm's lovely flowers add brilliant color to the summer garden and are favored by hummingbirds.

New Topic/Question
Reply



MultiQuote





|