473,717 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using arrays to simplify this code

63 New Member
Is there was a better way to do the following code that is currently in my project? Thanks
Expand|Select|Wrap|Line Numbers
  1. Dim db As ADODB.Connection
  2.  
  3. Set db = New ADODB.Connection
  4.  
  5. db.CursorLocation = adUseClient
  6.  
  7. db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Scheduling\AAGTC_Scheduling.mdb;"
  8.  
  9. Dim adoprimaryrs1 As ADODB.Recordset
  10.  
  11. Set adoprimaryrs1 = New ADODB.Recordset
  12.  
  13. Dim strSQL As String
  14.  
  15. 'SQL select statement
  16.  
  17. strSQL = "SELECT [Avon Park Air Scheduling Post Data].Canceled FROM [Avon Park Air Scheduling Post Data] WHERE Document_ID = " & "'" & Me.txtDocumentID.Text & "'"
  18.  
  19. 'Execute the first SQL statement to find conflicts, if any exist
  20. adoprimaryrs1.Open strSQL, db, adOpenStatic, adLockOptimistic
  21.  
  22. If adoprimaryrs1.BOF = False And adoprimaryrs1.EOF = False Then
  23.  
  24. If adoprimaryrs1!canceled <> "" Then
  25.  
  26. Dim Output1 As String
  27. Dim Output2 As String
  28. Dim Output3 As String
  29. Dim Output4 As String
  30. Dim Output5 As String
  31. Dim Output6 As String
  32. Dim Output7 As String
  33. Dim Output8 As String
  34.  
  35. inputstring = adoprimaryrs1!canceled
  36. On Error Resume Next
  37. Output1 = Split(inputstring, " ")(0)
  38. Output2 = Split(inputstring, " ")(1)
  39. Output3 = Split(inputstring, " ")(2)
  40. Output4 = Split(inputstring, " ")(3)
  41. Output5 = Split(inputstring, " ")(4)
  42. Output6 = Split(inputstring, " ")(5)
  43. Output7 = Split(inputstring, " ")(6)
  44. Output8 = Split(inputstring, " ")(7)
  45.  
  46. 'Trap value for Output1
  47. If Output1 = "Aircraft_1_Canceled" Then
  48.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  49. End If
  50.  
  51. If Output1 = "Aircraft_2_Canceled" Then
  52.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  53. End If
  54.  
  55. If Output1 = "Aircraft_3_Canceled" Then
  56.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  57. End If
  58.  
  59. If Output1 = "Aircraft_4_Canceled" Then
  60.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  61. End If
  62.  
  63. If Output1 = "Aircraft_5_Canceled" Then
  64.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  65. End If
  66.  
  67. If Output1 = "Aircraft_6_Canceled" Then
  68.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  69. End If
  70.  
  71. If Output1 = "Aircraft_7_Canceled" Then
  72.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  73. End If
  74.  
  75. If Output1 = "All_Canceled" Then
  76.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  77. End If
  78.  
  79.  
  80. 'Trap value for Output2
  81. If Output2 = "Aircraft_1_Canceled" Then
  82.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  83. End If
  84.  
  85. If Output2 = "Aircraft_2_Canceled" Then
  86.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  87. End If
  88.  
  89. If Output2 = "Aircraft_3_Canceled" Then
  90.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  91. End If
  92.  
  93. If Output2 = "Aircraft_4_Canceled" Then
  94.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  95. End If
  96.  
  97. If Output2 = "Aircraft_5_Canceled" Then
  98.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  99. End If
  100.  
  101. If Output2 = "Aircraft_6_Canceled" Then
  102.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  103. End If
  104.  
  105. If Output2 = "Aircraft_7_Canceled" Then
  106.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  107. End If
  108.  
  109. If Output2 = "All_Canceled" Then
  110.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  111. End If
  112.  
  113.  
  114. 'Trap value for Output3
  115. If Output3 = "Aircraft_1_Canceled" Then
  116.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  117. End If
  118.  
  119. If Output3 = "Aircraft_2_Canceled" Then
  120.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  121. End If
  122.  
  123. If Output3 = "Aircraft_3_Canceled" Then
  124.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  125. End If
  126.  
  127. If Output3 = "Aircraft_4_Canceled" Then
  128.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  129. End If
  130.  
  131. If Output3 = "Aircraft_5_Canceled" Then
  132.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  133. End If
  134.  
  135. If Output3 = "Aircraft_6_Canceled" Then
  136.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  137. End If
  138.  
  139. If Output3 = "Aircraft_7_Canceled" Then
  140.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  141. End If
  142.  
  143. If Output3 = "All_Canceled" Then
  144.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  145. End If
  146.  
  147. 'Trap value for Output4
  148. If Output4 = "Aircraft_1_Canceled" Then
  149.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  150. End If
  151.  
  152. If Output4 = "Aircraft_2_Canceled" Then
  153.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  154. End If
  155.  
  156. If Output4 = "Aircraft_3_Canceled" Then
  157.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  158. End If
  159.  
  160. If Output4 = "Aircraft_4_Canceled" Then
  161.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  162. End If
  163.  
  164. If Output4 = "Aircraft_5_Canceled" Then
  165.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  166. End If
  167.  
  168. If Output4 = "Aircraft_6_Canceled" Then
  169.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  170. End If
  171.  
  172. If Output4 = "Aircraft_7_Canceled" Then
  173.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  174. End If
  175.  
  176. If Output4 = "All_Canceled" Then
  177.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  178. End If
  179.  
  180. 'Trap value for Output5
  181. If Output5 = "Aircraft_1_Canceled" Then
  182.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  183. End If
  184.  
  185. If Output5 = "Aircraft_2_Canceled" Then
  186.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  187. End If
  188.  
  189. If Output5 = "Aircraft_3_Canceled" Then
  190.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  191. End If
  192.  
  193. If Output5 = "Aircraft_4_Canceled" Then
  194.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  195. End If
  196.  
  197. If Output5 = "Aircraft_5_Canceled" Then
  198.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  199. End If
  200.  
  201. If Output5 = "Aircraft_6_Canceled" Then
  202.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  203. End If
  204.  
  205. If Output5 = "Aircraft_7_Canceled" Then
  206.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  207. End If
  208.  
  209. If Output5 = "All_Canceled" Then
  210.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  211. End If
  212.  
  213. 'Trap value for Output6
  214. If Output6 = "Aircraft_1_Canceled" Then
  215.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  216. End If
  217.  
  218. If Output6 = "Aircraft_2_Canceled" Then
  219.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  220. End If
  221.  
  222. If Output6 = "Aircraft_3_Canceled" Then
  223.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  224. End If
  225.  
  226. If Output6 = "Aircraft_4_Canceled" Then
  227.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  228. End If
  229.  
  230. If Output6 = "Aircraft_5_Canceled" Then
  231.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  232. End If
  233.  
  234. If Output6 = "Aircraft_6_Canceled" Then
  235.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  236. End If
  237.  
  238. If Output6 = "Aircraft_7_Canceled" Then
  239.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  240. End If
  241.  
  242. If Output6 = "All_Canceled" Then
  243.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  244. End If
  245.  
  246. 'Trap value for Output7
  247. If Output7 = "Aircraft_1_Canceled" Then
  248.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  249. End If
  250.  
  251. If Output7 = "Aircraft_2_Canceled" Then
  252.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  253. End If
  254.  
  255. If Output7 = "Aircraft_3_Canceled" Then
  256.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  257. End If
  258.  
  259. If Output7 = "Aircraft_4_Canceled" Then
  260.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  261. End If
  262.  
  263. If Output7 = "Aircraft_5_Canceled" Then
  264.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  265. End If
  266.  
  267. If Output7 = "Aircraft_6_Canceled" Then
  268.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  269. End If
  270.  
  271. If Output7 = "Aircraft_7_Canceled" Then
  272.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  273. End If
  274.  
  275. If Output7 = "All_Canceled" Then
  276.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  277. End If
  278.  
  279. 'Trap value for Output8
  280. If Output8 = "Aircraft_1_Canceled" Then
  281.    frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 1
  282. End If
  283.  
  284. If Output8 = "Aircraft_2_Canceled" Then
  285.    frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 1
  286. End If
  287.  
  288. If Output8 = "Aircraft_3_Canceled" Then
  289.    frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 1
  290. End If
  291.  
  292. If Output8 = "Aircraft_4_Canceled" Then
  293.    frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 1
  294. End If
  295.  
  296. If Output8 = "Aircraft_5_Canceled" Then
  297.    frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 1
  298. End If
  299.  
  300. If Output8 = "Aircraft_6_Canceled" Then
  301.    frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 1
  302. End If
  303.  
  304. If Output8 = "Aircraft_7_Canceled" Then
  305.    frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 1
  306. End If
  307.  
  308. If Output8 = "All_Canceled" Then
  309.    frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 1
  310. End If
  311.  
  312. End If
  313.  
  314. If Output1 = "" Then
  315.     frmEditCompletedFlightMissions.chkAircraft1Cancelled.Value = 0
  316. End If
  317.  
  318. If Output2 = "" Then
  319.     frmEditCompletedFlightMissions.chkAircraft2Cancelled.Value = 0
  320. End If
  321.  
  322. If Output3 = "" Then
  323.     frmEditCompletedFlightMissions.chkAircraft3Cancelled.Value = 0
  324. End If
  325.  
  326. If Output4 = "" Then
  327.     frmEditCompletedFlightMissions.chkAircraft4Cancelled.Value = 0
  328. End If
  329.  
  330. If Output5 = "" Then
  331.     frmEditCompletedFlightMissions.chkAircraft5Cancelled.Value = 0
  332. End If
  333.  
  334. If Output6 = "" Then
  335.     frmEditCompletedFlightMissions.chkAircraft6Cancelled.Value = 0
  336. End If
  337.  
  338. If Output7 = "" Then
  339.     frmEditCompletedFlightMissions.chkAircraft7Cancelled.Value = 0
  340. End If
  341.  
  342. If Output8 = "" Then
  343.     frmEditCompletedFlightMissions.chkCancelEntireEvent.Value = 0
  344. End If
  345.  
  346. End If
  347.  
  348. Set adoprimaryrs1 = Nothing
  349.  
  350. Set db = Nothing
  351.  
Apr 26 '07 #1
4 1080
Killer42
8,435 Recognized Expert Expert
Is there was a better way to do the following code that is currently in my project?
...
Yes. :)
Apr 26 '07 #2
Killer42
8,435 Recognized Expert Expert
Seriously, I'd say that the one biggest improvement you could make would be to use an array rather than a bunch of separate string variables. An array allows you to use a loop, which in effect applies the same processing to any number of elements, rather than writing the same code over and over for individual variables.

A simple example...
Expand|Select|Wrap|Line Numbers
  1. Dim MyString(1 To 10) As String
  2. Dim I As Long
  3.  
  4. ' Load some values into the array.
  5. For I = 1 To 10
  6.   MyString(I) = "Aircraft_" & Format(I) & "_Cancelled"
  7. Next
  8.  
  9. ' Print them out.
  10. For I = 1 To 10
  11.   Debug.Print "MyString(" ; Format(I); ") = "; MyString(I)
  12. Next
I won't go into greater detail for now, as my goal is to help you understand the subject, not to do the job for you.
Apr 26 '07 #3
keithsimpson3973
63 New Member
Thanks Killer42. That is a huge help. I am going to play with that for a day or 2 and see how far I can go. I just seem to be having a very difficult time understanding arrays, there process, their logic, and the mechanics of putting them into use. As always, I am in awe of your knowledge. Thanks again!
Apr 27 '07 #4
Killer42
8,435 Recognized Expert Expert
Yeah, arrays can be a little difficult to grasp at first. Well worth it though, as they are an extremely powerful concept.

...

I was trying to think of an analogy to help clarify it, but went completely blank. Anyway, you can probably finc tons of tutorials on the web.

But yes, playing around with them is probably a good way to develop and understanding of how they work.

Good luck.
Apr 28 '07 #5

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

Similar topics

12
4307
by: James | last post by:
Hi, Have posted before, but will simplify problem here. For original post go to http://forums.devshed.com/t80025/s.html I have setup 2 arrays like so in my one page script: $carers = array( array('names' => 'Carer 01', 'hours' => 8, 'remaining' => 8),
12
9191
by: Dave Theese | last post by:
Hello all, I'm in a poition of trying to justify use of the STL from a performance perspective. As a starting point, can anyone cite any benchmarks comparing vectors to plain old statically-declared arrays? I'll also be looking at the other STL containers later... Also, I'd appreciate any comments anyone has on the suitability of the little program below for comparing vectors and arrays. One obvious shortcoming is that it uses...
3
437
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length string that I sent into it. After working on Debugging the code I found two problems. One was in the statement fromEncrypt = New Byte(encrypted.Length) {} where both FromEncrypt and encrypted are both byte arrays and encrypted's length is 24....
3
2708
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h> #include<stdlib.h> int main(void) {
3
14727
by: Mike Scott | last post by:
What is the best way to index an array by an enum. Pascal has a nice feature in that arrays can be indexed by an enum, for example type ButtonType = ( Left, Middle, Right ) ; var buttons : array of Button ; ....
5
1638
by: $hiv..... | last post by:
hi, How to use Zero lengh Arrays.. I searched but could not get much information regarding this where Do i get links abt this
2
2003
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I am learning. My problem is this. I had sucessfully written a C code that worked ( with considerable speedup over the IDL version ) using an array size of 100x100. However, I am working towards making the array size closer to 300x300. Since I had...
19
248234
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect this data is essential to any developer. This article is a basic tutorial on how to user HTML Forms, the most common method of data collection. Assumptions - Basic HTML knowledge. - Basic PHP knowledge. HTML Forms A common and simple way of...
3
2010
by: iglpdc | last post by:
Hi, I need a template class taking several non-type arguments. Then I want to be able to pass these arguments to the constructor of another non- template class. So far I have this (I did some editing to simplify the thing): template<int const* rule_, double const* raw_oper_> struct A{
0
8823
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8719
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9348
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9202
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7981
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6648
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4478
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2545
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2120
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.