home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / swanson / code.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-01-06  |  12.9 KB  |  409 lines

  1. VERSION 2.00
  2. Begin Form Variables 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Code Optimizations"
  5.    ClientHeight    =   5220
  6.    ClientLeft      =   3405
  7.    ClientTop       =   3435
  8.    ClientWidth     =   7395
  9.    Height          =   5625
  10.    Left            =   3345
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5220
  13.    ScaleWidth      =   7395
  14.    Top             =   3090
  15.    Width           =   7515
  16.    Begin TextBox txtLoopCount 
  17.       Height          =   320
  18.       Left            =   6000
  19.       TabIndex        =   8
  20.       Text            =   "txtLoopCount"
  21.       Top             =   3765
  22.       Width           =   1300
  23.    End
  24.    Begin CommandButton cmdExplicit 
  25.       Caption         =   "Explict Property"
  26.       Height          =   450
  27.       Left            =   120
  28.       TabIndex        =   2
  29.       Top             =   2280
  30.       Width           =   2415
  31.    End
  32.    Begin CommandButton cmdVariable 
  33.       Caption         =   "Variable Test"
  34.       Height          =   450
  35.       Left            =   120
  36.       TabIndex        =   1
  37.       Top             =   960
  38.       Width           =   1935
  39.    End
  40.    Begin CommandButton cmdVariant 
  41.       Caption         =   "Variant Counter"
  42.       Height          =   450
  43.       Left            =   120
  44.       TabIndex        =   4
  45.       Top             =   4190
  46.       Width           =   2415
  47.    End
  48.    Begin CommandButton cmdInteger 
  49.       Caption         =   "Integer Counter"
  50.       Height          =   450
  51.       Left            =   120
  52.       TabIndex        =   5
  53.       Top             =   4680
  54.       Width           =   2415
  55.    End
  56.    Begin TextBox txtValue 
  57.       Height          =   320
  58.       Left            =   6000
  59.       TabIndex        =   7
  60.       Text            =   "txtValue"
  61.       Top             =   1800
  62.       Width           =   1300
  63.    End
  64.    Begin CommandButton cmdValue 
  65.       Caption         =   "Value of the Control"
  66.       Height          =   450
  67.       Left            =   120
  68.       TabIndex        =   3
  69.       Top             =   2780
  70.       Width           =   2415
  71.    End
  72.    Begin TextBox txtCounter 
  73.       Height          =   320
  74.       Left            =   6000
  75.       TabIndex        =   6
  76.       Text            =   "txtCounter"
  77.       Top             =   60
  78.       Width           =   1300
  79.    End
  80.    Begin CommandButton cmdProperty 
  81.       Caption         =   "Property Test"
  82.       Default         =   -1  'True
  83.       Height          =   450
  84.       Left            =   120
  85.       TabIndex        =   0
  86.       Top             =   480
  87.       Width           =   1935
  88.    End
  89.    Begin Line Line1 
  90.       BorderColor     =   &H00808080&
  91.       Index           =   3
  92.       X1              =   -15
  93.       X2              =   7320
  94.       Y1              =   3465
  95.       Y2              =   3465
  96.    End
  97.    Begin Line Line1 
  98.       BorderColor     =   &H00FFFFFF&
  99.       BorderWidth     =   2
  100.       Index           =   2
  101.       X1              =   0
  102.       X2              =   7335
  103.       Y1              =   3480
  104.       Y2              =   3465
  105.    End
  106.    Begin Line Line1 
  107.       BorderColor     =   &H00808080&
  108.       Index           =   1
  109.       X1              =   0
  110.       X2              =   7335
  111.       Y1              =   1680
  112.       Y2              =   1680
  113.    End
  114.    Begin Label lblTitle 
  115.       AutoSize        =   -1  'True
  116.       BackColor       =   &H00FFFFFF&
  117.       BackStyle       =   0  'Transparent
  118.       Caption         =   "Integer vs. Variant Variables"
  119.       FontBold        =   -1  'True
  120.       FontItalic      =   0   'False
  121.       FontName        =   "MS Sans Serif"
  122.       FontSize        =   12
  123.       FontStrikethru  =   0   'False
  124.       FontUnderline   =   0   'False
  125.       ForeColor       =   &H00800000&
  126.       Height          =   300
  127.       Index           =   0
  128.       Left            =   120
  129.       TabIndex        =   21
  130.       Top             =   3735
  131.       Width           =   3675
  132.    End
  133.    Begin Label lblTitle 
  134.       AutoSize        =   -1  'True
  135.       BackColor       =   &H00FFFFFF&
  136.       BackStyle       =   0  'Transparent
  137.       Caption         =   "Explicit property vs. Value of the Control"
  138.       FontBold        =   -1  'True
  139.       FontItalic      =   0   'False
  140.       FontName        =   "MS Sans Serif"
  141.       FontSize        =   12
  142.       FontStrikethru  =   0   'False
  143.       FontUnderline   =   0   'False
  144.       ForeColor       =   &H00800000&
  145.       Height          =   300
  146.       Index           =   2
  147.       Left            =   120
  148.       TabIndex        =   20
  149.       Top             =   1800
  150.       Width           =   5550
  151.    End
  152.    Begin Label lblTitle 
  153.       AutoSize        =   -1  'True
  154.       BackColor       =   &H00FFFFFF&
  155.       BackStyle       =   0  'Transparent
  156.       Caption         =   "Variables vs. Property Access"
  157.       FontBold        =   -1  'True
  158.       FontItalic      =   0   'False
  159.       FontName        =   "MS Sans Serif"
  160.       FontSize        =   12
  161.       FontStrikethru  =   0   'False
  162.       FontUnderline   =   0   'False
  163.       ForeColor       =   &H00800000&
  164.       Height          =   300
  165.       Index           =   1
  166.       Left            =   120
  167.       TabIndex        =   19
  168.       Top             =   120
  169.       Width           =   3855
  170.    End
  171.    Begin Label lblVariant 
  172.       BackStyle       =   0  'Transparent
  173.       Caption         =   "00.00 secs"
  174.       FontBold        =   -1  'True
  175.       FontItalic      =   0   'False
  176.       FontName        =   "MS Sans Serif"
  177.       FontSize        =   9.75
  178.       FontStrikethru  =   0   'False
  179.       FontUnderline   =   0   'False
  180.       Height          =   250
  181.       Left            =   6000
  182.       TabIndex        =   18
  183.       Top             =   4290
  184.       Width           =   1800
  185.    End
  186.    Begin Label lblInteger 
  187.       BackStyle       =   0  'Transparent
  188.       Caption         =   "00.00 secs"
  189.       FontBold        =   -1  'True
  190.       FontItalic      =   0   'False
  191.       FontName        =   "MS Sans Serif"
  192.       FontSize        =   9.75
  193.       FontStrikethru  =   0   'False
  194.       FontUnderline   =   0   'False
  195.       Height          =   250
  196.       Left            =   6000
  197.       TabIndex        =   17
  198.       Top             =   4785
  199.       Width           =   1800
  200.    End
  201.    Begin Label Label1 
  202.       BackStyle       =   0  'Transparent
  203.       Caption         =   "Use the explicit Text property:"
  204.       Height          =   250
  205.       Index           =   3
  206.       Left            =   2700
  207.       TabIndex        =   16
  208.       Top             =   2385
  209.       Width           =   2700
  210.    End
  211.    Begin Label lblExplicit 
  212.       BackStyle       =   0  'Transparent
  213.       Caption         =   "00.00 secs"
  214.       FontBold        =   -1  'True
  215.       FontItalic      =   0   'False
  216.       FontName        =   "MS Sans Serif"
  217.       FontSize        =   9.75
  218.       FontStrikethru  =   0   'False
  219.       FontUnderline   =   0   'False
  220.       Height          =   250
  221.       Left            =   6000
  222.       TabIndex        =   15
  223.       Top             =   2385
  224.       Width           =   1300
  225.    End
  226.    Begin Label Label1 
  227.       BackStyle       =   0  'Transparent
  228.       Caption         =   "Use value of the control:"
  229.       Height          =   250
  230.       Index           =   2
  231.       Left            =   2700
  232.       TabIndex        =   14
  233.       Top             =   2880
  234.       Width           =   2700
  235.    End
  236.    Begin Label lblValue 
  237.       BackStyle       =   0  'Transparent
  238.       Caption         =   "00.00 secs"
  239.       FontBold        =   -1  'True
  240.       FontItalic      =   0   'False
  241.       FontName        =   "MS Sans Serif"
  242.       FontSize        =   9.75
  243.       FontStrikethru  =   0   'False
  244.       FontUnderline   =   0   'False
  245.       Height          =   250
  246.       Left            =   6000
  247.       TabIndex        =   13
  248.       Top             =   2880
  249.       Width           =   1300
  250.    End
  251.    Begin Line Line1 
  252.       BorderColor     =   &H00FFFFFF&
  253.       BorderWidth     =   2
  254.       Index           =   0
  255.       X1              =   15
  256.       X2              =   7350
  257.       Y1              =   1695
  258.       Y2              =   1680
  259.    End
  260.    Begin Label lblVariable 
  261.       BackStyle       =   0  'Transparent
  262.       Caption         =   "00.00 secs"
  263.       FontBold        =   -1  'True
  264.       FontItalic      =   0   'False
  265.       FontName        =   "MS Sans Serif"
  266.       FontSize        =   9.75
  267.       FontStrikethru  =   0   'False
  268.       FontUnderline   =   0   'False
  269.       Height          =   250
  270.       Left            =   6000
  271.       TabIndex        =   12
  272.       Top             =   1080
  273.       Width           =   1300
  274.    End
  275.    Begin Label Label1 
  276.       BackStyle       =   0  'Transparent
  277.       Caption         =   "Using a Variable in the loop:"
  278.       Height          =   250
  279.       Index           =   1
  280.       Left            =   2150
  281.       TabIndex        =   11
  282.       Top             =   1080
  283.       Width           =   3100
  284.    End
  285.    Begin Label lblProperty 
  286.       BackStyle       =   0  'Transparent
  287.       Caption         =   "00.00 secs"
  288.       FontBold        =   -1  'True
  289.       FontItalic      =   0   'False
  290.       FontName        =   "MS Sans Serif"
  291.       FontSize        =   9.75
  292.       FontStrikethru  =   0   'False
  293.       FontUnderline   =   0   'False
  294.       Height          =   250
  295.       Left            =   6000
  296.       TabIndex        =   10
  297.       Top             =   585
  298.       Width           =   1300
  299.    End
  300.    Begin Label Label1 
  301.       BackStyle       =   0  'Transparent
  302.       Caption         =   "Using the Text property in the loop:"
  303.       Height          =   250
  304.       Index           =   0
  305.       Left            =   2145
  306.       TabIndex        =   9
  307.       Top             =   585
  308.       Width           =   3105
  309.    End
  310. Sub cmdExplicit_Click ()
  311. 'Use the explicit property (txtValue.Text) reference
  312. 'Sub cmdValue_Click is slightly faster
  313.     Limit% = Val(txtValue)
  314.     screen.MousePointer = 11
  315.     Start = Timer
  316.     For x% = 1 To Limit%
  317.         foo$ = txtValue.Text
  318.     Next x%
  319.     Finish = Timer
  320.     screen.MousePointer = 0
  321.     lblExplicit = Format$(Finish - Start, "##.##") & " secs."
  322. End Sub
  323. Sub cmdInteger_Click ()
  324. 'Use an Integer as the Loop Counter
  325. 'faster than Sub cmdVariant_Click
  326. Dim intCounter1 As Integer, intCounter2 As Integer, intCounter3 As Integer
  327.     screen.MousePointer = 11
  328.     Start = Timer
  329.     For intCounter1 = 1 To 100
  330.         For intCounter2 = 1 To intCounter1
  331.             For intCounter3 = 1 To intCounter2
  332.                 var = intCounter3 * 100 + intCounter2 * 10 + intCounter1
  333.             Next intCounter3
  334.         Next intCounter2
  335.     Next intCounter1
  336.     Finish = Timer
  337.     screen.MousePointer = 0
  338.     lblInteger = Format$(Finish - Start, "##.##") & " secs."
  339. End Sub
  340. Sub cmdProperty_Click ()
  341. 'In each iteration, reference the Text Property
  342. 'Sub cmdVariable_Click is faster
  343.     Limit% = Val(txtCounter.Text)
  344.     screen.MousePointer = 11
  345.     Start = Timer
  346.     For x% = 1 To Limit%
  347.         foo$ = Left(txtCounter.Text, Len(txtCounter.Text \ 2))
  348.     Next x%
  349.     Finish = Timer
  350.     screen.MousePointer = 0
  351.     lblProperty = Format$(Finish - Start, "##.##") & " secs."
  352. End Sub
  353. Sub cmdValue_Click ()
  354. 'Use the Value of the control by omitting the explicit Text property
  355. 'slightly faster than Sub cmdExplicit_Click
  356.     Limit% = Val(txtValue)
  357.     screen.MousePointer = 11
  358.     Start = Timer
  359.     For x% = 1 To Limit%
  360.         foo$ = txtValue
  361.     Next x%
  362.     Finish = Timer
  363.     screen.MousePointer = 0
  364.     lblValue = Format$(Finish - Start, "##.##") & " secs."
  365. End Sub
  366. Sub cmdVariable_Click ()
  367. 'Use a Variable (Temp$) instead of a Property Access
  368. 'faster than Sub cmdProperty_Click
  369.     Limit% = Val(txtLoopCount.Text)
  370.     Temp$ = txtLoopCount.Text
  371.     screen.MousePointer = 11
  372.     Start = Timer
  373.     For varCounter1 = 1 To txtLoopCount.Text
  374.         For varCounter2 = 1 To varCounter1
  375.             For varCounter3 = 1 To varCounter2
  376.                 var = varCounter3 * 100 + varCounter2 * 10 + varCounter1
  377.             Next varCounter3
  378.         Next varCounter2
  379.     Next varCounter1
  380.     Finish = Timer
  381.     screen.MousePointer = 0
  382.     lblVariable = Format$(Finish - Start, "##.##") & " secs."
  383. End Sub
  384. Sub cmdVariant_Click ()
  385. 'Use a Variant as the Loop Counter.
  386. 'Sub cmdInteger_Click is faster since it uses a Integer as the Loop Counter
  387.     screen.MousePointer = 11
  388.     Start = Timer
  389.     For varCounter1 = 1 To txtLoopCount.Text
  390.         For varCounter2 = 1 To varCounter1
  391.             For varCounter3 = 1 To varCounter2
  392.                 var = varCounter3 * 100 + varCounter2 * 10 + varCounter1
  393.             Next varCounter3
  394.         Next varCounter2
  395.     Next varCounter1
  396.     Finish = Timer
  397.     screen.MousePointer = 0
  398.     lblVariant = Format$(Finish - Start, "##.##") & " secs."
  399. End Sub
  400. Sub Form_Load ()
  401.     'Center the form on load.
  402.     Me.Left = (screen.Width - Me.Width) / 2
  403.     Me.Top = (screen.Height - Me.Height) / 2
  404.     ' Set default counter values
  405.     txtCounter = 1000
  406.     txtValue = 1000
  407.     txtLoopCount = 100
  408. End Sub
  409.