Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42486

VS 2010 Parallel arrays[beginner help]

$
0
0
I'm trying to code an application that displays a name corresponding to a letter entered into the text box. I think I'm pretty close, but it's still not working. I just started programming so go easy on me please :) Here is the code I have so far. I will attach a picture of my interface. I have to get this done tonight so I'd really appreciate help. Thanks


Public Class frmMain

' declare class-level array
Dim strletters(4) As String
Dim food(4) As String
Dim animal(4) As String




Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub txtLetter_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLetter.KeyPress
' allows the text box to accept specific letters and the Backspace key

strletters(0) = "A"
strletters(1) = "B"
strletters(2) = "C"
strletters(3) = "G"
strletters(4) = "K"

If e.KeyChar <> "A" AndAlso e.KeyChar <> "a" AndAlso
e.KeyChar <> "B" AndAlso e.KeyChar <> "b" AndAlso
e.KeyChar <> "C" AndAlso e.KeyChar <> "c" AndAlso
e.KeyChar <> "G" AndAlso e.KeyChar <> "g" AndAlso
e.KeyChar <> "K" AndAlso e.KeyChar <> "k" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub

Private Sub txtLetter_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLetter.TextChanged
lblName.Text = String.Empty
End Sub

Private Sub btnFood_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
food(0) = "Apple"
food(1) = "Banana"
food(2) = "Carrot"
food(3) = "Grape"
food(4) = "Kiwi"

End Sub

Private Sub btnFood_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFood.Click
For x = 0 To 4
strletters(x) = food(x)
lblName.Text = food(x)

Next

End Sub

Private Sub btnAnimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnimal.Click

animal(0) = "Antelope"
animal(1) = "Bear"
animal(2) = "Camel"
animal(3) = "Goat"
animal(4) = "Kangaroo"

For x = 0 To 4
strletters(x) = animal(x)
lblName.Text = animal(x)
Next
End Sub
End Class
Attached Images
 

Viewing all articles
Browse latest Browse all 42486

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>