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

first highest / lowest before decrease/increase in high / low nos

2
I have the following the data in access 2003 database.

Expand|Select|Wrap|Line Numbers
  1.  sr No.  high    low        pline     dline   basetype   zonetype    
  2.    1    1146     1142       1124      1126        1         1
  3.    2    1136     1134       1128      1126        1         2
  4.    3    1137     1130       1129      1125        1         2
  5.    4    1147     1139       1131      1134        1         2
  6.    5    1131     1128       1128      1130        1         1
  7.    6    1135     1131       1129      1132        1         1
  8.    7    1138     1130       1132      1134        1         1
  9.    8    1149     1127       1134      1131        1         2
  10.    9    1147     1129       1136      1132        1         1
Now I wnat to find out first maximum high for each sr.no with zonetype 2 and first maximum low for each sr.no. with zonetype 1. for eg :
sr.No. 1 with zonetype 1 first low after the current record would be 1130 because next record low is 1139 which is greater than 1130 and of course in next record low is 1128 which will be ignored for sr.NO.1 since the first low is 1130 before increase in the low no. Similarly for sr.No.2 with zonetype 2, first high after the current record would be 1147 because in next record high is 1131 which is lower than 1147 and subsequent high of 1149 in sr.no.8 will be ignored and so on. Hence, my desired output will be

Expand|Select|Wrap|Line Numbers
  1. sr.No. zonetype  result  difference in sr.no.
  2.   1        1       1130   1-3=2 
  3.   2        2       1147   2-4=2 
  4.   3        2       1147   3-4=1 
  5.   4        2       1149   4-8=4  
  6.   5        1       1127   5-8=3
  7.   6        1       1127   6-8=2
  8.   7        1       1127   7-8=1
  9.   8        2       1147   8-9=1    
  10.  
I have the following vba, which is not giving the desired output. Can u help me correcting the vba. thanks in advance

Expand|Select|Wrap|Line Numbers
  1. Sub calMHIGHnN6()
  2.     Dim mydb As DAO.Database
  3.     Dim myRS As DAO.Recordset
  4.     Dim myCounter As Double
  5.     Dim mycurrenthigh As Double
  6.     Dim myprevioushigh As Double
  7.     Dim mycurrentlow As Double
  8.     Dim mypreviouslow As Double
  9.     Dim mydz As Integer
  10.     Dim mybase As Integer
  11.     Set mydb = CurrentDb
  12.     Set myRS = mydb.OpenRecordset("query14")
  13.  
  14. '   Loop through all records in table
  15.     myRS.MoveLast
  16.     myRS.MoveFirst
  17.     Do While Not myRS.EOF
  18.  
  19.         mydz = myRS("zonetype")
  20.         mybase = myRS("basetype")
  21.         mycurrentcd1 = myRS("pline")
  22.          mycurrentcd2 = myRS("dline")
  23.          mycurrenthigh = myRS("high")
  24.          mycurrentlow = myRS("low")
  25.          period_count = 0
  26. '   Check to see mfirst maximum high/low
  27.  
  28.             If mydz = 2 Then
  29.               If mycurrenthigh > myprevioushigh Then
  30.               myCounter = mycurrenthigh
  31.                       Else
  32.              If mycurrenthigh < myprevioushigh Then
  33.                  myRS.MoveNext
  34.                   myCounter = mycurrentcd1
  35.               End If
  36.             End If
  37.  
  38.             If mydz = 1 Then
  39.  
  40.               If mycurrentlow < mypreviouslow Then
  41.               myCounter = mycurrentlow
  42.  
  43.             Else
  44.              If mycurrentlow > mypreviouslow Then
  45.                 myRS.MoveNext
  46.  
  47.                        End If
  48.            End If
  49.            End If
  50.             End If
  51.  
  52.  '   Assgin counter value to the result
  53.            myRS.Edit
  54.          myRS.Fields("result") = myCounter
  55.  
  56.         myRS.Update
  57. '   Assign current number to previous number and go to next record
  58.         myRS.MoveNext
  59.  
  60.     Loop
  61.  
  62. '   Close recordset
  63.     myRS.Close
  64.     mydb.Close
  65.     Set myRS = Nothing
  66.     Set mydb = Nothing
  67.  
  68.     MsgBox "Done!"
  69. End Sub
Apr 20 '14 #1
2 1275
zmbd
5,501 Expert Mod 4TB
cliffs
I have the following vba, which is not giving the desired output. Can u help me correcting the vba. thanks in advance
Well:
By, simply stating that your code "doesn't work," along with code that appears to have had very little if any troubleshooting performed, and expecting someone to help doesn't usually result in much of an answer and may result in your thread being deleted. Instead, please tell us what you were expecting to happen, what actually happened.

For any errors: for each error; the EXACT title, error number, and descriptions that occurred and at what line in your posted code the error occurred.

These are the minimum requirements for posting a question of this nature.
Apr 20 '14 #2
cliffs
2
Hi, thanks for your help, Actually, I want the the following result, but I get the wrong result while running the module :


Expand|Select|Wrap|Line Numbers
  1. sr.No. zonetype  result     vba result 
  2.                  expected   
  3.   1        1       1130     1136
  4.   2        2       1147     1137
  5.   3        2       1147     1147
  6.   4        2       1149     1147
  7.   5        1       1127     1147
  8.   6        1       1127     1147
  9.   7        1       1127     1147
  10.  
basically I want to check maximum high before its declining the high for zonetype 2 and minimum low before its start increase the for zonetype 1. In my vba it checks for next price and thereafter it stops. I want to compare the current high with previous high for each sr_no.s, if current high > previous high then I want to check, current high with next high till I get the next high is lower then the current high for zonetype 2 and then move to sr_no.2,3,4 etc and vice versa for zonetype 1.


thanks for help
Apr 20 '14 #3

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

Similar topics

21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
1
by: sean | last post by:
I'm trying to change my applications priority to something besides the basic highest, above average, etc. I'm developing for an embedded processor (Windows CE 4.2), thus I'm using evc++ in...
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
4
by: | last post by:
Hi: how to reduce the tablespace's High water mark? ths!
1
by: niner | last post by:
I have been working on the following code for about 6 hours now. I am attempting to write a program in Java that finds the highest, lowest, sum, and mean of an array. The program should also end...
1
by: Kris tarun | last post by:
I have a table of a retail store which has almost 13000 customers. and i want to write a query for this.. Group products based on their sales patterns. Highest, lowest, and median values. Use...
7
by: Alberto Fortuny | last post by:
Hey guys, any idea as to how to find the lowest value and the highest value in this 2D array? I made the functions to find the lowest and highest, but all im getting on execution is a 1 on both, no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.