[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.
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.
Re: looping variable issue
what is it supposed to do?
what is the value contained in stringname(30)?
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.
Re: looping variable issue
vb Code:
For a As Integer = 0 To stringname(30)
shouldn't that be
vb Code:
For a As Integer = 0 To 30
???
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.
Re: looping variable issue
Quote:
Originally Posted by .paul.
vb Code:
For a As Integer = 0 To stringname(30)
shouldn't that be
vb Code:
For a As Integer = 0 To 30
???
yup changed that around and it worked. but now "i" is not increasing. :mad:
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.
Re: looping variable issue
wouldn't this do the job?
vb Code:
For i = 0 To ListBox1.Items.Count - 1
stringname(i) = MessageTransposition(ListBox1.Items(i).ToString, True)
Next
Re: looping variable issue
Quote:
Originally Posted by .paul.
wouldn't this do the job?
vb Code:
For i = 0 To ListBox1.Items.Count - 1
stringname(a) = MessageTransposition(ListBox1.Items(i).ToString, True)
Next
i think it might let me try it.
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.