Charging system--tangle of money! __integer

Source: Internet
Author: User

Before you do anything, you have to design and plan. This week the code for the computer room toll system didn't knock a few lines. The main problem is not to think clearly, is the question of money. How to do the balance, how to do recharge, how to update dynamically, how to make their own code error reduction. This is often said that the overall view.

Say it's easy to do hard. The most important aspect of dealing with money is that I always have a headache. Today I thought of a way to solve my own problem and share it with everyone. I hope everyone treatise.

Prerequisite: There are three tables are "Student basic information Table", "Student on machine record form", "Student recharge record Table" (after the figure)


The first is the general idea of consumption:




And then, we can deal with normal consumption in this way:



So let the problem become simple, specific thought history such, as long as the checkout time after the recharge time, recharge time is free, so no matter when the students are rushing money, in the machine table is considered him before the machine filled value. When he recharge the virtual checkout once. The balance is up to date.


The initial implementation of the specific code is:

' Function name: Check_out ' function: Checkout ' function parameter: No ' Date created: 2012/8/15 ' Creator: * * Modified: 2012/8/16 ' version: v1.2.0 public Function check_out () ' Recordset Dim Rstcheckout as ADODB for checkout. Recordset ' SQL statement Dim strSQL As String ' message Dim strsmg As String ' Last Balance Dim Intlastamo Unt As Integer ' This balance Dim intamount As Integer ' on machine time Dim datonlinetime As Date ' down time Dim datoffline Time as Date ' total Dim intlasttime As Integer ' consume Dim intcost As Integer ' to ensure that a student is on the computer to checkout If frm StudentOnOrOffLine.LabCount.Caption = 0 Then MsgBox "There are no students on the machine now. Please try again. ",," warned. "GoTo Exitfunction End If" finds all students who are not down strSQL = "SELECT * from Line_info where Offline_date is n Ull "Set rstcheckout = ExecuteSQL (strSQL, STRSMG) ' Cyclic checkout do ' Calculate this balance ' take last balance Intlast Amount = rstcheckout.fields (1) ' takes the machine time Datonlinetime = Format (CDate (Rstcheckout.fields (3)), "hh:mm ") ' Now timeVirtual for down time Datofflinetime = Format (now, "hh:mm") ' calculates consumption time Intlasttime = CInt (Datofflinetime- Datonlinetime) ' Calculates the consumption amount intcost = Intlasttime * inthourcost ' calculates the balance Intamo UNT = Intlastamount-intcost ' Update to Database Rstcheckout.fields (6) = Intcost ' Consumption amount Rstchecko Ut. Fields (7) = Intamount ' balance rstcheckout.update ' move to next rstcheckout.movenext ' note The recordset does not move to EOF (after the last record) to continue loop while rstcheckout.eof = False ' exit loop exitfunction:end Function


Recharge, the money directly into the Online_info table of the last balance, and the idea is, the students to recharge the time to move forward. Before moving on to the machine.       In this way, the last balance added to the argument. This thing let me see a fact. How important the early planning is. The concrete realization is simply, the thought refinement and the application really is a vital step. When designing or implementing a function, avoid knocking the code without fully understanding it. To have a holistic understanding, and then carefully plan. Keep doing it. You will succeed.


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.