⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 一个哈夫曼编码,我是新手,随便做个玩,请大家别笑话我.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "实验一计算平均指令长度"
   ClientHeight    =   4920
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5310
   LinkTopic       =   "Form1"
   ScaleHeight     =   4920
   ScaleWidth      =   5310
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdadd 
      Caption         =   "输入第1条指令频度Pi"
      Height          =   495
      Left            =   480
      TabIndex        =   4
      Top             =   120
      Width           =   2055
   End
   Begin VB.ListBox List1 
      Height          =   3120
      Left            =   480
      TabIndex        =   3
      Top             =   1200
      Width           =   4335
   End
   Begin VB.TextBox param1 
      Height          =   270
      Left            =   2520
      TabIndex        =   1
      Top             =   4440
      Width           =   2295
   End
   Begin VB.CommandButton cmdok 
      Caption         =   "计算平均指令长度"
      Height          =   495
      Left            =   2760
      TabIndex        =   0
      Top             =   120
      Width           =   2055
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      Caption         =   "已输入的指令频度"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   14.25
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   480
      TabIndex        =   5
      Top             =   840
      Width           =   4335
   End
   Begin VB.Label Label1 
      Caption         =   "所求平均指令长度为:"
      Height          =   255
      Left            =   600
      TabIndex        =   2
      Top             =   4440
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'计数器
Public counts As Integer

'取对数函数 base为底数 ,value 为值
Static Function Logs(value As Double, base As Double)
    Logs = Log(value) / Log(base)
End Function

'输入指令频度
Private Sub cmdadd_Click()
    myvalue = InputBox("请输入指令的频度", "请输入指令的频度")
    If IsNull(myvalue) = False Then
        '判断是否为数字
        If IsNumeric(myvalue) = True And 0 < myvalue And myvalue < 1 Then
            List1.AddItem (myvalue)
            counts = counts + 1
            cmdadd.Caption = "输入第" & (counts + 1) & "条指令频度Pi"
        Else
            MsgBox ("请输入合法的指令频度")
        End If
    End If
End Sub

'计算平均指令长度
Private Sub cmdok_Click()
 '求合
 For i = 0 To List1.ListCount - 1
       Sum = Sum + Logs(List1.List(i), 2)
 Next
 '取负数
 Sum = -Sum
 param1.Text = Sum
 MsgBox ("平均指令长度为:" & Sum)
End Sub

Private Sub Form_Load()
    '初始化计数器
    counts = 0
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -