Loop problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Werner
    New Member
    • Jul 2006
    • 4

    Loop problem

    Public AtendanceName() As String 'Array to store names
    Public ix As Integer
    Public i As Integer



    Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnSave.Click


    'Loop to load names into Array


    ix = 1
    i = 0

    For i = 0 To ix = 1

    AtendanceName(i x) = txtAname.Text
    ix = ix + 1
    i = i + 1

    Next i

    Please Help me. This is what i think but it doesnt work.
    I want the loop to load a different tname in the array with each click of the btnSave.

    After that I want to display all the loaded names inside a richtextbox with a loop.
    I imagine it will work the same as the load.
    I just cant get it to work. I'll propably laugh at the sullotion but i cant seem to see it.

    Thank you all!! :confused:
  • axas
    New Member
    • Jul 2006
    • 32

    #2
    Every time you click the save button, you want to save the contents of the text box?
    That is you want to do?

    Comment

    • Enyi
      New Member
      • Jul 2006
      • 38

      #3
      This is how i would approach saving the names:


      ' FORM LEVEL VARIABLES
      'Array to store names
      Public AtendanceName() As String

      ' Set to 0 for first position in array, this is the loop counter
      Public i As Integer = 0

      Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles btnSave.Click

      ' Add name in array
      AtendanceName(i ) = txtAname.Text

      ' Increase count by 1
      i += 1

      End Sub
      Last edited by Enyi; Jul 28 '06, 09:42 AM. Reason: Making easier to read code

      Comment

      • Elena
        New Member
        • Jul 2006
        • 3

        #4
        you don't need to increase i (i = i + 1). In For loop, Next statement does that for you

        For i = 0 To AtendanceName.L ength-1

        AtendanceName(i ) = txtAname.Text

        Next

        Comment

        Working...