├── sqlite.dll ├── database.db ├── Project1.vbw ├── Project1.vbp ├── database.bas └── Form1.frm /sqlite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobbiNespu/VB6-Sqlite3/HEAD/sqlite.dll -------------------------------------------------------------------------------- /database.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RobbiNespu/VB6-Sqlite3/HEAD/database.db -------------------------------------------------------------------------------- /Project1.vbw: -------------------------------------------------------------------------------- 1 | Form1 = 169, -14, 1072, 504, Z, 25, 25, 928, 543, C 2 | database = 345, 117, 1248, 635, 3 | -------------------------------------------------------------------------------- /Project1.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=Form1.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\Windows\system32\stdole2.tlb#OLE Automation 4 | Module=database; database.bas 5 | IconForm="Form1" 6 | Startup="Form1" 7 | Command32="" 8 | Name="Project1" 9 | HelpContextID="0" 10 | CompatibleMode="0" 11 | MajorVer=1 12 | MinorVer=0 13 | RevisionVer=0 14 | AutoIncrementVer=0 15 | ServerSupportFiles=0 16 | CompilationType=0 17 | OptimizationType=0 18 | FavorPentiumPro(tm)=0 19 | CodeViewDebugInfo=0 20 | NoAliasing=0 21 | BoundsCheck=0 22 | OverflowCheck=0 23 | FlPointCheck=0 24 | FDIVCheck=0 25 | UnroundedFP=0 26 | StartMode=0 27 | Unattended=0 28 | Retained=0 29 | ThreadPerObject=0 30 | MaxNumberOfThreads=1 31 | -------------------------------------------------------------------------------- /database.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "database" 2 | Option Explicit 3 | 4 | Public Declare Sub sqlite3_open Lib "sqlite.dll" (ByVal FileName As String, ByRef handle As Long) 5 | Public Declare Sub sqlite3_close Lib "sqlite.dll" (ByVal DB_Handle As Long) 6 | Public Declare Function sqlite3_last_insert_rowid Lib "sqlite.dll" (ByVal DB_Handle As Long) As Long 7 | Public Declare Function sqlite3_changes Lib "sqlite.dll" (ByVal DB_Handle As Long) As Long 8 | Public Declare Function sqlite_get_table Lib "sqlite.dll" (ByVal DB_Handle As Long, ByVal SQLString As String, ByRef ErrStr As String) As Variant() 9 | Public Declare Function sqlite_libversion Lib "sqlite.dll" () As String 10 | Public Declare Function number_of_rows_from_last_call Lib "sqlite.dll" () As Long 11 | 12 | Public DBz As Long 13 | Public DBFile As String 14 | Public minfo As String ' sql error akan store kat sini 15 | Public row As Variant 16 | Public query As String ' public variable untuk sql query 17 | Public numrows As Long 18 | Public i As Long 19 | 20 | 'connect ke database 21 | Public Function connectDb() 22 | DBFile = App.Path & "\database.db" 23 | sqlite3_open DBFile, DBz 24 | 25 | End Function 26 | 27 | 'tutup database 28 | Public Function closeDB() 29 | 30 | sqlite3_close (DBz) 31 | 32 | End Function 33 | 34 | 35 | Public Function getData() 36 | i = 1 'initialize counter untuk show data 37 | 38 | query = "SELECT * FROM users" 39 | 40 | row = sqlite_get_table(DBz, query, minfo) ' query database 41 | numrows = number_of_rows_from_last_call ' bilangan rows data yang di select 42 | End Function 43 | 44 | 45 | -------------------------------------------------------------------------------- /Form1.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form Form1 3 | Caption = "VB6+ SqLite" 4 | ClientHeight = 2805 5 | ClientLeft = 120 6 | ClientTop = 450 7 | ClientWidth = 3765 8 | LinkTopic = "Form1" 9 | ScaleHeight = 2805 10 | ScaleWidth = 3765 11 | StartUpPosition = 3 'Windows Default 12 | Begin VB.CommandButton Command2 13 | Caption = "Add" 14 | Height = 255 15 | Left = 2280 16 | TabIndex = 5 17 | Top = 2280 18 | Width = 1215 19 | End 20 | Begin VB.TextBox Text4 21 | Height = 285 22 | Left = 360 23 | TabIndex = 4 24 | Text = "Text1" 25 | Top = 1920 26 | Width = 1335 27 | End 28 | Begin VB.TextBox Text3 29 | Height = 285 30 | Left = 2040 31 | TabIndex = 3 32 | Text = "Text2" 33 | Top = 1920 34 | Width = 1455 35 | End 36 | Begin VB.CommandButton Command1 37 | Caption = "Next" 38 | Height = 315 39 | Left = 2280 40 | TabIndex = 2 41 | Top = 960 42 | Width = 1215 43 | End 44 | Begin VB.TextBox Text2 45 | Height = 285 46 | Left = 2040 47 | TabIndex = 1 48 | Text = "Text2" 49 | Top = 600 50 | Width = 1455 51 | End 52 | Begin VB.TextBox Text1 53 | Height = 285 54 | Left = 360 55 | TabIndex = 0 56 | Text = "Text1" 57 | Top = 600 58 | Width = 1335 59 | End 60 | Begin VB.Label Label2 61 | Caption = "Masuk Data Baru" 62 | Height = 255 63 | Left = 360 64 | TabIndex = 7 65 | Top = 1680 66 | Width = 2295 67 | End 68 | Begin VB.Label Label1 69 | Caption = "Data dalam Database" 70 | Height = 255 71 | Left = 360 72 | TabIndex = 6 73 | Top = 360 74 | Width = 2295 75 | End 76 | End 77 | Attribute VB_Name = "Form1" 78 | Attribute VB_GlobalNameSpace = False 79 | Attribute VB_Creatable = False 80 | Attribute VB_PredeclaredId = True 81 | Attribute VB_Exposed = False 82 | '------------------------------------------------- 83 | ' Basic VB6 dengan sqlite 84 | ' Instruction: copy sqlite.dll ke folder system32 85 | ' Author: ApoNie [http://GeeKzLife.Net] 86 | '------------------------------------------------- 87 | 88 | Private Sub Form_Load() 89 | 90 | Call connectDb 91 | Call getData ' get data 92 | Text1.Text = row(i, 1) ' data pada column 1 (name) dan row i 93 | Text2.Text = row(i, 0) ' data pada column 0 (ic) dan row i 94 | 95 | End Sub 96 | Private Sub Form_unload(Response As Integer) 97 | 98 | Call closeDB 99 | 100 | End Sub 101 | Private Sub Command1_Click() 102 | 103 | If (i < numrows) Then 'untuk pastikan papar dalam range yang diselect sahaja 104 | i = i + 1 105 | Else 106 | i = 1 107 | End If 108 | 109 | Text1.Text = row(i, 1) ' data pada column 1 (name) dan row i 110 | Text2.Text = row(i, 0) ' data pada column 0 (ic) dan row i 111 | 112 | End Sub 113 | 114 | Private Sub Command2_Click() 115 | 116 | Dim crows As Variant ' current rows (prive variable) 117 | 118 | query = "insert into users (nama,ic) VALUES ('" + Text4.Text + "','" + Text3.Text + "')" 119 | crows = sqlite_get_table(DBz, query, minfo) ' query database 120 | 121 | If (minfo = "") Then 122 | MsgBox "Data berjaya di masukkan" 123 | Else 124 | MsgBox "Error: minfo" 125 | End If 126 | 127 | Call getData ' update latest data 128 | 129 | End Sub 130 | --------------------------------------------------------------------------------