473,405 Members | 2,294 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,405 software developers and data experts.

Need alternative to 6 nested for loops

Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?
Sep 24 '08 #1
5 3679
Hola ElPresidente,

Well, I think you will need to supply more clear details than what you have
given.

Where does the data come from? Employee Division, etc comes from that
single file? If so what are you putting a batch number on?

"ElPresidente" <ch*************@gmail.comwrote in message
news:57**********************************@34g2000h sh.googlegroups.com...
Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?

Sep 24 '08 #2
Hi,

the first thing that comes into my mind is to create a datasource to the
Excel file and then set it as the datasource of a datagridview and use the
"select" method of the datagridview to pull out the information you need.

Use Excel as DataSource:
http://www.codeproject.com/KB/vb/Exc...nectivity.aspx

Uli
"ElPresidente" <ch*************@gmail.comschrieb im Newsbeitrag
news:57**********************************@34g2000h sh.googlegroups.com...
Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?
Sep 25 '08 #3
Hi again,

just as I sent the answer off I had another idea. If you dont need the
visual part of the datagridview you also could use a datatable object which
creates a "virtual database" in your memory.

Uli

"ElPresidente" <ch*************@gmail.comschrieb im Newsbeitrag
news:57**********************************@34g2000h sh.googlegroups.com...
Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?
Sep 25 '08 #4
On Sep 24, 2:22*pm, ElPresidente <chickenparme...@gmail.comwrote:
Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?
We're going to need more information. Can you post some code?
Sep 25 '08 #5
Hi,

I tested this today, for about 1000000 rows 100 times in a loop there was
needed 5 seconds, therefore what do you mean with slow, because some people
call this slow. Of course was this not done in Excel, but you can set put
the rows first in a OleDB DataSet table. (Like already mentioned in this
message thread)

I don't know of course how fast your python solution was?

Cor

"ElPresidente" <ch*************@gmail.comschreef in bericht
news:57**********************************@34g2000h sh.googlegroups.com...
Now that I have your attention haha...

I have this weekly file that contains several hundred invoices that
need to be given batch letters in according to the following
hierarchy.

Employee -Division -Customer -Product Type -Expense Code

I had previously programmed a working version in Python that
successfully did this by putting those 5 categories into 5 nested for
loops with a 6th for loop to iterate through all the Excel rows. If
the row didn't fit the criteria, it was skipped over. When there were
no rows left, it would cycle the parent for loop, increment a batch
letter and try again.

While this executed fast in Python, in VB.Net it's bogging down
heavily. There has to be a better way for me to write this code. Any
suggestions?
Sep 26 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
9
by: Gregory Petrosyan | last post by:
I often make helper functions nested, like this: def f(): def helper(): ... ... is it a good practice or not? What about performance of such constructs?
10
by: pcnerd | last post by:
I'm a VB.NET newbie. I've created a program that plots pixels at random on the form. I have a 19" LCD monitor with a resolution set to 1280 by 1024. If you do the math, that means that there are...
5
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Could someone give me a simple example of nested scope in C#, please? I've searched Google for this but have not come up with anything that makes it clear. I am looking at the ECMA guide and...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
13
by: Fredrik Lundh | last post by:
Patrol Sun wrote: so why exactly are you trying to nest 20 or 100 for-in loops? </F>
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.