473,321 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Loop problem with array

I am using Visual Basic Express 2008.
I'm really new to this, so this one could sound really kind of a joke to you, but the thing I want to do is:
Have a text box (Textbox1) and I'd like by clicking a button to display the next array item starting from the first one, but actually it does only show the last one (comments(2)) everytime I click on the button. This is the code I added to my button:

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim comments(2) As String
comments(0) = "Some text1.."
comments(1) = "Some text2.."
comments(2) = "Some text3.."

For i = 0 To 2
TextBox1.Text = comments(i)
Next

End Sub
Mar 22 '11 #1

✓ answered by Guido Geurs

The For ...Next runs so fast trough the data that the textbox has no time to refresh, so you see only the last text.

If you want to see the text with a time interval, you have to ad a timer.

3 1302
Guido Geurs
767 Expert 512MB
The For ...Next runs so fast trough the data that the textbox has no time to refresh, so you see only the last text.

If you want to see the text with a time interval, you have to ad a timer.
Mar 22 '11 #2
Hi Alkis,

Try this code

TextBox1.Text = ""
For i = 0 To 2
TextBox1.Text = TextBox1.Text & vbcrlf & comments(i)
Next
Mar 1 '12 #3
why you need to loop if you need to show only 1 result without any comparison?

'declare a global varialble X
'As Integer

Dim X As Integer

Public Sub Button6_Click()
dim strStatements(2) as String
strStatements(0) = "statement 1"
strStatements(1) = "statement 2"
strStatements(2) = "statement 3"
if X > 2 Then
exit(0);
Else
Textbox1.Text=strStatements(X)
X += 1
End if
End Sub

'PS: your code is correct but..
'you forgot to put your looping variable in the Next function

'it should be like this "Next i"
Mar 17 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Hannu Tiitu | last post by:
Hi! I have a small problem with array and objects: $a = new A(); $b = new A(); $c = new A(); $d = new A(); $e = new A(); $ar = array($a, $c, $d);
3
by: John F. | last post by:
Hi all, I'm searching fulltime for days now, and I don't find the solution, so I'm thinking this is more a bug :( If i use following code in form&subforms:
13
by: Ian Tuomi | last post by:
Could anyone please tell me what is wrong with this code? Compiler error is: "parse error before '.' token" in lines 13-16. I tried searching the internet but all the reference guides etc. say It's...
3
by: forum | last post by:
Hi! what's the standard way for a "for" loop with float increments? Anton
2
by: The.Relinator | last post by:
Hello, I am unable to get the following piece of code to work as desired. The fields valuable seems to contain all values however the vaules variable only contains the first assignied with $values...
10
by: wd.jonsson | last post by:
Hmm, my while loop with "or" doesn't seem to work as I want it to... How do I tell the while loop to only accept "Y" or "y" or "N" or "n" input from the str(raw_input)? Thank's in advance! ...
14
by: ptq2238 | last post by:
Hi, I'm getting confused with arrays and hope someone can shed light on my code. I wrote this to try and learn about files and arrays as I thought if I could grab each element and place them into...
5
by: Ranmini | last post by:
Dear prob solver, i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the...
1
by: djpaul | last post by:
Hello, I'm trying to write to a listbox from an array. But i need the first 3 (0,1,2,3) indices of the array and then a VbCrLf I wrote this: Try Dim TextFile As String =...
2
by: getteddy | last post by:
hi i am working on array , i am facing a problem in comparing data base element with array element if not (objrs("namephase")=("despArray(ctr,0)+despArray(ctr,3)")) then or If...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.