home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap09 / longdiss / longdiss.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-13  |  3.9 KB  |  134 lines

  1. VERSION 4.00
  2. Begin VB.Form frmLongDissector 
  3.    Caption         =   "Long Dissector"
  4.    ClientHeight    =   1800
  5.    ClientLeft      =   3960
  6.    ClientTop       =   3570
  7.    ClientWidth     =   5385
  8.    Height          =   2205
  9.    Left            =   3900
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1800
  12.    ScaleWidth      =   5385
  13.    Top             =   3225
  14.    Width           =   5505
  15.    Begin VB.TextBox txtLong 
  16.       Height          =   375
  17.       Left            =   240
  18.       TabIndex        =   5
  19.       Top             =   420
  20.       Width           =   1695
  21.    End
  22.    Begin VB.CommandButton cmdFigureIt 
  23.       Caption         =   "Figure It"
  24.       Default         =   -1  'True
  25.       Height          =   375
  26.       Left            =   240
  27.       TabIndex        =   0
  28.       Top             =   960
  29.       Width           =   1695
  30.    End
  31.    Begin VB.Label Label9 
  32.       Caption         =   "Byte 4:"
  33.       Height          =   195
  34.       Left            =   2700
  35.       TabIndex        =   10
  36.       Top             =   1260
  37.       Width           =   555
  38.    End
  39.    Begin VB.Label Label8 
  40.       Caption         =   "Byte 3:"
  41.       Height          =   195
  42.       Left            =   2700
  43.       TabIndex        =   9
  44.       Top             =   900
  45.       Width           =   555
  46.    End
  47.    Begin VB.Label Label7 
  48.       Caption         =   "Byte 2:"
  49.       Height          =   195
  50.       Left            =   2700
  51.       TabIndex        =   8
  52.       Top             =   540
  53.       Width           =   555
  54.    End
  55.    Begin VB.Label Label6 
  56.       Caption         =   "Byte 1:"
  57.       Height          =   195
  58.       Left            =   2700
  59.       TabIndex        =   7
  60.       Top             =   180
  61.       Width           =   555
  62.    End
  63.    Begin VB.Label Label5 
  64.       Caption         =   "Enter a long:"
  65.       Height          =   195
  66.       Left            =   240
  67.       TabIndex        =   6
  68.       Top             =   180
  69.       Width           =   1395
  70.    End
  71.    Begin VB.Label lblByte4 
  72.       Height          =   255
  73.       Left            =   3360
  74.       TabIndex        =   4
  75.       Top             =   1260
  76.       Width           =   1335
  77.    End
  78.    Begin VB.Label lblByte3 
  79.       Height          =   255
  80.       Left            =   3360
  81.       TabIndex        =   3
  82.       Top             =   900
  83.       Width           =   1335
  84.    End
  85.    Begin VB.Label lblByte2 
  86.       Height          =   255
  87.       Left            =   3360
  88.       TabIndex        =   2
  89.       Top             =   540
  90.       Width           =   1335
  91.    End
  92.    Begin VB.Label lblByte1 
  93.       Height          =   255
  94.       Left            =   3360
  95.       TabIndex        =   1
  96.       Top             =   180
  97.       Width           =   1335
  98.    End
  99. Attribute VB_Name = "frmLongDissector"
  100. Attribute VB_Creatable = False
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. Public Function ByteFromLong(LongVal As Long, Position As Integer) As Integer
  104. Dim iTemp As Long
  105. If Position < 1 Or Position > 4 Then
  106.    ByteFromLong = -1
  107.    Exit Function
  108. End If
  109. Select Case Position
  110. Case 1
  111.    iTemp = LongVal And 127   ' Binary 01111111
  112. Case 2
  113.    iTemp = LongVal And 32512   ' Binary 01111111 00000000
  114.    iTemp = iTemp / 256  ' Binary 1 00000000
  115. Case 3
  116.    iTemp = LongVal And 8323072  ' Binary 01111111 00000000 00000000
  117.    iTemp = iTemp / 65536  ' Binary 1 00000000 00000000
  118. Case 4
  119.    iTemp = LongVal And 2130706432 ' Binary 01111111 00000000 00000000 00000000
  120.    iTemp = iTemp / 16777216  ' Binary 1 00000000 00000000 00000000
  121. End Select
  122. ByteFromLong = iTemp
  123. End Function
  124. Private Sub Command1_Click()
  125. End Sub
  126. Private Sub cmdFigureIt_Click()
  127. Dim iLong As Long
  128. iLong = Val(txtLong.TEXT)
  129. lblByte1.Caption = Str(ByteFromLong(iLong, 1))
  130. lblByte2.Caption = Str(ByteFromLong(iLong, 2))
  131. lblByte3.Caption = Str(ByteFromLong(iLong, 3))
  132. lblByte4.Caption = Str(ByteFromLong(iLong, 4))
  133. End Sub
  134.