Results 1 to 10 of 10

Thread: [RESOLVED] looping variable issue

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Resolved [RESOLVED] looping variable issue

    Code:
            For i = 0 To ListBox1.Items.Count - 1
                For a As Integer = 0 To stringname(30)
                    stringname(a) = ListBox1.Items(i).ToString
                    If a > ListBox1.Items.Count Then
                        Exit For
                    End If
                    stringname(a) = MessageTransposition(stringname(a), True)
                Next
            Next
    That is my looping code which works fine other than it doesn't increase the value of "a" every loop. "a" is always = 0. I am very new to loops (been messing around with them for an hour maybe two) so I don't know why it doesn't increase. I thought it had to cause it is a loop but really wouldn't know. So if there is anyone out there who can help me please feel free to speak up.

    Thank you.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: looping variable issue

    That code doesn't make too much sense I'm afraid, at least not to me. I think that you need to describe what it is that you're trying to achieve.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: looping variable issue

    what is it supposed to do?

    what is the value contained in stringname(30)?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: looping variable issue

    Code:
            For i = 0 To ListBox1.Items.Count - 1
                For a As Integer = 0 To stringname(30)
                    stringname(a) = ListBox1.Items(i).ToString
                    If a > ListBox1.Items.Count Then
                        Exit For
                    End If
                    stringname(a) = MessageTransposition(stringname(a), True)
                Next
            Next
    The first line starts the loop that gets the items in a listbox.

    Code:
    For i = 0 To ListBox1.Items.Count - 1
    The second line starts the loop for setting the value of the item to stringname(0-30)
    Code:
    For a As Integer = 0 To stringname(30)
    the third line is the line that sets stringname(a) to = the the text value of the current item
    Code:
    stringname(a) = ListBox1.Items(i).ToString
    the if then statement checks to see if a is greater than the number of items in the listbox. if it is it exits the loop.
    Code:
    If a > ListBox1.Items.Count Then
                        Exit For
                    End If
    the next line calls the decryption/encryption function and gives it the value of stringname(a). when it gets the encrypted data back as MessageTransposition then it sets stringname(a) to = MessageTransposition
    Code:
    stringname(a) = MessageTransposition(stringname(a), True)
    the problem again is that the value of a doesn't go up. hope i have mad it as clear as i can.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: looping variable issue

    vb Code:
    1. For a As Integer = 0 To stringname(30)

    shouldn't that be

    vb Code:
    1. For a As Integer = 0 To 30

    ???

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: looping variable issue

    Quote Originally Posted by .paul.
    what is it supposed to do?

    what is the value contained in stringname(30)?
    I am using a listbox to save a playlist for a media player I am making.

    The variable stringname(30) should be holding listbox items.But only stringname(0) is holding the data. by that i mean it wont push the next set of data into stringname(1). It keeps it all in stringname(0). That is how i know "a" doesn't increase and when i debuged it it always = 0.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: looping variable issue

    Quote Originally Posted by .paul.
    vb Code:
    1. For a As Integer = 0 To stringname(30)

    shouldn't that be

    vb Code:
    1. For a As Integer = 0 To 30

    ???
    yup changed that around and it worked. but now "i" is not increasing.
    i believe that it has something to do with the loop order because i have a breakpoint set on the first line of code i showed you earlier and they breakpoint doesn't go off so it is not getting run at all.
    Last edited by bagstoper; May 25th, 2008 at 08:54 AM.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: looping variable issue

    wouldn't this do the job?

    vb Code:
    1. For i = 0 To ListBox1.Items.Count - 1
    2.      stringname(i) = MessageTransposition(ListBox1.Items(i).ToString, True)
    3. Next

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: looping variable issue

    Quote Originally Posted by .paul.
    wouldn't this do the job?

    vb Code:
    1. For i = 0 To ListBox1.Items.Count - 1
    2.      stringname(a) = MessageTransposition(ListBox1.Items(i).ToString, True)
    3. Next
    i think it might let me try it.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: looping variable issue

    yes this works. it is encrypted and saved to the file thanks so much for your help. would rate you twice but sadly i can't. thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width