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

📄 form1.frm

📁 可以选择形成方波、三角波
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "模拟信号发生器"
   ClientHeight    =   9240
   ClientLeft      =   6060
   ClientTop       =   1845
   ClientWidth     =   12930
   LinkTopic       =   "Form1"
   ScaleHeight     =   9240
   ScaleWidth      =   12930
   Begin VB.CommandButton Command6 
      Caption         =   "退出"
      Height          =   495
      Left            =   1800
      TabIndex        =   16
      Top             =   4920
      Width           =   1215
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   480
      Top             =   5040
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.TextBox Text5 
      Height          =   375
      Left            =   2400
      TabIndex        =   8
      Top             =   3480
      Width           =   855
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   2280
      TabIndex        =   7
      Top             =   2400
      Width           =   855
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   2280
      TabIndex        =   6
      Top             =   1320
      Width           =   855
   End
   Begin VB.CommandButton Command5 
      Caption         =   "保存"
      Height          =   375
      Left            =   1800
      TabIndex        =   5
      Top             =   4320
      Width           =   1215
   End
   Begin VB.CommandButton Command4 
      Caption         =   "重设"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   4320
      Width           =   1215
   End
   Begin VB.CommandButton Command3 
      Caption         =   "三角波"
      Height          =   375
      Left            =   240
      TabIndex        =   3
      Top             =   3480
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "方波"
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   2520
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "正弦波"
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   1320
      Width           =   1215
   End
   Begin VB.PictureBox Picture1 
      AutoRedraw      =   -1  'True
      BackColor       =   &H00FFFFFF&
      Height          =   5775
      Left            =   3840
      ScaleHeight     =   5715
      ScaleWidth      =   8835
      TabIndex        =   0
      Top             =   240
      Width           =   8895
   End
   Begin VB.Label Label13 
      Caption         =   "v"
      Height          =   255
      Left            =   3360
      TabIndex        =   15
      Top             =   3480
      Width           =   255
   End
   Begin VB.Label Label12 
      Caption         =   "v"
      Height          =   255
      Left            =   3240
      TabIndex        =   14
      Top             =   2520
      Width           =   255
   End
   Begin VB.Label Label11 
      Caption         =   "s"
      Height          =   255
      Left            =   3240
      TabIndex        =   13
      Top             =   1440
      Width           =   255
   End
   Begin VB.Line Line2 
      X1              =   0
      X2              =   12960
      Y1              =   9240
      Y2              =   9240
   End
   Begin VB.Line Line1 
      X1              =   0
      X2              =   12960
      Y1              =   9240
      Y2              =   9240
   End
   Begin VB.Label Label9 
      Caption         =   "模拟信号"
      Height          =   495
      Left            =   3840
      TabIndex        =   12
      Top             =   0
      Width           =   1335
   End
   Begin VB.Label Label3 
      Caption         =   "偏置"
      Height          =   375
      Left            =   1920
      TabIndex        =   11
      Top             =   3480
      Width           =   615
   End
   Begin VB.Label Label2 
      Caption         =   "幅度"
      Height          =   255
      Left            =   1680
      TabIndex        =   10
      Top             =   2520
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "周期"
      Height          =   255
      Left            =   1800
      TabIndex        =   9
      Top             =   1440
      Width           =   615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'初始定义。
Option Explicit
Private Const pi = 3.1415926
Dim n, k, iy, ix, i, Y, a
Dim fname As String


Private Sub Command1_Click()  '画正弦波。

If IsNumeric(Text1.Text) = False Or IsNumeric(Text2.Text) = False Then
MsgBox "请正确输入!!!", 48    '判断输入的是否为数值类型。
Else
Picture1.Cls  '清除原来波形
Command2.Enabled = True
Command3.Enabled = True
Call zuobiao  '画坐标

If Val(Text1.Text) = 0 Then
MsgBox "周期为零,请重新设置!", 32   '如果周期为零。
Exit Sub
End If
n = 0
For i = 0 To 20 Step 0.001
Picture1.PSet (i, Val(Text2.Text) * Sin(((2 * pi * (1 / Val(Text1.Text))) * i) + Val(Text5.Text))), vbGreen  '画正弦。
Next
Command1.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text5.Enabled = False
End If
End Sub


'定义“退出”键。
Private Sub Command6_Click()
End
End Sub

Private Sub Command2_Click()  '画方波。
Command1.Enabled = True
Command3.Enabled = True
If IsNumeric(Text1.Text) = False Or IsNumeric(Text2.Text) = False Then    '判断输入的是否为数值类型。
MsgBox "请正确输入!!!", 48
Else
Picture1.Cls
Call zuobiao
If Val(Text1.Text) = 0 Then
MsgBox "周期为零,请重新设置!", 32
Exit Sub
End If
n = 0
For k = 0 To 20 Step Val(Text1.Text) * (1 / 2) '画方波,步长为1/2周期
    n = n + 1
    For i = k To k + Val(Text1.Text) * (1 / 2) Step 0.001
        Y = Val(Text2.Text) * (-1) ^ n                   '先画上下两条横线
         Picture1.PSet (i, Y + Val(Text5.Text)), vbGreen
    Next i
Picture1.Line (k, Val(Text2.Text) + Val(Text5.Text))-(k, -Val(Text2.Text) + Val(Text5.Text)), vbGreen  '再依次画出连接上下横线的竖线
Next k
Command2.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text5.Enabled = False
End If
End Sub
'画三角波。
Private Sub Command3_Click()
Command1.Enabled = True
Command2.Enabled = True
If IsNumeric(Text1.Text) = False Or IsNumeric(Text2.Text) = False Then   '判断输入的是否为数值类型。
MsgBox "请正确输入!!!", 48
Else
Picture1.Cls
Call zuobiao
If Val(Text1.Text) = 0 Then
MsgBox "周期为零,请重新设置!", 32
Exit Sub
End If
n = 0
For k = 0 To 20 Step 1 / ((1 / Val(Text1.Text)) * 2)  '画三角波。
    n = n + 1
    For i = k To k + 1 / ((1 / Val(Text1.Text)) * 2) Step 0.001
        Picture1.PSet (i, (-1) ^ (n + 1) * Val(Text2.Text) + (-1) ^ n * 4 * Val(Text2.Text) * (1 / Val(Text1.Text)) * (i - k) + Val(Text5.Text)), vbGreen
    Next i
Next k
Command3.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
Text5.Enabled = False
End If
End Sub
'定义模拟信号的“重置”键。
Private Sub Command4_Click()
Text1.Enabled = True
Text2.Enabled = True
Text5.Enabled = True
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text5.Text = ""
Picture1.Cls
End Sub

Private Sub Command5_Click()     '保存波形为图形文件。
On Error GoTo b             '出现错误即退出
CommonDialog1.CancelError = True
CommonDialog1.DialogTitle = "保存图像"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "图形文件(*.bmp)|*.bmp"  '保存类型
CommonDialog1.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
CommonDialog1.ShowSave
If Err = CommonDialog1.CancelError Then Exit Sub
If Dir(CommonDialog1.FileName) = "" Then   '保存时输入的文件名原来不存在,则直接保存
SavePicture Picture1.Image, CommonDialog1.FileName
Else
a = MsgBox("同名文件存在,覆盖吗?", vbYesNo, "模拟信号发生器")   '若文件名已存在,提示是否覆盖
If a = vbYes Then
SavePicture Picture1.Image, CommonDialog1.FileName  '若覆盖,则保存
Else
Command5_Click    '否则,从新开始
End If
End If
b: Exit Sub
End Sub
'画坐标轴
Public Sub zuobiao()
Picture1.Scale (-1, 10.5)-(21, -10.5)  '定义坐标系的范围。
Picture1.Line (-0.6, 0)-(20.6, 0)  '画坐标轴。
Picture1.Line (0, 10)-(0, -10)

Picture1.Line (-0.18, 9.6)-(0, 10), vbBlack  '画Y轴的箭头。
Picture1.Line (0.18, 9.6)-(0, 10), vbBlack
Picture1.CurrentX = 0.5
Picture1.CurrentY = 10.4
Picture1.Print "Y/V"

Picture1.Line (20, 0.45)-(20.5, 0), vbBlack  'X轴的箭头。
Picture1.Line (20, -0.45)-(20.5, 0), vbBlack
Picture1.CurrentX = 20.2
Picture1.CurrentY = 2
Picture1.Print "X/S"

For iy = -10 To 10 Step 2   'Y轴的刻度。
Picture1.Line (0.12, iy)-(0, iy), vbBlack
Picture1.CurrentX = -1
Picture1.CurrentY = iy
Picture1.Print iy
Next iy

For ix = 0 To 20 Step 2    'X轴的刻度。
Picture1.Line (ix, 0.15)-(ix, 0), vbBlack
Picture1.CurrentX = ix
Picture1.CurrentY = -1
Picture1.Print ix
Next ix
End Sub

⌨️ 快捷键说明

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