Converting A Do While Loop To A For Next Loop?
Sep 29, 2011How would I convert this Do While loop to a For...Next loop? I can't figure it out.
intCount = 0
Do While intCount < 50
lstOutput.Items.Add(intCount)
intCount += 1
Loop
How would I convert this Do While loop to a For...Next loop? I can't figure it out.
intCount = 0
Do While intCount < 50
lstOutput.Items.Add(intCount)
intCount += 1
Loop
Makes the following statement about the code below:
**"The computer evaluates the loop condition in the Do...Loop statment to determine whether the loop instructions should be processed. In this case, the inputsales <> String.Empty condition compares the contenst of the input sales variable to the String.Empty value. As you know the String.Empty value represents a zero length, or empty, string if the inputsales variable is empty, the loop condition evaluates to True and the computer process the loop instructions. *If on the other hand the inputsales variable is not empty, the loop condition evaluates to false and the computer skips over the loop instructions.
Based on the code I think it is the opposite: ...that while the inputsales value is not empty it should evaluate to true and process the loop and if it is empty it should evaluate to false and skip the loop?
See below.
Option Explicit On
Option Strict On
Imports System.Globalization
[CODE]...
I know I am missing the obvious. I would like a label to show how many cycles in loop are left.
[Code]...
I am constructing a program, i am new to Visual Basic, but i have past programming experience. I was wondering if anyone knew how to form a loop that could...lets say calculate the answer when two numbers are added together,and it would repeat this thousands of times, etc. And if there is a way, would it be possible to calculate the time taken to complete this loop.
View 5 RepliesI have written a function that gets the alexa ranking of a given url, now this function works perfectly but I want to loop through a ListView of urls and grab the alexa rank of each item (url) with my function.The code works great if I put a MessageBox in the loop to test that the function is returning a value but when I remove the MessageBox the loop does not work.I need it to loop through adding each result without a MessageBox stop in each loop.
vb
For Each Item In ListView1.Items
Dim result As Integer
result = GetAlexaRank(Item.Text)
[code].....
So I made a simple patform game where the player has to jump quickly while the platforms move to the bottom of the screen, as to not touch the bottom of the screen. But, I need to know how to create a loop to loop the locations of the platform. This means that after twenty or so platforms, the same platforms come up again, so that the player will have an "endless" game. I've declared all the platform's locations relative to the location of the first repeating platform:
[Code]...
I assigned an integer as 1, and looped my program using:[code]I can recieve the packets without looping, but once i loop, i receive nothing.
View 29 RepliesI have this little application that runs a SQL query works great, now I want to have a Start Button run the and display results then System.Threading.Thread.Sleep(300 * 1000) for 5 min then run again and display results and loop till I buttonstop_click. unsure if the sleep is the best method.
[Code]...
I am new to VB programming. I have the following code. When I execute my program only the last value from the loop is displayed in the label. I do write my code so that all of the values (years 1 to 5) show up in the label?
[Code]...
I'm completely new to working with more than one thread at a time but I've been reading up on backgroundworker quite a bit today. I get the general idea and think I could use it ok if it weren't for the fact I have a loop in a loop and I don't think they could be run inside a single thread together
View 4 RepliesHow do you convert a loop to a for loop
View 5 RepliesDim count As Integer
For count = 1 To 10 Step 1
Dim But+count As New Button
myButton+count.Width = 100*count
[code]....
Dim But+count As New Button => How to make it work
I'm slowly learning about loops. I have a couple of questions
1) When a condition is being tested.. what does that mean? I don't understand the "condition" word.
2) What is the difference between a loop that never ends and a loop that ends?
I have the code for the loop that ends and the loop that never ends. I can see the difference in the code, but I don't understand what is making it different. Here is the code below.
[code]...
I use the following code to add a row to an existing table
Dim newLineRow As DataRow = dsAccountDetails.Tables("Ph").NewRow()
newLineRow("Service TN") = "test"
dsAccountDetails.Tables("Ph").Rows.Add(newLineRow)
When I run the code it adds a single row to my table just like I want it to. However, when I put it in a loop it errors and tells me that the row already exists. The number of rows is always changing and I want to build the table from arrays. Why isn't the following working?
Dim a As Integer = 0
Dim b as integer= 5
For a = 0 to b
dsAccountDetails.Tables("Ph").Rows.Add(newLineRow)
Next
Currently, lets say that I have this code:
While r <> "HI"
r = RandomStringGenerator(1)
time = time + 1[code]....
how can I make it so that i can say basically this:
While r <> "HI" Or While r <> "BY"
r = RandomStringGenerator(1)
time = time + 1[code].....
But it still doesn't work! What's up with this?
Why does any app I make use 50% CPU while in a loop, even if the loop is doing simple evaluations, I've added Application.DoEvents() which stops the application hanging, but 50% is rediculous, what gives?
View 10 RepliesI have got this far and if you run it, it will do what you ask. Now when I type in 99999 or -99999 it will not end. Can someone tell me what I am doing wrong. I am suppose to loop until a sentinel value of -99999 is enter for previous meter reading.[code]...
View 2 RepliesI am working in VB 2008, Like vb 6.0 I used 'Do Until' loop in record set. I am now using 'For Loop' command for moving record in a table in vb 2008. But I want to use 'Do Unitl' Loop in record set moving record pointer to next record. Is it possible. If possible please show me with example.
View 4 RepliesI have a function , inside got three row and 3 column now i want to loop the data ....to display out. [code] now i want to check for the if in first row, then the price set to 0.00 else maintain original price.
View 3 RepliesI have the following code that I would like to get working, but for some reason, it keeps giving me the wrong output, and I wonder if anyone on the list might be able to help me fix it. [code] What this code is supposed to do, I am trying to achieve, is to change it so that I could use pagination with it. However, the problem with this code right now is that the ID's are generated, but iterates over the songs with duplicate entries, like:
1 Hello
2 Hello
1 Cool
2 Cool
Is it possible if I could have code above only get this to print out?
I am making another software these days it has a for loo. and when i debug the program it gave an error to me.. i read it and i a knew the solution but when i put the else condition i have to end my for loop how could i do it?
View 1 RepliesFor a console app, inside a loop I want to check for user input and if not correct, stay in the current loop until the user gets it right.In other words, I want to keep the loop from moving onto the next iteration until the desired entry is made.[code]
View 1 Repliesgot this code:
Dim i As Integer = 90
Dim REY As String
Do
[code].....
The program I have to write has to 1. Calculate and display the sum of 4 + 8 + 12 + 16 + ... + 204 + 208 2. Calculate and display 7! (the factorial of 7) 3. Display the results of your calculation on the console like this: Result A = 5512, Result B = 5040.I need to calculate and display the sum of 4 + 8 + 12 + 16 + ... + 204 + 208 ( the answer is 5512) but i need the program to do it.I also need to do it using a for next loop. So how would I go about doing that?The next thing I need to do is calculate and display 7! (the factorial of 7) The answer is 5040?
Module Module1
Sub Main()
Dim count2 As Integer = 7
For factorial = count2 To 1 Step -1
[code]....
Dim Temp() As String, Result As String, HTMLCode As String
HTMLCode = t.Text
Temp = Split(HTMLCode, "/view/")
Temp = Split(Temp(1), "/")
Result = Temp(0)
l.Items.Add(Result)
I don't know how to make a for each loop for this code... What i need is to get the text between "/view/" and "/", which it already does. But it only results in 1 string. I need it to find all the lines that contain "/view/" and end with "/" and extract the text/numbers between them. How do I do that ?
i need to break out of an inner loop and i've been advised that exit loop is not the best way to do so. So i've thought of another way to do so, i want to get the value within the if statement, but it doesnt appear to be working properly.
[Code]...
You see that i'm using Bavailable to try and break out of the loop to get the value pos in the instance of one of these if's conditions are returned true?
I have a SQLite database that I wish to read records from and execute a piece of code against each record.I am using a While loop with a Try Catch INSIDE it...Code is as follows:-
result = slcom.ExecuteReader()
'TODO: There is a problem with this while loop whereby if an ex is caught the connection
' to the database is closed.
While result.Read
[code]....
The problem is, once the Try block is entered and an ex is caught, the next iteration of the while loop fails, as it seems the minute an ex is caught the connection to the SQLite database is closed, eventhough the connection properties state that it is open.
I have a label who's text is determined by looping through a listbox upon a click event. I would like to have a timer loop through the listbox (... to set the label's text) if the button is not pressed in time ('x' seconds).
View 3 RepliesBelow is the code for a linked list search I have tried to implement in to searching through each of the elements of htmlelements .For some reason If element.InnerText = (item) will only work if if is only a string ("example") .Are there any other ways of Implementing the for each loop to search through my item linked list?
Original code for searching for 1 string
Private Sub block()
Dim elements As HtmlElementCollection = webBrowser.document.All
Dim word_found As Boolean
word_found = False
[CODE]...
This is the Loop for item I have tried to implement but is not working ,because of the for each loop .The value of element.Innertext = "" or null when I try to use one of the linked list item[If element.InnerText = (item)] is used and only have a value when a string is used to [If element.InnerText = (google)]
Private Sub block()
Dim elements As HtmlElementCollection = webBrowser.document.All
Dim word_found As Boolean
word_found = False
Dim item As LinkedListItem = words.Head
[CODE]...
I have designed an app in vb.net 2005 that at one point adds and loops over about 500k list in listbox about.
When adding these items to the listbox, the app freezes for about 5-10 minutes, then when looping over the items, processing them, the app also freezes for the same time. Am loading the data from a text file
How can I make my application responsive during loops? should I use a queue to process the list? what is the messagequeue control for?