473,383 Members | 1,892 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,383 software developers and data experts.

using for loop

9
hi i am a new user to visual basic which i find very interesting but one small problem stuck out behind me using for loop
i get confused with the following code please help at(nvnrai8@gmail.com)

private sub command1_click()
for n=0 tolist1.listcount-1
if list1.selected(n) =true then
list2.additem list1.list(n)
list1.selected(n)=false
end if
next n
end sub

what does next n work here and where it goes while working and also how for loops works here.this is a program which adds list1 items to list2 box

if anyone has the solution please respond back....
Jan 28 '10 #1
4 1999
vb5prgrmr
305 Expert 100+
n, in this case is a variable that holds the incremented value from start to finish...

For n = startvalue to finishvalue

For n = 0 to list1.listcount - 1

next n 'here is where n = n + 1

A for loop is normally used to walk through a list or collection of items that are sequentially numbered, either forward or backward, but it does have a step option that allows you to change that behavior...

for example, your code could be modified to walk backwards from listcount - 1 to 0 by the use of the step keyword and a minus 1 value...
Expand|Select|Wrap|Line Numbers
  1. For n = List1.ListCount -1 To 0 Step - 1
  2.   '...
  3. Next n
  4.  
Or if the occasion arises, you can increment by two or three or whatever by use the the step keyword and a value...
Expand|Select|Wrap|Line Numbers
  1. For n = 10 To 100 Step 10
  2.   '...
  3. Next n
  4.  
or backwards...
Expand|Select|Wrap|Line Numbers
  1. For n = 100 To 10 Step - 10
  2.   '...
  3. Next n
  4.  


Good Luck
Jan 28 '10 #2
navda
9
hi thanks a lot for answering me back....
well i still have some doubts with previous solution

private sub command1_click()
for n=0 tolist1.listcount-1
if list1.selected(n) =true then
list2.additem list1.list(n)
list1.selected(n)=false
end if
next n
end sub

ok i got the point about the incrementation of next n=n+1.but i want to know that
if n=0 means first index value of my list item and listcount means end value of my list item let it be 7 i.e, 6 by (list1.listcount-1)

well what does list1.selected(n)=true means here.... is it saying that the index value between 0 to 6 is correct, or a condition which checks that i have selected the index value between 0 to 6....please make me clear

as well i want to know if i select the items from list 1 having index value between 0 to 6 let it be index 3 and send it to list2.... then next n takes me to index 4 then index 5 then index 6(who does not respond and display any item name or send its value to list 2 because i have not selected those items)??? and if my loop condition ends the program ends and in the code as said (list1.selected(n)=false) makes my selected item false in list 1.

so what happens if i select the same item next time how does for loop react does it makes again the value of n=0 and start from the begining?will there be any flow of previous loop in next selection....???

is this the concept here of for loop...please explain me....



thanks looking forward...at(nvnrai8@gmail.com)
Feb 4 '10 #3
vb5prgrmr
305 Expert 100+
VB6.0 can be confusing when it comes to this because the counts of a lot of controls are one (1) based, meaning they start counting at 1, while references in control to the actual elements of the control are zero (0) based...

?Selected is the item in the control selected?...



Good Luck
Feb 4 '10 #4
Guido Geurs
767 Expert 512MB
dear,

attached is an example explaning how lists works.

hope this will help.

br,
Attached Files
File Type: zip Transfer list using indexes.zip (1.5 KB, 61 views)
Feb 4 '10 #5

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

Similar topics

3
by: Carlos Ribeiro | last post by:
As a side track of my latest investigations, I began to rely heavily on generators for some stuff where I would previsouly use a more conventional approach. Whenever I need to process a list, I'm...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
8
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
5
by: John Dumais | last post by:
Hello, I have been trying to figure out how to write an array of doubles (in this specific case) to a binary stream without using a loop. What I have been doing is... foreach(double d in...
13
by: Bev in TX | last post by:
We are using Visual Studio .NET 2003. When using that compiler, the following example code goes into an endless loop in the "while" loop when the /Og optimization option is used: #include...
9
by: George McCullen | last post by:
I have an Outlook 2003 using Exchange Server 2003 Public Contacts Folder containing 20,000 Contacts. I am writing a VB .Net 2003 program that loops through all the contacts in a "for each oCt in...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
1
by: Thiero | last post by:
Hi I posted s thread but did have any reply, I am a new programmer and really wants someone to help me on how to use TreeMap for this code cos I want to it to be able to handle the options from 6...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
3
by: Akira | last post by:
I noticed that using foreach is much slower than using for-loop, so I want to change our current code from foreach to for-loop. But I can't figure out how. Could someone help me please? Current...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.