home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vsfd1016 / data1.cab / Sample_-_General / frmMain.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1998-08-03  |  12.4 KB  |  378 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    Caption         =   "Demo VSFlex"
  4.    ClientHeight    =   1800
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   3135
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   1800
  10.    ScaleWidth      =   3135
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "&Done"
  14.       Default         =   -1  'True
  15.       Height          =   375
  16.       Left            =   1200
  17.       TabIndex        =   1
  18.       Top             =   1320
  19.       Width           =   855
  20.    End
  21.    Begin VB.Label Label1 
  22.       Caption         =   "Please follow along documented code and look at the immediate pane for results."
  23.       BeginProperty Font 
  24.          Name            =   "Arial"
  25.          Size            =   9
  26.          Charset         =   0
  27.          Weight          =   400
  28.          Underline       =   0   'False
  29.          Italic          =   0   'False
  30.          Strikethrough   =   0   'False
  31.       EndProperty
  32.       Height          =   975
  33.       Left            =   480
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   2175
  37.    End
  38. Attribute VB_Name = "frmMain"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. ' Demonsration of VSFlexData object
  44. ' Copyright
  45.  1998, VocalSoft Communications
  46. ' All rights reserved.
  47. Private Sub Form_Load()
  48. ' Demonstrates various ways to use the VSFlexData.
  49. ' In order to understand how this works, step
  50. ' through the code line by line and read through the
  51. ' comments.  Watch for the results in the immediate
  52. ' pane or the debug window.
  53. '=>Start here!
  54.     VSFlexRegister "A 16-digit key"
  55.     ' If you have aregistered version of VSFlexData, replace the
  56.     ' string with your 16-digit key
  57.     DemoIntrinsic
  58.     ' Demonstrates the use of VSFlexData as
  59.     ' intrinsic data types
  60.     DemoMap
  61.     ' Demonstrates the use of VSFlexData as
  62.     ' a map
  63.     DemoArray
  64.     ' Demonstrates the use of VSFlexData as
  65.     ' an array
  66.     DemoSet
  67.     ' Demonstrates the use of VSFlexData as
  68.     ' an array
  69.     DemoStack
  70.     ' Demonstrates the use of VSFlexData as
  71.     ' a stack
  72.     DemoQueue
  73.     ' Demonstrates the use of VSFlexData as
  74.     ' a queue
  75.     DemoFile
  76.     ' Demonstrates the use of VSFexData as a self-
  77.     ' contained object smart enough to know how to
  78.     ' write itself to a file and read itself back
  79.     ' from a file
  80.     DemoMethods
  81.     ' Demonstrates various utility methods of the
  82.     ' onject
  83. End Sub
  84. Private Sub DemoIntrinsic()
  85. ' Demonstrates the use of object as any of the
  86. ' intrinsic data types
  87.     Dim x As VSFlexData
  88.     Set x = New VSFlexData
  89.     Debug.Print "Demo of intrinsic data types"
  90.     Debug.Print "============================"
  91.     x = 5
  92.     Debug.Print x
  93.     ' As an integer
  94.     x = "My name is John Doe"
  95.     Debug.Print x
  96.     ' As a string
  97.     x = 5.12314 + 1
  98.     Debug.Print x
  99.     ' As a floating point
  100.     ' Can be used as any of the VB Intrinsic data types
  101.     Debug.Print
  102. End Sub
  103. Private Sub DemoMap()
  104. ' Demonstrates the use of object as a map
  105. ' A map is like a VB collection, but greatly
  106. ' enhanced
  107.     Dim x As VSFlexData
  108.     Dim k As VSFlexData
  109.     Set x = New VSFlexData
  110.     Debug.Print "Demo of Maps"
  111.     Debug.Print "============"
  112.     With x
  113.         .SetMap
  114.         !MinWidth = 10
  115.         !MaxWidth = 7500
  116.         ' Notice that you just start using the map.
  117.         ' Unlike a collection, when using a map you don't
  118.         ' have to worry about adding items, duplicate keys, etc.
  119.         ' Once you have set the object as a map, just
  120.         ' keep adding items to it with the slot operator (!).
  121.         
  122.         Set !Form = Me
  123.         !Form.Caption = "VSFlexData Demo"
  124.         ' Also notice that you can set a member of a map to
  125.         ' an object.  In this instance this object is a form.
  126.         ' To build more complicated data structures, you could use
  127.         ' maps of maps, maps of arrays, arrays of maps --
  128.         ' the possibilities are limitless.
  129.         
  130.         Debug.Print !MinWidth
  131.         Debug.Print !MaxWidth
  132.         Debug.Print !Form.Name
  133.         Debug.Print
  134.         ' This is how you access map members
  135.         
  136.         Debug.Print .DebugPrint
  137.         ' This is another way you could take a
  138.         ' quick look at the data in your object
  139.         
  140.         Set k = .GetKeys
  141.         Debug.Print k(1) & " = " & x(k(1))
  142.         Debug.Print k(2) & " = " & x(k(2))
  143.         Debug.Print k(3) & " = " & x(k(3)).Name
  144.         ' Notice how you can get the keys of a map.  You can't
  145.         ' do this with a VB collection.
  146.         
  147.         If .Exists("MinWidth") Then
  148.             !MinWidth = 0
  149.             Debug.Print "Now MinWidth = " & !MinWidth
  150.         End If
  151.         ' You could use the Exists method to find out
  152.         ' if a certain key exists in the map
  153.     End With
  154.     Debug.Print
  155. End Sub
  156. Private Sub DemoArray()
  157. ' Demonstrates the use of object as an array
  158.     Dim x As VSFlexData
  159.     Dim k As VSFlexData
  160.     Set x = New VSFlexData
  161.     Set k = New VSFlexData
  162.     x.Tag = "x"
  163.     k.Tag = "k"
  164.     Debug.Print "Demo of arrays"
  165.     Debug.Print "=============="
  166.     With x
  167.         .SetArray
  168.         x(1) = "This"
  169.         x(2) = "is"
  170.         x(3) = "a"
  171.         x(4) = "test."
  172.         Debug.Print x.DebugPrint
  173.         ' This is a dynamic array.  Notice that you don't have to
  174.         ' specify the number of elements, and you certainly
  175.         ' don't have to ReDim the array -- just keep adding elements!
  176.         
  177.         .SetArray 3
  178.         x(1) = "This"
  179.         x(2) = "is"
  180.         x(3) = "a"
  181.         ' This is a fixed array.  Since you specified the
  182.         ' number of elements in the SetArray method,
  183.         ' the following line if uncommented would
  184.         ' cause a runtime error:
  185.         ' x(4) = "test."
  186.         
  187.         k.SetArray 5
  188.         Set x(1) = k
  189.         
  190.         x(1)(1) = "This"
  191.         x(1)(2) = "is"
  192.         x(1)(3) = "another"
  193.         x(1)(4) = "test."
  194.         Debug.Print x.DebugPrint
  195.         ' This is how you could use a multidimensional array.
  196.         ' This particular array is a 2-dimensional array, but
  197.         ' there is no reason why you can't use more than 2 dimensions.
  198.         
  199.         k.AddLast "Wow! that's cool."
  200.         ' Another way to add an element to an array
  201.         Debug.Print x.DebugPrint
  202.     End With
  203.     Debug.Print
  204. End Sub
  205. Private Sub DemoFile()
  206. ' Demonstrates the use of object as a
  207. ' self-contained data structure smart enough
  208. ' to save itself to a file and read itself
  209. ' from a file
  210.     Dim str As String
  211.     Dim x As VSFlexData: Set x = New VSFlexData
  212.     Dim k As VSFlexData: Set k = New VSFlexData
  213.     x.SetSet 5, 4, 3, 2, 1
  214.     ' Initialize x as a set of (5,4,3,2,1)
  215.     x.Export App.Path & "\" & "Test.VSF"
  216.     ' Export x to a file
  217.     k.Import App.Path & "\" & "Test.VSF"
  218.     ' Import k from the file
  219.     Debug.Print x.DebugPrint
  220.     Debug.Print
  221.     ' See what's in x
  222.     Debug.Print k.DebugPrint
  223.     Debug.Print
  224.     ' See what's in k
  225. End Sub
  226. Private Sub DemoSet()
  227. ' Demonstrates the use of object as a set
  228.     Dim x As VSFlexData
  229.     Set x = New VSFlexData
  230.     Debug.Print "Demo of set"
  231.     Debug.Print "==========="
  232.     ' A set can be used to define a constant set of values
  233.     ' Once defined, niether more members can be added nor
  234.     ' the existing members can be changed
  235.     x.SetSet 100, 200, "This is a strng", 244.5
  236.     ' Create a set
  237.     Debug.Print x.DebugPrint
  238.     ' Print the values
  239.     Debug.Print x.Find(200)
  240.     ' You can get the index of a value
  241.     Debug.Print x.Exists(100)
  242.     ' You can determne whether a value exists
  243.     Debug.Print
  244. End Sub
  245. Private Sub DemoStack()
  246. ' Demonstrates the use of object as a stack
  247.     Dim x As VSFlexData
  248.     Set x = New VSFlexData
  249.     Debug.Print "Demo of stack"
  250.     Debug.Print "============="
  251.     ' A stack can be used to to implement the LIFO
  252.     ' or Last-In-First-Out data structure.
  253.     ' You can only PUSH elements on a stack
  254.     ' and POP them out
  255.     x.SetStack
  256.     ' Create a stack
  257.     x.Push 100
  258.     ' Push an integer to the stack
  259.     x.Push 200.25
  260.     ' Push a real to the stack
  261.     x.Push "This is a stack"
  262.     ' Push a string to the stack
  263.     x.Push Me
  264.     ' Push an object to the stack
  265.     Debug.Print x.Find(200)
  266.     ' Find 200 on the stack
  267.     Debug.Print x.Exists(200.25)
  268.     ' Does 200.25 exist on the stack?
  269.     Debug.Print x.Pop.Name
  270.     Debug.Print x.Pop
  271.     Debug.Print x.Pop
  272.     Debug.Print x.Pop
  273.     ' Pop values from stack
  274.     Debug.Print
  275. End Sub
  276. Private Sub DemoQueue()
  277. ' Demonstrates the use of object as a stack
  278.     Dim x As VSFlexData
  279.     Set x = New VSFlexData
  280.     Debug.Print "Demo of Queue"
  281.     Debug.Print "============="
  282.     ' A queue can be used to to implement the FIFO
  283.     ' or Frst-In-First-Out data structure.
  284.     ' You can only PUSH elements on a queue
  285.     ' and POP them out
  286.     x.SetQueue
  287.     ' Create a stack
  288.     x.Push 100
  289.     ' Push an integer to the stack
  290.     x.Push 200.25
  291.     ' Push a real to the stack
  292.     x.Push "This is a queue"
  293.     ' Push a string to the stack
  294.     x.Push Me
  295.     ' Push an object to the stack
  296.     Debug.Print x.Find(200)
  297.     ' You can get the index of a value
  298.     Debug.Print x.Exists(200.25)
  299.     ' You can determne whether a value exists
  300.     Debug.Print x.Pop
  301.     Debug.Print x.Pop
  302.     Debug.Print x.Pop
  303.     Debug.Print x.Pop.Name
  304.     ' Print the values
  305.     Debug.Print
  306. End Sub
  307. Private Sub DemoMethods()
  308. ' Demonstrates various methods of the VSFlexData object
  309.     Dim vsMap As VSFlexData: Set vsMap = New VSFlexData
  310.     Dim vsMap2 As VSFlexData: Set vsMap2 = New VSFlexData
  311.     Dim vsArray As VSFlexData: Set vsArray = New VSFlexData
  312.     Dim vsArray2 As VSFlexData: Set vsArray2 = New VSFlexData
  313.     Debug.Print "Demo various methods"
  314.     Debug.Print "===================="
  315.     vsMap.SetMap
  316.     vsArray.SetArray
  317.     ' Set one of the variables as a map
  318.     ' and the other one as an array
  319.     With vsMap
  320.         !Name = "John Doe"
  321.         !Phone = 5551212
  322.     End With
  323.     ' Put some initial data in the map
  324.     vsArray(1) = "Mr."
  325.     vsArray(2) = "Mrs."
  326.     vsArray(3) = "Miss"
  327.     ' Put some initial data in the array
  328.     Debug.Print vsMap.IsNumeric("Phone")
  329.     Debug.Print vsMap.IsInteger("Phone")
  330.     Debug.Print vsMap.IsLong("Phone")
  331.     Debug.Print vsMap.IsString("Name")
  332.     Debug.Print vsArray.IsString(2)
  333.     Debug.Print vsArray.IsObject(1)
  334.     ' Notice how you can find out the type of
  335.     ' each member element
  336.     Debug.Print
  337.     Debug.Print vsArray.Find("Mrs.")
  338.     Debug.Print vsMap.Find("Phone")
  339.     Debug.Print vsMap(vsMap.Find("Phone"))
  340.     ' The Find method finds returns the position of a
  341.     ' given element in the array.  In case of a map, it
  342.     ' returns the position of the slot or key name.
  343.     Debug.Print
  344.     Debug.Print vsArray.Exists("Miss")
  345.     Debug.Print vsMap.Exists("Phone")
  346.     Debug.Print vsMap.Exists("Mr.")
  347.     ' Notice how you can find out if a given element exists
  348.     ' in an array or a given key exists in a map.
  349.     Debug.Print
  350.     vsArray.AddFirst "Sir"
  351.     vsArray.AddLast "Madam"
  352.     Debug.Print vsArray(1)
  353.     Debug.Print vsArray(vsArray.Length)
  354.     ' You can also add elements in the first
  355.     ' or the last position
  356.     Debug.Print
  357.     vsMap2.Become vsMap
  358.     vsMap!Phone = 911
  359.     vsMap!Name = "Emergency"
  360.     Debug.Print vsMap2!Phone
  361.     Debug.Print vsMap2!Name
  362.     ' Become is one method that you could use
  363.     ' to copy an existing VSFlexData object to another.
  364.     ' Notice that after we copied vsMap to vsMap2,
  365.     ' we changed vsMap -- but this did not effect vsMap.
  366.     ' VB Collections lack this functionality
  367.     Debug.Print
  368.     Set vsArray2 = vsArray.Clone
  369.     Debug.Print vsArray2.DebugPrint
  370.     ' Clone performs the same operation as Become
  371.     ' GetObjectString returns a string for the data
  372.     ' of that object
  373.     Debug.Print
  374. End Sub
  375. Private Sub Command1_Click()
  376.     Unload Me
  377. End Sub
  378.