Click here to Skip to main content
16,017,297 members
Articles / Web Development / IIS
Tip/Trick

How to Design an Identification Card (ID Card) Print Program using Visual Basic 6.0 on Windows 2000, 7 or Later?

Rate me:
Please Sign up or sign in to vote.
4.58/5 (9 votes)
26 Jan 2015CPOL4 min read 74.3K   4.7K   6   11
Designing an identification card (ID Card) print program using Visual Basic 6.0 on Windows 2000, 7 or later

Introduction

If you want to identify your guests and then use the identification card (ID Card) is very convenient. Normally, you use ID Card which means you have a lot of guests. So, we design an ID Card print program to help you print many ID Cards. Otherwise, if you want to make your business card, you should try it. It can preview your design before you want to print.

We use a simple file system to manage our ID Card that means you just arrange to a folder. There are many files in the folder. The file name separates two parts, including number part and name part. You can adjust the count of the number and you will find out the two parts of change such as file name is ‘0001Brian.jpg’ and then the count of the number is four. The number part is ‘0001’ and the name part is ‘Brian’. You can make a lot of files for the ID Card or make your business card. You also are able to load foreground and background picture on the ID Card. It is good and beautiful.

We will use an ADO database object, a file system object and a report object. The ADO database object helps us to connect report object that it is able to preview and print ID Card. The file system object arrange and manage temporal files can be used. You can redesign this program to suit your requirements. There are three language editions for you.

Background

Equipment

  • Operation System: Microsoft Windows 7 Professional (64 bit)
  • Development Utility: Microsoft Visual Basic 6.0

Using the Code

Image 1

Image 2

  1. Initial all objects, especially, a database object and a file system object.
    VB.NET
    Private Sub Form_Load()
        ' Create a File System Object to accessible and management files or folder.
        Set objFso = New FileSystemObject
        ' Create a Stream Object of the ADO Database for processing binary picture.
        Set objStm = New ADODB.Stream
        ' This is database path.
        strLTYD_FN = App.Path & "\db1.mdb"
        ' Call a connection the access database function.
        Call mdiMM_Setup_cnnDB
        ' Get photo folder path from the register of the windows system.
        txtMM_PD.Text = GetSetting("GeneralOffice", "IdentificationCard", _
                                   "PhotosFolder", App.Path & "\IMG")
        ' Arrange to the string.
        txtMM_PD.Text = Trim(txtMM_PD.Text)
        ' Set up the File object to connect the path.
        File1.Path = Trim(txtMM_PD.Text)
        ' Call loading foreground picture function.
        Call frmCLASS_Load_imgCLASS_Card_F
        ' Call loading background picture function.
        Call frmCLASS_Load_imgCLASS_Card_B
    End Sub
  2. How to load a binary file into the field of the Access 2003 database.
    VB.NET
    Private Sub cmdCLASS_Card_F_Click()
    ' Set up whole error where go to.
    On Error GoTo cmdCLASS_Card_F_Click_ER:
    
    Dim strPT As String
    
    Dim intERR_Count As Integer
    ' We need a temporal picture file.
    strPT = App.Path & "LTY-PicTmp.WOK"
    If Right$(App.Path, 1) <> "\" Then
       strPT = App.Path & "\LTY-PicTmp.WOK"
    End If
    ' Checking the temporal picture that it exists.
    If objFso.FileExists(strPT) = True Then
       ' Set up the temporal picture attribute. It should can be overwritten.
       SetAttr strPT, vbArchive
    End If
    ' Open a common file dialog of the open file that only about picture of the types.
    With cdlCLASS
         .FileName = ""
         .CancelError = False
         .Filter = "All Picture (*.bmp;*.ico;*.wmf;*.jpg;*.gif) |*.bmp;*.ico;*.wmf;*.jpg;*.gif|" & _
                   "Bitmap (*.bmp)|*.bmp|" & _
                   "ICON (*.ico)|*.ico|" & _
                   "WMF (*.wmf)|*.wmf|" & _
                   "JPEG (*.jpg)|*.jpg|" & _
                   "GIF (*.gif)|*.gif|"
         .Flags = cdlOFNFileMustExist Or _
                  cdlOFNHideReadOnly Or _
                  cdlOFNLongNames Or _
                  cdlOFNPathMustExist
         .InitDir = App.Path
         .ShowOpen
    End With
    ' If it is no file and then exit the function.
    If Len(cdlCLASS.FileName) <= 0 Then
       Exit Sub
    End If
    ' If it had open a file, it should be less than 500KB.
    If objFso.GetFile(cdlCLASS.FileName).Size >= 512000 Then
       MsgBox "Sorry," & Chr$(13) & _
              "The file is over 500 KB ," & Chr$(13) & _
              "Please choose less than 500KB.", _
              vbOKOnly, _
              "Notice"
       Exit Sub
    ' The file size is less than 500KB.
    ElseIf objFso.GetFile(cdlCLASS.FileName).Size < 512000 Then
       ' Checking the file is exist.
       If objFso.FileExists(strLTYD_FN) = True Then
          ' Overwrite the temporal picture from the selected file.
          objFso.CopyFile cdlCLASS.FileName, strPT, True
          ' Set up the file can be overwritten.
          SetAttr strPT, vbArchive
          ' To find out ID is 001 from database.
          objRst_LTYD_Card.Filter = "[ID] LIKE '001'"
          ' If it is not any record in the database, we have to create a new record.
          If objRst_LTYD_Card.EOF = True Then
             objRst_LTYD_Card.AddNew
             objRst_LTYD_Card!ID = "001"
             objRst_LTYD_Card!IDName = "IDCardNumber"
             objRst_LTYD_Card.Update
          End If
          ' To query this record.
          objRst_LTYD_Card.Requery
          ' If the record exists.
          If objRst_LTYD_Card.EOF = False Then
             ' Update the foreground picture from the temporal picture into the database.
             With objStm
                  ' The type is binary. Because it is a picture file.
                  .Type = adTypeBinary
                  ' Open the stream of the database.
                  .Open
                  ' Loading the file.
                  .LoadFromFile strPT
                  ' Put the picture into the field.
                  objRst_LTYD_Card!Foreground = .Read
                  ' Update the database.
                  objRst_LTYD_Card.Update
                  ' Close the stream of the database.
                  .Close
             End With
             ' Loading the picture file into the image object. The means is to show it.
             imgCLASS_Card_F.Picture = LoadPicture(cdlCLASS.FileName)
          ' If it is still no any record in the database.
          ElseIf objRst_LTYD_Card.EOF = True Then
             ' To appear a notice. We have a problem.
             MsgBox "Sorry," & Chr$(13) & _
                    "It has a problem that cannot load the picture." & Chr$ (13) & _
                    "It is not found out this picture.", _
                    vbOKOnly, _
                    "Notice"
          End If
          ' Delete this temporal picture file.
          objFso.DeleteFile strPT, True
       End If
    End If
    ' Exit the function
    Exit Sub
    ' The error of label
    cmdCLASS_Card_F_Click_ER:
      ' If the user chooses to cancel and then exit the function.
      If Err.Number = cdlCancel Then
         Exit Sub
    
      Else
        ' If the problem is about connecting to databases, 
        ' Maybe we need to wait for these instructions.
        intERR_Count = intERR_Count + 1
        ' We use the delay function to waiting the connect object to process its work.
        Select Case intERR_Count
               ' Waiting for 20 seconds.
               Case 0 To 19
                    Call frmPPE_Delay(1)
                    Resume
               ' Appear a message box to ask the user.
               Case 20 To 30
                    Select Case MsgBox("Sorry, The program is busy now" & Chr$(13) & _
                                       "It is may take a couple of minutes," & Chr$(13) & _
                                       "Would you want to try again?" & Chr$(13) & Chr$(13) & _
                                       "Yes: I want to waiting 3 second and then to execute it." _
                                        & Chr$(13) & _
                                       "No: I want to end.", _
                                       vbYesNo + vbCritical, "Notice")
                           Case vbYes
                                Call frmPPE_Delay(3)
                                Resume Next
                           Case vbNo
                                Call frmPPE_Delay(1)
                                Exit Sub
                    End Select
    
               Case Else
    
                    On Error GoTo 0
                    Exit Sub
        End Select
      End If
    End Sub
  3. To preview these identification cards (ID Card):
    VB.NET
    Private Sub Command2_Click()
        ' If the function encounters any error and then go on ere label.
        On Error GoTo ere
                           
        Dim a, b As Integer
        ' List of all photos.
        For a = 0 To File1.ListCount
            ' To print five identification card once.
            b = (((a + 1) - 1) Mod 5) + 1
            ' If photo file name has existed.
            If Len(File1.List(a)) > 0 Then
               ' Set up the foreground of the identification card.
               Set drt_Member_Card.Sections("Section1").Controls_
                      ("drt_Member_Card_Fg" & Trim(Str(b))).Picture = imgCLASS_Card_F.Picture
               ' Set up the background of the identification card.
               Set drt_Member_Card.Sections("Section1").Controls_
                      ("drt_Member_Card_Bg" & Trim(Str(b))).Picture = imgCLASS_Card_B.Picture
               ' Loading the photo file into paper.
               Set drt_Member_Card.Sections("Section1").Controls_
                      ("drt_Member_Card_Photo" & Trim(Str(b))).Picture = _
                      LoadPicture(File1.Path & "\" & File1.List(a))
               ' Set up the file name in the paper. However, this is a personal name.
               drt_Member_Card.Sections("Section1").Controls_
                      ("drt_Member_Card_Name" & Trim(Str(b))).Caption = Mid$(File1.List(a), _
                      (Slider5.Value + 1), (Len(File1.List(a)) - 4) - (Slider5.Value))
               ' Set up the file name in the paper. 
               ' However, this is a number of the identification card.
               If Slider5.Value > 0 Then
                  drt_Member_Card.Sections("Section1").Controls_
                    ("drt_Member_Card_Num" & Trim(Str(b))).Caption = _
                                      Left$(File1.List(a), Slider5.Value)
               End If
            End If
            ' If the loop is five and then to preview it.
            If (b Mod 5) = 0 Then
                ' Set up the data source of the report object.
                Set drt_Member_Card.DataSource = objRst_LTYD_Card.DataSource
                ' Preview.
                drt_Member_Card.Show 1
            ' If the loop is the latest and then preview it.
            ElseIf (b < 5) And (a = File1.ListCount) Then
                ' Set up the data source of the report object.
                Set drt_Member_Card.DataSource = objRst_LTYD_Card.DataSource
                ' Preview.
                drt_Member_Card.Show 1
            End If
        Next a
        ' Exit the function.
        Exit Sub
    
    ere:
    End Sub

Exception

  1. We use the instructions to catch errors and process it, the instructions are ‘ON ERROR GOTO ...’ and a label.
  2. We need to VB6 runtime program to help execute this program. I suggest you can go to here (http://sourceforge.net/projects/vb6extendedruntime/) and download a package of the runtime program.
  3. Microsoft has provided VB6 runtime SP6 in there (http://support2.microsoft.com/vbruntime).
  4. How to install Visual Studio 6.0 in Windows Vista, 7 or later?
    File Name: sp598ent.stf
    13				Group	28 36 38 29 30 32 26 27 14 25 16 17 20 18 19 15 39 21 22 24 23 43
    									ß Problem in here.
    14				CustomAction	"""sp598ent.dll"", ""GetPathFromReg"", _
                    ""HKEY_LOCAL_MACHINE,Software\Microsoft\VisualStudio\6.0\Setup,VSCommonDir"" "	_
       				%d\Common				
    (… More)
    35				CustomAction	"sp598ent.dll,ExitInFinalize,34"									
    36				Depend	"27 ?  : 37"									ß Problem in here.
    37		IsWin95		CustomAction	"sp598ent.dll,CheckForMDAC"		ß Problem in here.

    Please change 36 to 38 and then delete 36 and 37 of string lines.

    VB.NET
    File Name: sp598ent.stf
    13				Group	28 38 29 30 32 26 27 14 25 16 17 20 18 19 15 39 21 22 24 23 43  
                    ß Change it.
    14				CustomAction	"""sp598ent.dll"", ""GetPathFromReg"", 
                    ""HKEY_LOCAL_MACHINE,Software\Microsoft\VisualStudio\6.0\Setup,VSCommonDir"" "
    					%d\Common				
    (… More)									
    36				Depend	"27 ?  : 37"									ß Delete it.
    37		IsWin95		CustomAction	"sp598ent.dll,CheckForMDAC"		ß Delete it.

    Save it. Now, you can keep installing Service Pack 5 and then you could find out it is working correctly.

    1. Introduction

      We always need to refer to old code. Therefore, sometimes, we need to catch an idea from old code. For example, Visual Studio 6.0 has a lot of good code. But it is not installed Windows Vista, 7 or later. There is one way that helps you to install it in Windows Vista, 7 or later.

    2. Equipment
      • Operation System: Windows Vista and Windows 7
      • Development Tool: Microsoft Visual Studio 6.0
    3. Usage

      If you were to install Visual Studio 6.0 on Windows when it told you that it is not supported. Please, force it to keep installing it. When it has been installed, finish and then you have to install Visual Studio 6.0 Service Pack 5 that you can use it in Windows Vista, 7 or later. However, there is a problem that it is not to install Service Pack 5. We have to fix it to help it for installation progress. To open the file ‘sp598ent.stf’ and then edit it. It is important that is find out ’13 Group 28 36’. The problem is in there. We need change its flow of installation. Please follow as below:

    4. Exception 1. If you find out the install program no responsibility when it searched to install component. Don’t worry. It is correct. Because your hard disk size is bigger than before and then it needs more time to find out that had been installed component. You just wait for it to search finish.

Acknowledgement

Thank you (Microsoft Visual Basic 6.0) very much for this great development utility.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer GJun Information Co.,Ltd.
Taiwan Taiwan
Dr. Lai Tai-Yu received the Ph.D. from National Taipei University of Technology in 2016. He is the co-author of 2 journal, 25 conference papers, 6 books, 9 articles in the codeproject.com, and 2 patents inventions. His research interests lie in the areas of digital image processing and AI. He is a lecturer.  

Dr Taiyu Lai. Stopień doktora, uzyskał w 2016 roku i objął stanowisko adiunkta na Wydziale. Ponadto jest autorem i współautorem: 2 publikacji artykułu w czasopiśmie naukowym, 25 artykułów opublikowanych w materiałach konferencyjnych, 6 książek, 9 eseje w monografiach codeproject.com, i posiada dwa patenty. Zainteresowania naukowe: przetwarzania obrazów i AI. Jest wykładowcą.  

赖岱佑在2016年取得台北科技大学资讯工程博士学位,有2篇期刊、25篇会议论文、6本书籍、9篇文章在 codeproject.com 、2项专利。研究方向:数字图像处理和AI。现职是一位讲师。

賴岱佑在2016年取得台北科技大學資訊工程博士學位,有2篇期刊、25篇會議論文、6本書籍、9篇文章在 codeproject.com 、2項專利。研究方向:數位影像處理和AI。現職是一位講師。

Comments and Discussions

 
GeneralMy vote of 5 Pin
Member 1290943922-Feb-19 3:28
Member 1290943922-Feb-19 3:28 
QuestionError Pin
Member 1338343729-Aug-17 1:02
Member 1338343729-Aug-17 1:02 
AnswerRe: Error Pin
sabir bakali5-Feb-18 22:50
sabir bakali5-Feb-18 22:50 
QuestionHow to design an identification card (ID Card) print program using Visual Basic.Net on Windows 2000, 7 or later? Pin
Ziad.hawamdeh.dev27-Aug-15 13:37
Ziad.hawamdeh.dev27-Aug-15 13:37 
QuestionMy VOTE OF 5 ! Pin
ISpliter28-Jan-15 8:50
ISpliter28-Jan-15 8:50 
AnswerRe: My VOTE OF 5 ! Pin
Lai Taiyu28-Jan-15 12:30
professionalLai Taiyu28-Jan-15 12:30 
GeneralRe: My VOTE OF 5 ! Pin
ISpliter28-Jan-15 13:46
ISpliter28-Jan-15 13:46 
GeneralRe: My VOTE OF 5 ! Pin
Lai Taiyu28-Jan-15 13:58
professionalLai Taiyu28-Jan-15 13:58 
GeneralMy vote of 1 Pin
D-McK27-Jan-15 8:43
professionalD-McK27-Jan-15 8:43 
VB6? What year is this?
GeneralRe: My vote of 1 Pin
Lai Taiyu27-Jan-15 11:19
professionalLai Taiyu27-Jan-15 11:19 
GeneralRe: My vote of 5 Pin
ISpliter28-Jan-15 8:54
ISpliter28-Jan-15 8:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.