Josh

Josh

  • NA
  • 4
  • 0

total newb to VB, for loops and textboxes

Dec 30 2007 11:03 PM
thanks for bearing with a total newb - I've done some programmning before, but it was in college, in C++, and console only :). I'm teaching myself some VB.net, and am having trouble porting some of the concepts forward. I'm writing a practice program to help track my golf scores over time, and report on various statistics. It seems to encompass many of the techniques I might need at work (which is the ultimate goal for learning to code in VB). What I've got are 26 text boxes that I need to grab input from - 18 for the par of the hole, and 18 for my score on that hole. I'm struggling with how I can address each of the textboxes in an iterative manner - for humor, here's the current "get data" procedure ...


    Private Sub bAddScore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAddScore.Click
        Par(1) = tbH1P.Text
        Par(2) = tbH2P.Text
        Par(3) = tbH3P.Text
        Par(4) = tbH4P.Text
        Par(5) = tbH5P.Text
        Par(6) = tbH6P.Text
        Par(7) = tbH7P.Text
        Par(8) = tbH8P.Text
        Par(9) = tbH9P.Text
        Par(10) = tbH10P.Text
        Par(11) = tbH11P.Text
        Par(12) = tbH12P.Text
        Par(13) = tbH13P.Text
        Par(14) = tbH14P.Text
        Par(15) = tbH15P.Text
        Par(16) = tbH16P.Text
        Par(17) = tbH17P.Text
        Par(18) = tbH18P.Text

        Score(1) = tbH1S.Text
        Score(2) = tbH2S.Text
        Score(3) = tbH3S.Text
        Score(4) = tbH4S.Text
        Score(5) = tbH5S.Text
        Score(6) = tbH6S.Text
        Score(7) = tbH7S.Text
        Score(8) = tbH8S.Text
        Score(9) = tbH9S.Text
        Score(10) = tbH10S.Text
        Score(11) = tbH11S.Text
        Score(12) = tbH12S.Text
        Score(13) = tbH13S.Text
        Score(14) = tbH14S.Text
        Score(15) = tbH15S.Text
        Score(16) = tbH16S.Text
        Score(17) = tbH17S.Text
        Score(18) = tbH18S.Text
    End Sub

(no error checking or anything yet, I'm just getting started). I'm familiar with the looping syntaxes and usage, but getting the object names (tbHxS or tbHxP) to resolve properly has stumped me. (anything prefaced by "tb" is a textbox on the form, and score() and par() are int arrays, 18 elements each).

If anyone could suggest a manner of constructing a FOR loop to do this, or perhaps a better way to attack the problem as a whole (lots of inputs needed at one time), I would be MUCH appreciative. Thank you!

-Josh

Answers (3)