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 / samples4 / ch13 / fclient.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  4.7 KB  |  155 lines

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