SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size
SETHA SITE INFORMATION

How to Import Data from Excel into ListView in Visual Basic 6

E-mail Print PDF

Assume that we have an Excel file named Book3.xls locates in the same folder as the project folder which consists of data in four columns of the first sheet. We will import those data in Excel file into the ListView (have the same four columns as in Excel) in Visual Basic 6.

    Dim ExcelObj As Object
    Dim ExcelBook As Object
    Dim ExcelSheet As Object
    Dim i As Integer

    Set ExcelObj = CreateObject("Excel.Application")
    Set ExcelSheet = CreateObject("Excel.Sheet")
    
    ExcelObj.WorkBooks.Open App.Path & "\Book3.xls"
    
    Set ExcelBook = ExcelObj.WorkBooks(1)
    Set ExcelSheet = ExcelBook.WorkSheets(1)
    
    Dim l As ListItem
    lvwList.ListItems.Clear
    With ExcelSheet
    i = 1
    Do Until .cells(i, 1) & "" = ""
        Set l = lvwList.ListItems.Add(, , .cells(i, 1))
        l.SubItems(1) = .cells(i, 2)
        l.SubItems(2) = .cells(i, 3)
        l.SubItems(3) = .cells(i, 4)
        i = i + 1
    Loop

    End With
    
    ExcelObj.WorkBooks.Close
    
    Set ExcelSheet = Nothing
    Set ExcelBook = Nothing
    Set ExcelObj = Nothing

Download Sample Code
 

How to Export Data from ListView in Visual Basic 6 to Excel

E-mail Print PDF

Assume that we have a ListView contains data in four columns. We want to export all data in ListView to a new sheet of Microsoft Excel. Below is a sample code in Visual Basic 6 use to export data from ListView to Microsoft Excel.

    Dim ExcelObj As Object
    Dim ExcelBook As Object
    Dim ExcelSheet As Object
    Dim i As Integer

    Set ExcelObj = CreateObject("Excel.Application")
    Set ExcelBook = ExcelObj.WorkBooks.Add
    Set ExcelSheet = ExcelBook.WorkSheets(1)

    With ExcelSheet
        For i = 1 To lvwList.ListItems.Count
            .cells(i, 1) = lvwList.ListItems(i).Text
            .cells(i, 2) = lvwList.ListItems(i).SubItems(1)
            .cells(i, 3) = lvwList.ListItems(i).SubItems(2)
            .cells(i, 4) = lvwList.ListItems(i).SubItems(3)
        Next
    End With
    
    ExcelObj.Visible = True
    
    Set ExcelSheet = Nothing
    Set ExcelBook = Nothing
    Set ExcelObj = Nothing
Download Sample Code
 

How to Create Napoléon Fortune Teller in Turbo C++

E-mail Print PDF

This sample code shows you how to:

  • use graphic mode in Turbo C++
  • use mouse pointer in Turbo C++
  • create windows-like interface (button, textbox, form, scroll bar, etc.)
  • generate code for the requested name for fortune teller


  • Download Sample Code
     

    How to Open Report in Microsoft Access from Visual Basic 6

    E-mail Print PDF

    This sample shows you how to open report in Microsoft Access from Microsoft Visual Basic 6 coding.

    • Required Reference: Microsoft Access x.x Object Library
      How to add reference: Project -> References -> (Tick) Microsoft Access x.x Object Library)
    • x.x is the version of Microsoft Access and can be 11.0, 12.0, etc.

    Private db As New Access.Application
    
    Private Sub Command1_Click()
        Dim rpt As New Report
        Dim ctl As Control
        
        db.OpenCurrentDatabase App.Path & "\db1.mdb", True
        db.Visible = True
        
        Dim strSource As String
        strSource = "SELECT * FROM tblStudent WHERE Sex='m'"
        
        db.DoCmd.OpenReport "rptStudent", acViewDesign, , , , "m"
        db.Reports("rptStudent").RecordSource = strSource
        db.DoCmd.OpenReport "rptStudent", acViewPreview
        db.DoCmd.Maximize
        
        Set rpt = Nothing
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
        db.CloseCurrentDatabase
        Set db = Nothing
    End Sub
    
    Download Sample Code
     

    How to Create Calendar and Clock in Turbo C++ Graphic Mode

    E-mail Print PDF

    This is a sample of Turbo C++ programming language show you about:

    • How to use graphic mode in Turbo C++
    • How to create calendar
    • How to create real time clock
    • How to use mouse pointer
    • How to draw windows-like interface in Turbo C++



    Download Source Code
     


    Page 16 of 19