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

📄 form1.frm

📁 UPC-EA 类型条形码生成和读取示例
💻 FRM
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "UPC-E/A 类型条形码生成和读取"
   ClientHeight    =   7665
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6450
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   511
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   430
   StartUpPosition =   1  'CenterOwner
   Begin MSComDlg.CommonDialog Cdlg 
      Left            =   5640
      Top             =   3960
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Frame Frame2 
      Caption         =   "读取识别"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3975
      Left            =   120
      TabIndex        =   11
      Top             =   3600
      Width           =   6255
      Begin VB.PictureBox Picture2 
         Height          =   2840
         Left            =   120
         ScaleHeight     =   185
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   393
         TabIndex        =   15
         Top             =   1080
         Width           =   5950
         Begin VB.CommandButton Command5 
            Height          =   255
            Left            =   5640
            TabIndex        =   20
            Top             =   2520
            Width           =   255
         End
         Begin VB.VScrollBar VScroll1 
            Height          =   2535
            Left            =   5640
            TabIndex        =   17
            Top             =   0
            Width           =   255
         End
         Begin VB.HScrollBar HScroll1 
            Height          =   255
            Left            =   0
            TabIndex        =   16
            Top             =   2520
            Width           =   5655
         End
         Begin VB.PictureBox Picture3 
            AutoRedraw      =   -1  'True
            AutoSize        =   -1  'True
            BackColor       =   &H80000009&
            BorderStyle     =   0  'None
            BeginProperty Font 
               Name            =   "Terminal"
               Size            =   6
               Charset         =   255
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   2460
            Left            =   0
            ScaleHeight     =   164
            ScaleMode       =   3  'Pixel
            ScaleWidth      =   372
            TabIndex        =   19
            Top             =   0
            Width           =   5580
         End
      End
      Begin VB.CommandButton Command4 
         Caption         =   "加载条码图片"
         Height          =   735
         Left            =   120
         TabIndex        =   12
         Top             =   240
         Width           =   2295
      End
      Begin VB.Label Label6 
         Caption         =   "条码识别内容:"
         Height          =   375
         Left            =   2520
         TabIndex        =   21
         Top             =   660
         Width           =   3540
      End
      Begin VB.Label Label5 
         Caption         =   "在条形码起始侧点击开始读取识别!"
         ForeColor       =   &H00FF0000&
         Height          =   375
         Left            =   2520
         TabIndex        =   18
         Top             =   240
         Width           =   3135
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "条码生成"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   3375
      Left            =   120
      TabIndex        =   0
      Top             =   105
      Width           =   6255
      Begin VB.ComboBox BarType 
         Height          =   300
         ItemData        =   "Form1.frx":030A
         Left            =   1200
         List            =   "Form1.frx":0314
         TabIndex        =   14
         Text            =   "UPC-E"
         Top             =   1200
         Width           =   1695
      End
      Begin VB.CommandButton Command3 
         Caption         =   "关于"
         Height          =   615
         Left            =   4680
         TabIndex        =   1
         Top             =   960
         Width           =   1455
      End
      Begin VB.CommandButton Command2 
         Caption         =   "保存"
         Height          =   615
         Left            =   3120
         TabIndex        =   6
         Top             =   960
         Width           =   1575
      End
      Begin VB.CommandButton Command1 
         Caption         =   "生成条码"
         Height          =   735
         Left            =   3120
         TabIndex        =   8
         Top             =   240
         Width           =   3015
      End
      Begin VB.TextBox Text1 
         Height          =   285
         Left            =   1200
         MaxLength       =   12
         TabIndex        =   7
         Text            =   "036000"
         Top             =   360
         Width           =   1695
      End
      Begin VB.ComboBox barSize 
         Height          =   300
         ItemData        =   "Form1.frx":0326
         Left            =   1200
         List            =   "Form1.frx":0336
         TabIndex        =   5
         Text            =   "3"
         Top             =   840
         Width           =   1695
      End
      Begin VB.PictureBox Picture1 
         Height          =   1575
         Left            =   120
         ScaleHeight     =   101
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   397
         TabIndex        =   2
         Top             =   1680
         Width           =   6015
         Begin VB.PictureBox bar 
            AutoRedraw      =   -1  'True
            BackColor       =   &H80000009&
            BorderStyle     =   0  'None
            BeginProperty Font 
               Name            =   "Terminal"
               Size            =   6
               Charset         =   255
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1215
            Left            =   120
            ScaleHeight     =   81
            ScaleMode       =   3  'Pixel
            ScaleWidth      =   380
            TabIndex        =   3
            Top             =   240
            Width           =   5700
         End
         Begin VB.Label Label3 
            Caption         =   "生成条码 :"
            BeginProperty Font 
               Name            =   "宋体"
               Size            =   9
               Charset         =   134
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   4
            Top             =   0
            Width           =   1815
         End
      End
      Begin VB.Label Label4 
         Caption         =   "条码类型:"
         Height          =   210
         Left            =   120
         TabIndex        =   13
         Top             =   1275
         Width           =   1215
      End
      Begin VB.Label Label1 
         Caption         =   "条形码数字:"
         Height          =   195
         Left            =   120
         TabIndex        =   10
         Top             =   420
         Width           =   1110
      End
      Begin VB.Label Label2 
         Caption         =   "单边宽度:"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   840
         Width           =   1215
      End
   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 Sub Command1_Click()
    Dim i As Integer

    If Text1 = "" Then
        MsgBox "请输入要生成的条码数字!", vbInformation, "提示"
        GoTo skip
    End If
    If IsNumeric(Text1) = False Then
        MsgBox "条码内容必须为数字!", vbCritical, "提示"
        GoTo skip
    End If

    Select Case (BarType.Text)
        Case "UPC-E"
        If Len(Text1.Text) < 6 Then
            MsgBox "UPC-E类型的条码内容必须小于6位的数字!", vbInformation, "提示"
            GoTo skip
        End If
        Case "UPC-A"
        If Len(Text1.Text) < 12 Then
            MsgBox "UPC-A类型的条码内容必须小于12位的数字!", vbInformation, "提示"
            GoTo skip
        End If
    End Select

    drawBar (Text1)
skip:

End Sub

'绘制条码
Private Sub drawBar(numbr As String)
    Dim size As Integer
    Dim i, j As Integer
    Dim h1, h2 As Integer
    Dim num As Integer
    Dim pattern(10) As String
    Dim patWid As Integer
    Dim prevPatWid As Integer
    Dim ofset As Integer
    ofset = 5

    size = barSize.Text
    If BarType.Text = "UPC-E" Then
        bar.Width = (size * 53 + ofset * 2)
    Else
        bar.Width = (95 * size + ofset * 2)
    End If
    bar.Line (0, 0)-(bar.Width, bar.Height), vbWhite, BF
    h1 = bar.Height
    Select Case size
        Case 1
        bar.FontSize = 5
        h2 = h1 - 15
        Case 2
        bar.FontSize = 6
        h2 = h1 - 15
        Case 3
        bar.FontSize = 9
        h2 = h1 - 17
        Case 4
        bar.FontSize = 9
        h2 = h1 - 17
    End Select
    '===================
    'UPC 条码样式
    '===================
    pattern(0) = "3211"
    pattern(1) = "2221"
    pattern(2) = "2122"
    pattern(3) = "1411"
    pattern(4) = "1132"
    pattern(5) = "1231"
    pattern(6) = "1114"
    pattern(7) = "1312"
    pattern(8) = "1213"
    pattern(9) = "3112"

    '起始
    For j = 1 To 3
        patWid = size - 1
        If j = 2 Then
            bar.Line (prevPatWid + ofset, 0)-(prevPatWid + patWid + ofset, h1), vbWhite, BF
        Else
            bar.Line (prevPatWid + ofset, 0)-(prevPatWid + patWid + ofset, h1), vbBlack, BF
        End If
        prevPatWid = prevPatWid + patWid + 1
    Next

    '条码值
    If BarType.Text = "UPC-E" Then
        For i = 1 To 6
            num = Mid$(numbr, i, 1)
            prevPatWid = 0

            If i = 4 Then
                For j = 1 To 5
                    patWid = size - 1
                    If j = 2 Or j = 4 Then

⌨️ 快捷键说明

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