Make our own ebay (auction system en)-Resolving bids-page 6

Source: Internet
Author: User
Resolving Bids-page 6

Chris Payne

September 11, 2000



Function Resolvebids (ItemID)


' Set variables and create objects
Dim monincrement, Monhighprice, intavailable, Inttotitems, Flgquit
Dim blnresolved


' Assume bids are resolved
blnresolved = True
strConnectionString = "dsn=myauction; Uid=username; Pwd=password;database=myauctiondb "
Set rst = Server.CreateObject ("ADODB.") Recordset ")


' Get information from items table
strSQL = "Select Increment, Available from Tblauctionitems WHERE" & _
"IID =" & ItemID
Rst.open strSQL, strConnectionString
Monincrement = rst (0)
Intavailable = rst (1)
Rst.close


' Find the highest bid and total number of items bid for
strSQL = "Select Max (Winprice) as Winprice, sum (winitems) as" & _
"Winitems from Tblauctionbids WHERE" & _
"ItemID =" & ItemID
Rst.open strSQL, strConnectionString
Monhighprice = rst (0)
Inttotitems = rst (1)
Rst.close


' If a user with a higher max bid exists, then
' Update their bid if and only if available the items is exceeded
strSQL = "Select Maxbid, UID, Biditems, Winprice from" & _
"Tblauctionbids WHERE ItemID =" & ItemID
Rst.open strSQL, strConnectionString
If not rst.eof then
Do Until rst.eof
if (RST (0) > Monhighprice + monincrement) and (Inttotitems > Intavailable) & _
and (RST (3) <> Monhighprice) Then
Monhighprice = Monhighprice + monincrement
Call Dobids (ItemID, RST (1), Monhighprice)
blnresolved = False
End If
Rst. MoveNext
' If we ' re at the end of the recordset
And the bids are not yet resolved.
If not blnresolved and rst.eof then
Rst. MoveFirst
blnresolved = True
End If
Loop
End If
Rst.close

End Function


The main part of the above code is the last Do...loop section. The process is as follows:


Enter a user ' s bid (using the Dobids () function)
Find the highest bid for the item, and total number of items bid for
Loop through database and:
IF the current bidder ' s maximum bid is higher than the highest winning,
And the total number of items bid to is greater than the number of items available,
And the current bidder ' s bid are not the highest bid,
THEN increment the current bidder ' s bid by the increment value.
If we reach the "end of the" Recordset, and the bids are still not resolved, the start over.
This process would automatically update all bids appropriately, and weed out those whose max bids are
High enough. The reason we check to make sure the total number of items bid for is greater than the number
Total items available in step 4 are because if all bids are placed and items claimed, and there are
Still lots available, then everyone wins and bids don't need to is incremented.

For example, imagine there are lots available, and there are 3 bidders. If bidder A wants 3 lots at $
Bidder B wants 3 lots at $, and bidder C wants 3 lots at $, everyone would win because there is enough
Lots to go around, and then some. The Do loop above'll only have to go through once.

However, suppose bidder C now wants 5 items. Since There are not enough items to go around, someone would
Have to lose out. The loop in the code above weeds this person out by checking Max bids and updating the
Winning bids. If everyone's Max bids in this scenario is $, and the increment was $, then bidder C and
Whichever of bidder A and B placed the bid would win (remember that bid priority are placed on most
Lots bid for, followed by bid time.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.