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

need help in VB Code

3
Good day,

Iam traying to get result of my record as below

If next record is biger than previous show "1"
If next record is same previous show "1"
If next record is smallest show "0"
if next record is same previous show "0"

Example

Expand|Select|Wrap|Line Numbers
  1.  
  2. id    Time        Code    Price    Res
  3.    1    10:00:00 AM    1010    905     [COLOR="Blue"]0[/COLOR]
  4.  464    10:00:34 AM    1010    906     [COLOR="blue"]1[/COLOR]
  5.  626    10:00:56 AM    1010    906    [COLOR="blue"]1[/COLOR]
  6. 1523    10:02:16 AM    1010    904    [COLOR="blue"]0[/COLOR]
  7. 1568    10:02:21 AM    1010    904    [COLOR="blue"]0[/COLOR]
  8. 1569    10:02:21 AM    1010    905    [COLOR="blue"]1[/COLOR]
  9.  
  10.  
the code gave me correct result for some filed and other incorrect !

Could you please check the code and correct it for me.

I have attached the DB for any correction

Note: the command bottons on Form1 of Forms Object.

Iam very appreciated for assistant . :)

..

the code below and need updating.


Private Sub cmdUpdate_Click()
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim SQL As String
Dim Code As String
Dim Price As Long
'Dim Res As String
Dim Res As Variant
'Dim PrevRes As String
Dim PrevRes As Variant

Set cnn = CurrentProject.Connection
SQL = "Select [code],[Price],[Res] from [tt]" & _
" order by [code],[ID]"

rst.Open SQL, cnn, adOpenKeyset, adLockOptimistic

Do While Not rst.EOF
Code = rst![code]
Price = rst![Price]
'PrevRes = ""
PrevRes = Null
rst.MoveNext
Do While rst![code] = Code
'Res = IIf(rst![Price] > [Price], "1", IIf(rst![Price] < [Price], "0", IIf(rst![Price] = [Price], PrevRes, Null)))
Res = IIf(rst![Price] > [Price], "1", IIf(rst![Price] < [Price], "0", PrevRes))
rst![Res] = Res
PrevRes = Res
Price = rst![Price]
rst.MoveNext
If rst.EOF Then
Exit Do
End If
Loop
Loop
Set cnn = Nothing
Set rst = Nothing

MsgBox "Res field updated."

End Sub
Attached Files
File Type: zip VBA Access 2000.zip (15.0 KB, 98 views)
Aug 23 '06 #1
3 2118
rosy
3
Iam sorry my expamle was not cleared.

Asum that I have this fields: Id,Code,Price,Res

the "res" field will show the vb code result

if the current price = 905 then I input a new entery with price 905 the Res filed should show "0" because the price same as previous price. then when I input a new entry with price 906 the result should show "1" because the previos record is less.
Aug 24 '06 #2
CaptainD
135 100+
Are you wanting to compare the new price to the most recent previous price?

you have several entries to the same item. The most recent is 904, now I update it to 905. Are these two entries the ones you are concerned with or do you want to compare each entry and show a trend?

If you are just wanting to compare the top 2 entries to each other then use your SQL statement to select the top 2 by date. Why go through all of them.
Aug 24 '06 #3
rosy
3
I have filed called "code" this code is varialble. could be 1010,1020 or 1030 etc.

this code belong to share stock number. if price is less than previous this mean some one has sold the share , if the price is higher this mean some one has bought the share. the goole of this program to show me how many share has sold and bought.

hope this give you more clarify for my idea.

thank you sir.
Aug 24 '06 #4

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

Similar topics

10
by: Beach Potato | last post by:
Dear Y'all: I'm about to start porting a big old project written in anscient version of Delphi to something more stable, robust, supportable and maybe even portable. Since I haven't seriously...
15
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
4
by: Quas.co.ua | last post by:
Hello all. I need your help. I need C compler to make demo of some technologie. This C compiler I need to write program which after run will be located in one segment of memory and it...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.