home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples5 / ch13 / fclient.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  4.7 KB  |  154 lines

  1. VERSION 5.00
  2. Begin VB.Form frmClient 
  3.    Caption         =   "Customer"
  4.    ClientHeight    =   3000
  5.    ClientLeft      =   840
  6.    ClientTop       =   1785
  7.    ClientWidth     =   4470
  8.    LinkTopic       =   "Form1"
  9.    PaletteMode     =   1  'UseZOrder
  10.    ScaleHeight     =   3000
  11.    ScaleWidth      =   4470
  12.    Begin VB.Timer Timer1 
  13.       Interval        =   500
  14.       Left            =   3360
  15.       Top             =   240
  16.    End
  17.    Begin VB.ListBox lstPurchase 
  18.       Height          =   1395
  19.       Left            =   180
  20.       TabIndex        =   3
  21.       Top             =   1140
  22.       Width           =   4095
  23.    End
  24.    Begin VB.CheckBox chkShop 
  25.       Caption         =   "Shop"
  26.       Height          =   255
  27.       Left            =   1260
  28.       TabIndex        =   2
  29.       Top             =   660
  30.       Width           =   1335
  31.    End
  32.    Begin VB.TextBox txtClient 
  33.       Height          =   285
  34.       Left            =   1260
  35.       MaxLength       =   1
  36.       TabIndex        =   0
  37.       Text            =   "1"
  38.       Top             =   240
  39.       Width           =   1335
  40.    End
  41.    Begin VB.Label lblStatus 
  42.       Height          =   195
  43.       Left            =   180
  44.       TabIndex        =   4
  45.       Top             =   2700
  46.       Width           =   4095
  47.    End
  48.    Begin VB.Label Label1 
  49.       Alignment       =   1  'Right Justify
  50.       Caption         =   "Customer #:"
  51.       Height          =   195
  52.       Left            =   120
  53.       TabIndex        =   1
  54.       Top             =   300
  55.       Width           =   1095
  56.    End
  57. Attribute VB_Name = "frmClient"
  58. Attribute VB_GlobalNameSpace = False
  59. Attribute VB_Creatable = False
  60. Attribute VB_PredeclaredId = True
  61. Attribute VB_Exposed = False
  62. Option Explicit
  63. ' Copyright 
  64.  1997 by Desaware Inc. All Rights Reserved
  65. ' Simple state machine
  66. ' 0 - Idle
  67. ' 1 - Looking for checkstand
  68. ' 2 - Waiting for checkstand to be free
  69. ' 3 - Checkstand is free, data loaded
  70. ' 4 - Waiting for checkout complete
  71. Dim CurrentState%
  72. Dim CurrentTotal As Single
  73. Dim MappingHandle As Long
  74. Dim MappingAddress As Long
  75. Private Sub Form_Unload(Cancel As Integer)
  76.     CleanUp
  77. End Sub
  78. Private Sub Timer1_Timer()
  79.     Dim usename$
  80.     Dim newtotal&
  81.     Dim cs As CheckStand
  82.     Dim x%
  83.     Select Case CurrentState
  84.         Case 0
  85.             If chkShop.value = 1 Then
  86.                 CurrentState = 1
  87.             End If
  88.         Case 1
  89.             usename$ = GetMappingName$()
  90.             ' Right now we only use checkstand 1
  91.             MappingHandle = OpenFileMapping(FILE_MAP_WRITE, False, usename$)
  92.             If MappingHandle = 0 Then Exit Sub
  93.             MappingAddress = MapViewOfFile(MappingHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0)
  94.             CurrentState = 2
  95.         Case 2
  96.             agCopyData ByVal MappingAddress, cs, Len(cs)
  97.             If cs.Total = 0 Then CurrentState = 3
  98.         Case 3
  99.             CurrentTotal = 0
  100.             For x = 0 To CInt(Rnd(99))
  101.                 cs.Prices(x) = 100 * Rnd()
  102.                 CurrentTotal = CurrentTotal + cs.Prices(x)
  103.             Next x
  104.             cs.Done = True
  105.             cs.Client = "Client" & txtClient.Text
  106.             agCopyData cs, ByVal MappingAddress, Len(cs)
  107.             CurrentState = 4
  108.         Case 4
  109.             agCopyData ByVal MappingAddress, cs, Len(cs)
  110.             If cs.Total <> 0 Then
  111.                 For x = 0 To 99
  112.                     newtotal = newtotal + cs.Prices(x)
  113.                 Next x
  114.                 cs.Total = 0
  115.                 lstPurchase.AddItem Format$(CurrentTotal, "0.00")
  116.                 agCopyData cs, ByVal MappingAddress, Len(cs)
  117.                 If chkShop.value = 0 Then
  118.                     CurrentState = 0
  119.                 Else
  120.                     CurrentState = 1
  121.                 End If
  122.             ' Clear file mapping handles, etc.
  123.             CleanUp
  124.             End If
  125.     End Select
  126.     Select Case CurrentState
  127.         Case 0
  128.             lblStatus.Caption = "Idle"
  129.         Case 1
  130.             lblStatus.Caption = "Looking for checkstand"
  131.         Case 2
  132.             lblStatus.Caption = "Waiting in line at checkstand"
  133.         Case 3
  134.             lblStatus.Caption = "Loading items onto checkstand"
  135.         Case 4
  136.             lblStatus.Caption = "Waiting for checkout to be complete"
  137.     End Select
  138. End Sub
  139. Public Function GetMappingName() As String
  140.     GetMappingName = "ChkStd1map"
  141. End Function
  142. Private Sub CleanUp()
  143.     ' Remember, this won't get called if you Stop without
  144.     ' closing the main window.
  145.     If MappingAddress <> 0 Then
  146.         Call UnmapViewOfFile(MappingAddress)
  147.         MappingAddress = 0
  148.     End If
  149.     If MappingHandle <> 0 Then
  150.         Call CloseHandle(MappingHandle)
  151.         MappingHandle = 0
  152.     End If
  153. End Sub
  154.