473,412 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,412 software developers and data experts.

Hi For Loop Problems:

72
Hi there can somebody tell how can will i be able to shorten my code: coz i think the code that i have is very redundant, can someone help me with this, i just want to do it in a single for loop.

Here's my code:

Expand|Select|Wrap|Line Numbers
  1. 'Time Connection
  2. If rs.State = adStateOpen Then rs.Close
  3.        rs.Open "Select * from [Time]", cnn, adOpenKeyset, adLockOptimistic
  4.     While rs.EOF <> True
  5.         For x = 0 To 11
  6.          frmMain.Combo1(x).AddItem rs.Fields("Time").Value
  7.         Next x
  8.      rs.MoveNext
  9.     Wend
  10. 'Time Connection
  11.  
  12. 'Room Connection
  13. If rs.State = adStateOpen Then rs.Close
  14.        rs.Open "Select * from [ROOMS]", cnn, adOpenKeyset, adLockOptimistic
  15.   While rs.EOF <> True
  16.     For x = 0 To 11
  17.          frmMain.Combo2(x).AddItem rs.Fields("ROOM").Value
  18.     Next x
  19.   rs.MoveNext
  20.   Wend
  21. 'Room Connection
  22.  
  23. 'Days Connection
  24. If rs.State = adStateOpen Then rs.Close
  25.        rs.Open "Select * from [DAYS]", cnn, adOpenKeyset, adLockOptimistic
  26.   While rs.EOF <> True
  27.     For x = 0 To 11
  28.          Form2.Combo3(x).AddItem rs.Fields("DAYS").Value
  29.     Next x
  30.   rs.MoveNext
  31.   Wend
  32. 'Days Connection
  33.  
  34.  
i hope someone hav an idea on this, thank you in advance.
May 21 '07 #1
1 1072
Dököll
2,364 Expert 2GB
Hi there can somebody tell how can will i be able to shorten my code: coz i think the code that i have is very redundant, can someone help me with this, i just want to do it in a single for loop.

Here's my code:

Expand|Select|Wrap|Line Numbers
  1. 'Time Connection
  2. If rs.State = adStateOpen Then rs.Close
  3.        rs.Open "Select * from [Time]", cnn, adOpenKeyset, adLockOptimistic
  4.     While rs.EOF <> True
  5.         For x = 0 To 11
  6.          frmMain.Combo1(x).AddItem rs.Fields("Time").Value
  7.         Next x
  8.      rs.MoveNext
  9.     Wend
  10. 'Time Connection
  11.  
  12. 'Room Connection
  13. If rs.State = adStateOpen Then rs.Close
  14.        rs.Open "Select * from [ROOMS]", cnn, adOpenKeyset, adLockOptimistic
  15.   While rs.EOF <> True
  16.     For x = 0 To 11
  17.          frmMain.Combo2(x).AddItem rs.Fields("ROOM").Value
  18.     Next x
  19.   rs.MoveNext
  20.   Wend
  21. 'Room Connection
  22.  
  23. 'Days Connection
  24. If rs.State = adStateOpen Then rs.Close
  25.        rs.Open "Select * from [DAYS]", cnn, adOpenKeyset, adLockOptimistic
  26.   While rs.EOF <> True
  27.     For x = 0 To 11
  28.          Form2.Combo3(x).AddItem rs.Fields("DAYS").Value
  29.     Next x
  30.   rs.MoveNext
  31.   Wend
  32. 'Days Connection
  33.  
  34.  
i hope someone hav an idea on this, thank you in advance.
Hey, darrel!

Is it necessary to have Combo3 on a different form, why not a frame within the same form. That should help reduce the code....
Jun 3 '07 #2

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

Similar topics

47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
2
by: Mr BigSmoke | last post by:
Hi everybody... I have an app that has to controll some ascii files every 10/30 seconds... I was planning to have an GUI using wxpython. The problems is that i wasn't able to manage my application...
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
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.