On Jumat, 16 Juli 2010 12 komentar

Semakin kompleksnya data yang dibutuhkan mengharuskan suatu sistem dapat mengakses data secara multi akses dimana data dapat di akses secara online seperti WEB. Tapi di sini saya mencoba untuk mengoneksikan MYSQL Hosting dengan Aplikasi Dekstop VB 6.0 dengan bantuan MYSQL Connector ODBC.

Berikut beberapa situs hosting Database MYSQL:

  1. 000webhost.com
  2. freemysql.net
  3. freesql.org
  4. db4free.net
  5. free-mysql.bizhostnet.com
Dalam kasus ini saya menggunakan freemysql.net sebagai tempat hosting databasenya.

Berikut connectionstring untuk koneksi database MYSQL -nya :

'awal kode

Dim koneksi As New ADODB.Connection
Dim server, port, database, username, password As String

server = "76.73.77.53" 'untuk nama servernya sesuaikan dengan akun anda
port = "3306" 'port yang terbuka untuk situs hosting freemysql.net
database = "databaseku" 'sesuaikan dengan database anda
username = "usernameku" 'sesuaikan dengan username anda
password = "passwordku" 'sesuaikan dengan password anda

Set koneksi = New ADODB.Connection

koneksi.CursorLocation = adUseClient
koneksi.Mode = adModeReadWrite
koneksi.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Server=" & server _
& ";Port=" & port & ";Database=" & database & ";User=" & username & ";Password=" _
& password & ";Option=3;"
koneksi.Open

'akhir kode

Semoga membantu...

nb : untuk MYSQL Connector ODBC 3.51 silahkan download di sini download
(password : slavara0713)

Baca Selengkapnya...
On Sabtu, 10 Juli 2010 0 komentar

Bagi anda yang ingin mengetahui bagaimana cara Membuat Side Bar Dua Kolom di Blogspot seperti gambar di bawah ini:



Berikut adalah langkah-langkanya:

  1. Login dengan akun anda ke Dashboard , kemudian pilih Layout --> Edit HTML
  2. Klik Download Full Template, ini penting sebagai backupan template anda, jika nanti terjadi hal-hal yang tidak diinginkan...wah bahasanya.... : ) hehe.... template anda bisa direstore kembali seperti semula...
  3. Kemudian anda cari kode ini ]]></b:skin>
  4. Lalu copy kode di bawah ini, kemudian anda simpan diatas kode ]]></b:skin> tadi.


    #lsidebar-wrapper {
    float: left;
    margin:0 10px 0 5px;
    padding:0;
    width:150px;
    display:inline;
    }
    .lsidebar {
    line-height: 1.5em;
    }
    .lsidebar .widget {
    background: #FFFFFF;
    float:left;
    width: 140px;
    margin: 0 0 10px 0;
    padding: 10px;
    border:1px solid #f1f1f1;
    }
    #rsidebar-wrapper {
    float: right;
    margin-right:10px;
    padding:0;
    width:140px;
    }
    .rsidebar {
    line-height: 1.5em;
    }
    .rsidebar .widget {
    background: #FFFFFF;
    float:right;
    width: 130px;
    margin: 0 0 10px 0;
    padding: 10px;
    border:1px solid #f1f1f1;
    }


    (Kode dengan warna merah bisa anda atur sesuai dengan selera anda)
    Atau bisa juga anda simpan setelah kode di bawah ini, silahkan pilih sesuai selera

    /*- Sidebar -*/
    #sidebar {
    float: left;
    width: 320px;
    margin: 6px 0px 5px 0px;
    padding:0px;
    line-height: 18px;
    display: inline;
    }

  5. Setelah langkah diatas, kemudian dilanjutkan dengan mencari kode seperti di bawah ini atau yang nampak mirip2 :

    <div id='sidebar-wrapper'>
    <b:section class='sidebar' id='sidebar' preferred='yes'>
    <b:widget id='HTML6' locked='false' title='' type='HTML'/>
    </b:section>
    </div>


  6. Setelah ketemu, hapus dulu kode </div> nya, lalu anda copy kode berikut dan letakkan di bawahnya.

    <div id='lsidebar-wrapper'>
    <b:section class='lsidebar' id='lsidebar' preferred='yes'>
    </b:section>
    </div>
    <div id='rsidebar-wrapper'>
    <b:section class='rsidebar' id='rsidebar' preferred='yes'>
    </b:section>
    </div>
    </div>

    Jadi kode tersebut akan tampak seperti ini:

    <div id='sidebar-wrapper'>
    <b:section class='sidebar' id='sidebar' preferred='yes'>
    <b:widget id='HTML6' locked='false' title='' type='HTML'/>
    </b:section>
    <div id='lsidebar-wrapper'>
    <b:section class='lsidebar' id='lsidebar' preferred='yes'>
    </b:section>
    </div>
    <div id='rsidebar-wrapper'>
    <b:section class='rsidebar' id='rsidebar' preferred='yes'>
    </b:section>
    </div>
    </div>

  7. Jika sudah selesai semua, tinggal anda Save Template sekarang.
  8. Silahkan anda lihat hasilnya dengan cara click Page Elements.


    Sekarang anda sudah berhasil Membuat Side Bar Dua Kolom di Blogspot...

    Semoga membantu.............

Baca Selengkapnya...
On Rabu, 07 Juli 2010 0 komentar

Bagi teman-teman yang belum tahu mungkin masih bingung dalam membuat kategori di blogspot, walaupun itu sangatlah mudah jika teman-teman sudah mengetahuinya.
Sebelum kita melangkah lebih jauh, saya jelaskan dulu apa itu kategori?, kategori merupakan tempat dikumpulkannya artikel yang mempunyai tema yang sama. Sebagai contoh jika saya memposting artikel dengan judul "searching pun bisa dapat duit", "perangkat yang dibutuhkan pebisnis online", dan "dapat duit dengan download". Maka semua artikel tersebut dapat saya kumpulkan ke dalam kategori "bisnis online". Adanya kategori inilah yang akan memudahkan pengunjung blog/web dalam memilah-milah artikel mana yang diperlukan.

Di dalam blogspot kategori diistilahkan sebagai LABEL.

Lalu Bagaimanakah cara membuat kategori atau label tersebut?

Untuk membuat sebuah kategori atau label, teman-teman hanya perlu menceklis kotak di samping tulisan Label pada postingan teman-teman. Lengkapnya adalah sebagai berikut:
1. Pada Dashboard Pilih Edit Entri.
2. Lalu pilih postingan yang akan diberi label/kategori dengan cara menceklis kotak
disamping kiri.
3. Tepat di atas kotak yang telah di ceklis tadi, pilihlah kategori yang menurut teman-teman cocok untuk postingan yang telah dibuat.
4. Jika teman-teman ingin menambahkan kategori, teman-teman cukup pilih label baru kemudian tuliskan kategori yang diinginkan.

Satu postingan dapat dimasukkan ke dalam beberapa kategori. Untuk membuatnya tinggal dipisahkan dengan tanda koma ( , ) saja.

Sekarang bagaimana cara memunculkan kategori/label pada halaman blog ?

Untuk para pengguna template baru, kategori/label bisa di tampilkan di sidebar, dan biasanya element label ini sudah tersedia ketika baru memasang template. Jika elemen label belum tersedia, teman-teman bisa membuatnya sendiri, silahkan ikuti langkah - langkahnya berikut ini:

1. Klik Dashboard yang ada di pojok kanan atas.
2. klik menu Tata Letak.
3. Klik menu Elemen Halaman.
4. Klik tulisan Tambahkan Gadget.
5. Cari Gadget "Label" kemudian klik " + " di sebelah kanan gadget label.
6. Muncul jendela pilihan, Pilih radio button yang anda inginkan di samping
tulisan Menyortir, Alfabetik : jika kategori ingin di tampilkan sesuai dengan
abjad alfabetik ( dari A --> Z ), Frekuensi : jika kategori ingin
ditampilkan sesuai dengan banyaknya postingan yang telah dibuat.
7. Lalu terakhir, klik tombol yang bertuliskan SIMPAN PERUBAHAN.
8. Selesai.

Ok, jika berhasil maka blog teman-teman sekarang telah memiliki kategori/label.

Semoga membantu...

Baca Selengkapnya...
On Selasa, 06 Juli 2010 0 komentar

Banyak trik yang bisa dilakukan untuk mengenalkan blog kita. Facebook adalah salah satu jalan terbaik. Facebook digunakan banyak sekali blogger dan juga kita bisa mencari pelanggan 'loyal' baru dari kalangan non-Blogger. Hal kecil yang bisa mencolok dan menarik perhatian adalah memanfaatkan Status Generator sehingga nama blog kita selalu terlihat saat kita update status di facebook.

Untuk membuatnya sangatlah mudah, berikut langkah2nya :

1. Sekarang silahkan Anda buat aplikasi baru dengan pergi ke http://www.facebook.com/developers/createapp.php

2.Tentukan nama aplikasi Anda. Isi dengan Alamat blog Anda misal slavara0713.blogspot.com. Pilih Setuju lalu klik tombol Buat Aplikasi Baru.



3. Anda akan dibawa ke halaman pengaturan aplikasi.



4. Biarkan tetap terbuka. Silahkan pergi ke http://apps.facebook.com/statusgen. Klik Create.

5. Isi 4 kolom (Application ID, API KEY, Secret dan Application Name) sesuai angka yang Anda lihat pada halaman pengaturan aplikasi yang tadi telah Anda buat.



6. Pada canvas page URL isi dengan yang Anda inginkan. Misal saya isi dengan slavaraupdatestatus maka nantinya alamat aplikasi anda berada pada alamat http://apps.facebook.com/slavaraupdatestatus/

7. Jika sudah selesai mengisi, klik tekan tombol ini. Anda akan mendapatkan kode uniq untuk Canvas Callback URL Aplikasi Anda.



8. Silahkan ke halaman pengaturan aplikasi Anda. Pada bagian kiri pilih kanvas.

- Canvas Page URL isi sesuai alamat aplikasi yang tadi Anda pilih, misalkan slavaraupdatestatus.
- Canvas Callback URL isi dengan kode uniq yang baru saja Anda dapatkan.
- Metode Render pilih FBML. Jika sudah silahkan klik Simpan Perubahan.



Nah, sekarang aplikasi Anda telah jadi. Silahkan cek aplikasi Anda (misal silahkan coba: http://apps.facebook.com/slavaraupdatestatus/. Untuk menggunakan silahkan klik Izinkan. Setelah masuk ke halaman aplikasi, silahkan klik link untuk menggunakan aplikasi.



Akan muncul kotak dialog perizinan perubahan status, silahkan klik Izinkan. Maka, Anda akan berada pada halaman untuk mengupdate status Anda, cukup isikan pada kolom yang tersedia lalu tekan tombol Update Status Anda. Silahkan cek dinding facebook Anda dan hasilnya seperti gambar di bawah ini.



Jika ingin lebih menarik silahkan tambahkan icon, sehingga akan muncul icon kecil seperti pada status yang bawah. Untuk menambahkan icon silahkan pergi ke halaman sunting aplikasi Anda.

Sekarang saat melihat update status Anda, orang juga akan lihat alamat blog Anda. Tentu beberapa akan sangat tertarik. Agar lebih optimal sebaiknya Anda manfaatkan halaman aplikasi untuk grup blog Anda juga (saat membuat aplikasi otomatis Anda akan memiliki halaman aplikasi tersebut). Jika orang klik link slavara0713.blogspot.com seperti gambar di atas, maka itu otomatis menuju ke halaman profil aplikasi.

Silahkan mencoba...
Semoga bermanfaat...

Baca Selengkapnya...
On Senin, 05 Juli 2010 0 komentar

Berikut adalah kode VB 6.0 untuk meletakkan aplikasi yang telah kita buat pada system tray windows:



Semoga membantu...

Baca Selengkapnya...
On 0 komentar

Berikut adalah kodenya:

Private Sub cmdGetSysDir_Click()
      Dim Junk, WinSysDir$
      WinSysDir = Space(144)
      Junk = GetSystemDirectory(WinSysDir, 144)
      WinSysDir = Trim(WinSysDir)
      MsgBox "The Windows System Directory Path is: " & WinSysDir
End Sub

Semoga bisa membantu...

Baca Selengkapnya...
On Rabu, 30 Juni 2010 0 komentar

Bagaimana ya caranya memformat size memori lewat VB.NET ?, nah, disini saya ingin berbagi kodenya nih...silahkan di coba...





Kode:

Enum FormatMemorySizeUnits
BestGuess
Bytes
Kilobytes
Megabytes
Gigabytes
End Enum


' Mengconvert sebuah angka dari bytes ke dalam Kbytes, Megabytes, or Gigabytes

Function FormatMemorySize(ByVal value As Long, _
ByVal unit As FormatMemorySizeUnits, Optional ByVal decimalDigits As _
Integer = 2, Optional ByVal omitThousandSeps As Boolean = False) As String
' pengecekan error sederhana
If value < 0 Then Throw New ArgumentException("Value can't be negative")

' Mendapatkan unit terbaik, jika di minta
If unit = FormatMemorySizeUnits.BestGuess Then
Select Case value
Case Is < 1023
unit = FormatMemorySizeUnits.Bytes
decimalDigits = 0
Case Is < 1024 * 1023
unit = FormatMemorySizeUnits.Kilobytes
Case Is < 1048576 * 1023
unit = FormatMemorySizeUnits.Megabytes
Case Else
unit = FormatMemorySizeUnits.Gigabytes
End Select
End If

' evaluasi nilai desimal
Dim val As Decimal
Dim suffix As String

Select Case unit
Case FormatMemorySizeUnits.Bytes
val = value
Case FormatMemorySizeUnits.Kilobytes
val = value / 1024
suffix = "K"
Case FormatMemorySizeUnits.Megabytes
val = value / 1048576
suffix = "M"
Case FormatMemorySizeUnits.Gigabytes
val = value / 1073741824
suffix = "G"
End Select

' Mendapatkan string perwakilan
Dim format As String
If omitThousandSeps Then
format = "F" & decimalDigits.ToString
Else
format = "N" & decimalDigits.ToString
End If

Return val.ToString(format) & suffix
End Function


Semoga bisa memberi pengetahuan baru buat teman-teman.... ^_^

Baca Selengkapnya...
On Senin, 28 Juni 2010 2 komentar

Berikut sedikit kode untuk membuat form menjadi transparan dalam vb.net...

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Me.Opacity = 0.5

End Sub

Baca Selengkapnya...
On 0 komentar

Berikut adalah kode multithreading dalam vb.net...

Imports System
Imports System.Threading
Public Module ThreadSample
Public Balance As Integer = 1000
Sub Main()
Dim account As Account = New Account()
Dim depositeBalance1 As DepositeBalance = New _
DepositeBalance(account, 1000, "Customer 1")
Dim depositeBalance2 As DepositeBalance = New _
DepositeBalance(account, 1000, "Customer 2")
Dim t1 As Thread = New _
Thread(AddressOf depositeBalance1.DepositeAmount)
Dim t2 As Thread = New _
Thread(AddressOf depositeBalance2.DepositeAmount)
t1.Start()
t2.Start()
Try
t1.Join()
t2.Join()
Catch e As Exception
Console.Write(e.ToString())
Finally
'Do Nothing
End Try
End Sub
Public Class Account
Private balanceAmount As Integer
Public Sub Deposite(ByVal amount As Integer, _
ByVal message As String)
Console.Write(message & _
" Depositing Amount " & amount)
Console.Write(message & " Checking Previous Balance")
Monitor.Enter(Me)
balanceAmount = getBalance()
Console.Write(message & _
" Previous Balance in Account " & balanceAmount)
balanceAmount += amount
Console.Write(message & _
" Updating Balance in Account ")
setBalance(balanceAmount)
Monitor.Exit(Me)
Console.Write(message & " Update Balance " & Balance)

End Sub
Private Function getBalance() As Integer
Try
Thread.sleep(1000)
Catch e As Exception
Console.Write(e.ToString())
Finally
'Do Nothing
End Try
Return Balance
End Function

Private Sub setBalance(ByVal amount As Integer)
Try
Thread.sleep(1000)
Catch e As Exception
Console.Write(e.ToString())
Finally
'Do Nothing
End Try
Balance = amount
End Sub
End Class

Public Class DepositeBalance
Private account As Account
Private amount As Integer
Private message As String

Public Sub new(ByRef account As Account, _
ByVal amount As Integer, ByVal message As String)
MyBase.New()
Me.account = account
Me.amount = amount
Me.message = message
End Sub
Public Sub DepositeAmount()
Account.Deposite(amount, message)
End Sub
End Class
End Module

Baca Selengkapnya...
On 0 komentar

Berikut akan saya berikan sedikit kode sebagai implementasi dari inheritance di vb.net...

' Membuat object mobil
Public Class Car

Public Color As String
Private numberOfDoors As Integer

' Konstruksi
Sub New()
' Setting menjadi default:
Color = "White"
numberOfDoors = 5
End Sub

Property NumberOfDoors() As Integer
'Memanggil ketika property "got"
Get
Return numberOfDoors
End Get
End Property

End Class

' Proses inheritance objek mobil
Public Class SportsCar
Inherits Car
Public Weight As Integer
End Class

' Module where the real instance of Car and SportsCar Object are Utilized.
'Modul dimana instansiasi dari objek mobil dan mobil sport dimanfaatkan
Module Module1

Sub Main()
' membuat objek mobil baru...
Dim myCar As SportsCar
myCar = New SportsCar()

' setting berat (kg)...
myCar.Weight = 1085

' laporan details...
Console.WriteLine("Weight:" & myCar.Weight)
' menunggu...
Console.ReadLine()
End Sub

End Module

Baca Selengkapnya...
On Kamis, 24 Juni 2010 1 komentar

Pernahkah ketika teman-teman sedang membuat program di VB 6.0, teman-teman mengalami kesulitan seperti bagaimana ya cara menghitung selisih antara dua tanggal ? nah, dibawah ini adalah sedikit kode yang dapat teman-teman gunakan untuk menghitung selisih antara dua tanggal.

DateDiff("d", Format(TanggalAwal, "dd/MM/yyyy"), Format(TanggalAkhir, "dd/MM/yyyy"))

Semoga dapat membantu teman-teman sekalian...

Baca Selengkapnya...
On Senin, 21 Juni 2010 1 komentar

Pernah menggunakan method replace di VB? Secara default, method ini hanya akan mencari satu karakter tertentu dari string yang dituju dan akan mengubah karakter tersebut dengan karakter yang dikehendaki, misalnya:

dim myFStr as string, mySStr as string

myFStr=”3ko”

mySStr=myFstr.replace(”3″,”E”)

kode akan mengubah string “3ko” menjadi “Eko” (karakter 3 di-replace oleh karakter E). Lalu bagaimana kalo string awalnya adalah “h454n” dan kita akan merubahnya menjadi string “hasan”? Dalam kasus ini, kita perlu me-replace string secara berturutan. Contoh:

dim myFStr as string,mySStr as string

myFStr=”h454n”

mySStr=myFstr.replace(”4″,”a”).replace(”5″,”s”)

Kode akan me-replace karakter 4 menjadi a dan karakter 5 menjadi s.

Semoga Membantu...

Baca Selengkapnya...
On Minggu, 20 Juni 2010 0 komentar

Untuk mewujudkan suatu program atau aplikasi yang user-friendy, suatu program diwajibkan mempunyai shortcut untuk beberapa pengoprasiannya untuk menggantikan kerja mouse. misal saja untuk keluar dari form user tidak perlu lagi klik tombol Close pada form tersebut, tapi cukup dengan menekan tombol Esc yang ada pada keybord. ataupun untuk melakukan perpindahan antar control, user awam cenderung menggunakan tombol Enter daripada tombol Tab.

Akan tetapi seringkali para programmer Visual Basic .NET (Pemula tentunya) mengalami kesulitan dalam menangkap event tombol pada keyboard, bayak sebenernya cara menangkap aksi tombol ini, misal saja dengan KeyPress event, KeyUp ataupun KeyDown event.

Private Sub form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then
SendKeys.Send("{tab}")
End If
End Sub

Tetapi event code diatas hanya bekerja jika hanya focus berada pada form1 atau jika hanya form1 kosong dan belum ada control didalamnya, tetapi apabila focus berada pada control yang ada didalamnya, misal saja TextBox, maka key event diatas tidak akan bekerja.

akan tetapi ada beberapa trik untuk menangkap event tombol tanpa memandang focus berada dimana. Ok, langsung kita coba aja script code berikut:

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
Try
If msg.WParam.ToInt32 = Convert.ToInt32(Keys.Escape) Then
Me.Close()
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
Catch ex As Exception
Return False
End Try
Return MyBase.ProcessCmdKey(msg, keyData)
End Function

Sekarang coba jalankan program yang barusan dibikin, dan tekan tombol Esc, lalu lihat apa yang terjadi….

Semoga Membantu...

Baca Selengkapnya...
On Kamis, 17 Juni 2010 0 komentar

Ada banyak software yang membantu bagi para programmer VB untuk membuat membuat laporan dalam bentuk chart. Diantaranya adalah MS Chart (standard control dari visual studio) namun dirasa masih sangat terbatas dari segi fungsi yang ada. Ada pula Chart Director (www.advsofteng.com) yang sangat lengkap mulai dari Bar Chart, Line Chart, Pie Chart, XY Chart, Polar Chart, sampai Meters and Gauges Chart. Chart Director juga dapat digunakan bagi programmer PHP,ASP,JAVA,Python,C++,dll. Chart Director merupakan chart komponen yang paling lengkap yang pernah saya coba untuk aplikasi VB, tetapi komponen ini tidak gratis alias harus bayar, tetapi bagi para programmer dapat mencobanya dengan mendownload versi trialnya di www.advsofteng.com. Ada juga yang lain khusus untuk VB net yaitu dotnetchart (www.dotnetcharting.com) tetapi komponen ini pun tidak gratis. Ada lagi yang lain yang freeware yaitu RM Chart (www.rmchart.com). Dalam komponen ini cukup lengkap fitur yang diberikan dan pemakaiannya pun tidaklah sulit. Menurut saya RMChart komponent yang paling bagus yang pernah saya coba sebagai komponen yang sifatnya gratis. Komponent ini dapat juga digunakan untuk pengembang VB net.
Disini saya akan membahas cara membuat chart di Microsoft Excel. Mengapa excel? Sekarang hampir semua komputer baik kantor maupun rumah yang menggunakan sistem operasi Windows, pasti memiliki aplikasi excel didalamnya. Jadi tidaklah sulit bagi para pengembang menggunakan excel sebagai output laporannya untuk program aplikasinya. Selain itu pengguna dapat dengan mudah merubah type chart yang dihasilkan langsung dari excel tanpa merubah coding. Jadi laporan chart dari excel lebih dinamis.
Demikian contoh membuat laporan chart di Excel menggunakan VB
Pertama tambahkan referensi “Microsoft Excel 9.0 Object Library” untuk pengguna Microsoft Office 2000, “Microsoft Excell 11.0 Object Library” untuk pengguna Microsoft Office 2003. Perlu diperhatikan pada saat kita membuat program dan mengkompilenya menggunakan Excel 11.0 lalu mencoba menjalankan aplikasinya untuk komputer yang memiliki Office 2000, maka program tersebut tidak dapat jalan karena menggunakan versi yang lebih baru. Maka perlu dibuat setupnya, untuk membuatnya dapat menggunakan Package and Development Wizardnya punya Visual Studio.
Tambahkan juga referensi “Microsoft ActiveX Data Objects 2.8 Library” dan “Microsoft ActiveX data Objects Recordset 2.8 Library” khusus bagi pengguna Windows XP SP2
Tambahkan juga referensi “Microsoft Shell Controls And Automation”
Tambahkan component “Microsoft Common Dialog Control 6.0”

Berikut contoh codingnya
Dim objExcelA As Excel.Application
Dim objExcelW As Excel.Workbook
Dim objExcelSI As Excel.Worksheet
Dim objExcelCI As Excel.Chart
Dim objExcelCS As Excel.ChartObject
Dim rst1 As ADODB.Recordset
Dim row As Long
Dim chgtype As Long
Dim LastCell As String
Dim statYear As String
Dim bkmark As Variant
Private Sub Form_Load()
‘untuk set common dialognya dengan nama: dlgFileLocation
‘menentukan alamatnya dahulu untuk file xls yang akan dibuat
With dlgFileLocation
.DefaultExt = “.XLS”
.DialogTitle = “Where is the Spread Sheet”
.Filter = “Excel SpreadSheet|*.XLS|All Files|*.*”
.FilterIndex = 1
.FileName = “Issue Statistics”
.CancelError = True
.Flags = FileOpenConstants.cdlOFNHideReadOnly + _
FileOpenConstants.cdlOFNCreatePrompt + _
FileOpenConstants.cdlOFNOverwritePrompt
.InitDir = “C:\TEMP\”
.ShowSave
End With
Set objExcelA = New Excel.Application
Set objExcelW = objExcelA.Workbooks.Add
Set rst1 = New ADODB.Recordset
‘buat recordsetnya
With rst1
.Fields.Append “code”, adVarChar, 20, adFldIsNullable
.Fields.Append “name”, adVarChar, 40, adFldIsNullable
.Fields.Append “value”, adInteger, , adFldIsNullable
.Open
End With
Set objExcelSI = objExcelW.Worksheets.Add
objExcelSI.Name = “test1″
objExcelSI.Cells(1, 1).Value = “kode1″
objExcelSI.Cells(1, 2).Value = “name2″
objExcelSI.Cells(1, 3) = “value1″
objExcelW.Charts.Add
Set objExcelCI = objExcelW.ActiveChart
objExcelCI.Activate
objExcelCI.Name = “chart 1″
Dim i%, row%
For i = 1 To 50
rst1.AddNew
rst1.Collect(”code”) = “a”
rst1.Collect(”name”) = “aaaaa”
rst1.Collect(”value”) = i
Next
row = 2
rst1.MoveFirst
‘isi data
Do While Not rst1.EOF
objExcelSI.Cells(row, 1).Value = rst1.Collect(”code”)
objExcelSI.Cells(row, 2).Value = rst1.Collect(”name”)
objExcelSI.Cells(row, 3).Value = rst1.Collect(”value”)
rst1.MoveNext
If rst1.EOF Then
LastCell = “D” & Mid$(Str$(row), 2)
objExcelCI.SetSourceData objExcelSI.Range(”a1:” & LastCell), xlColumns
objExcelCI.ChartType = xlLineMarkers
objExcelCI.Legend.Position = xlLegendPositionBottom
objExcelCI.HasTitle = True
objExcelCI.ChartTitle.Text = objExcelCI.Name
Else
If chgtype <> rst1.Fields(”code”) Then
LastCell = “D” & Mid$(Str$(row), 2)
objExcelCI.SetSourceData objExcelSI.Range(”a1:” & LastCell), xlColumns
objExcelCI.ChartType = xlLineMarkers
objExcelCI.Legend.Position = xlLegendPositionBottom
objExcelCI.HasTitle = True
objExcelCI.ChartTitle.Text = objExcelCI.Name
End If
End If
row = row + 1
Loop
objExcelCI.SetSourceData objExcelSI.Range(”a1:” & LastCell), xlColumns
objExcelCI.ChartType = xlLineMarkers
objExcelCI.Legend.Position = xlLegendPositionBottom
objExcelCI.HasTitle = True
objExcelCI.ChartTitle.Text = objExcelCI.Name

On Error GoTo err
objExcelA.DisplayAlerts = False
objExcelW.SaveAs dlgFileLocation.FileName
objExcelA.Quit
Set objExcelA = Nothing
Set objExcelW = Nothing
Set objExcelSI = Nothing
Set objExcelCI = Nothing
Set objExcelCS = Nothing
Set rst1 = Nothing
Dim shl As New Shell
shl.Open dlgFileLocation.FileName
Me.MousePointer = vbNormal
Exit Sub
err:
Msgbox “Error create excel because of file already opened”,vbExclamation,”Confirm”
End
End Sub

Baca Selengkapnya...
On 7 komentar

Pernahkah suatu ketika Anda memiliki data yang tersimpan di sebuah file Excel lalu Anda ingin membaca dan bahkan mengambil data dari dalam file Excel tadi, untuk selanjutnya diproses dengan program VB yang Anda buat.

Berikut cara untuk mengakses data dari Exel tersebut, mulai dari membuat atau mendapatkan object Excel, membuka file Excel, membaca worksheet pertama, mengambil data yang terdapat di worksheet pertama pada kolom dan baris tertentu, menutup worksheet dan workbook Excel, sampai kepada membersihkan memory yang digunakan oleh object Excel dari dalam program Anda.

Semuanya cukup dengan mengoptimalkan Microsoft Excel Object Library dari dalam Visual Basic 6. Object ini bisa Anda gunakan dengan syarat di komputer tersebut sudah terinstall Microsoft Excel atau Microsoft Office.
Persiapan: 1. Buat satu project standard exe dengan satu form
2. Tambahkan 1 control CommandButton ke atas form
3. Tambahkan item "Microsoft Excel X.X Object Library"
dari menu Project -> References... . X.X tergantung
versi Excel atau Microsoft Office yang Anda gunakan.
Saat saya mencoba code ini, di notebook saya sudah
terinstall Microsoft Office 2000 dan Microsoft Office
2007, dan X.X di atas yang muncul = 12.0 di mana VB6
hanya menampilkan object library Excel yang versi
terakhir. MS Excel 2007 object library versi 12.0
4. Pastikan file Dataku.xls sudah terdapat di dalam
direktori yang sama dengan aplikasi Anda ini dan
di kolom B mulai dari baris pertama sampai kelima
sudah ada nilai atau datanya.
5. Copy-kan code berikut ke editor form yang bertalian.

Dim Excel As Excel.Application 'Excel Application
Dim ExcelWBk As Excel.Workbook 'Excel Workbook
Dim ExcelWS As Excel.Worksheet 'Excel Worksheet

Private Sub Command1_Click()
On Error GoTo Err
'Inisialisasi object Excel
StartExcel
'Buka file Dataku.xls yang berada di direktori yang sama
'dengan aplikasi Anda
Set ExcelWBk = Excel.Workbooks.Open(App.Path & "\Dataku.xls")
'Tampilkan status di form
Print "Berhasil membuka file ..."
'Akses Sheet pertama (1)
'Jika ingin mengakses sheet kedua, ganti
'(1) menjadi (2), dst...
Set ExcelWS = ExcelWBk.Worksheets(1)
'Tampilkan status di form
Print "Berhasil membaca Sheet1 ..."
'Lakukan proses di worksheet ExcelWS
With ExcelWS
Dim i As Integer
Dim strData As String
'Baca mulai dari baris pertama sampai kelima
For i = 1 To 5
'Tampung ke sebuah variabel
strData = strData & .Cells(i, 2) & vbCrLf
Next i
End With
'Tampilkan ke layar
MsgBox strData
'Setelah selesai, jangan lupa tutup worksheet
CloseWorkSheet
'Tampilkan status di form
Print "Berhasil menutup worksheet dan file Excel ..."
'Jangan lupa pula, selalu bersihkan memory yang
'digunakan oleh object Excel
ClearExcelMemory
'Tampilkan status di form
Print "Berhasil membersihkan memory Excel ..."
'Tampilkan pesan
MsgBox "Selesai, coy...!", vbInformation, "Mantap"
Exit Sub
Err:
'CloseWorkSheet
ClearExcelMemory
MsgBox Err.Description, vbCritical, "Error euy"
End Sub

Private Sub StartExcel()
On Error GoTo Err:
'Pertama, ambil object Excel, dan jika error
'lompat ke label Err di paling bawah Sub ini,
'dan buat object Excel. Error terjadi jika
'object Excel belum dibuat
Set Excel = GetObject(, "Excel.Application")
Exit Sub
Err:
'Buat object Excel jika belum ada.
Set Excel = CreateObject("Excel.Application")
End Sub

Private Sub CloseWorkSheet()
On Error Resume Next
'Tutup Excel workbook
ExcelWBk.Close
'Keluar dari aplikasi Excel
Excel.Quit
End Sub

Private Sub ClearExcelMemory()
'Sebelum membersihkan memory, periksa terlebih dulu
'object yang akan dibersihkan...
If Not ExcelWS Is Nothing Then Set ExcelWS = Nothing
If Not ExcelWBk Is Nothing Then Set ExcelWBk = Nothing
If Not Excel Is Nothing Then Set Excel = Nothing
End Sub

Baca Selengkapnya...
On 0 komentar

Black (Hitam) : #000000

White (Putih) : #ffffff

Blue (Biru) : #0066ff

Old Green (Hijau tua) : #006666

Red (Merah) : #ff0000

Yellow (Kuning) : #ffff00

Green (Hijau Muda) : #00ff00

Purple : (Ungu) : #ff00ff

BlueSky (Biru Langit) : #00ffff

Orange (Oranye) : #ff9900

Pink (Merah Muda) : #ff99ff

Di atas adalah beberapa kode warna untuk HTML, semoga membantu...

Baca Selengkapnya...
On 2 komentar

Di bawah ini ada referensi yang diambil dari suatu situs masih dalam bentuk aslinya. Enjoy...

The Format function converts a value to a text string and gives you control over the string's appearance. For example, you can specify the number of decimal places for a numeric value, leading or trailing zeros, currency formats, and portions of the date. The syntax is:
Syntax
Format(expression [,format [,firstdayofweek [,firstweekofyear]]])

expression
Any valid expression
format
A valid named or user-defined format expression
firstdayofweek
A constant that specifies the first day of the week
firstweekofyear
A constant that specifies the first week of the year
The firstdayofweek argument has these settings:

Constant Value Description
vbUseSystem 0 Use NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
The firstweekofyear argument has these settings:

Constant Value Description
vbUseSystem 0 Use NLS API setting.
vbFirstJan1 1 Start with week in which January 1 occurs (default).
vbFirstFourDays 2 Start with the first week that has at least four days in the year.
vbFirstFullWeek 3 Start with the first full week of the year.
Notes
If you try to format a number without specifying format, Format provides functionality similar to the Str function, although it is internationally aware. However, positive numbers formatted as strings using Format don’t include a leading space reserved for the sign of the value; those converted using Str retain the leading space.

If you are formatting a non-localized numeric string, you should use a user-defined numeric format to ensure that you get the look you want.

If the Calendar property setting is Gregorian and format specifies date formatting, the supplied expression must be Gregorian. If the Visual Basic Calendar property setting is Hijri, the supplied expression must be Hijri.

If the calendar is Gregorian, the meaning of format expression symbols is unchanged. If the calendar is Hijri, all date format symbols (for example, dddd, mmmm, yyyy) have the same meaning but apply to the Hijri calendar. Format symbols remain in English; symbols that result in text display (for example, AM and PM) display the string (English or Arabic) associated with that symbol. The range of certain symbols changes when the calendar is Hijri.

Formatting Symbols
Character Description
None
No formatting Display the number with no formatting.
: Time separator. In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings.
/ Date separator. In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.
C Display the date as ddddd and display the time as t t t t t, in that order. Display only date information if there is no fractional part to the date serial number; display only time information if there is no integer portion.
D Display the day as a number without a leading zero (1 - 31).
dd Display the day as a number with a leading zero (01 - 31).
ddd Display the day as an abbreviation (Sun - Sat).
dddd Display the day as a full name (Sunday - Saturday).
ddddd Display the date as a complete date (including day, month, and year), formatted according to your system's short date format setting. The default short date format is m/d/yy.
dddddd Display a date serial number as a complete date (including day, month, and year) formatted according to the long date setting recognized by your system. The default long date format is mmmm dd, yyyy.
w Display the day of the week as a number (1 for Sunday through 7 for Saturday).
ww Display the week of the year as a number (1 - 53).
m Display the month as a number without a leading zero (1 - 12). If m immediately follows h or hh, the minute rather than the month is displayed.
MM Display the month as a number with a leading zero (01 - 12). If m immediately follows h or hh, the minute rather than the month is displayed.
MMM Display the month as an abbreviation (Jan - Dec).
MMMM Display the month as a full month name (January - December).
q Display the quarter of the year as a number (1 - 4).
y Display the day of the year as a number (1 - 366).
yy Display the year as a 2-digit number (00 - 99).
yyyy Display the year as a 4-digit number (100 - 9666).
h Display the hour as a number without leading zeros (0 - 23).
hh Display the hour as a number with leading zeros (00 - 23).
n Display the minute as a number without leading zeros (0 - 59).
nn Display the minute as a number with leading zeros (00 - 59).
s Display the second as a number without leading zeros (0 - 59).
ss Display the second as a number with leading zeros (00 - 59).
t t t t t Display a time as a complete time (including hour, minute, and second), formatted using the time separator defined by the time format recognized by your system. A leading zero is displayed if the leading zero option is selected and the time is before 10:00 A.M. or P.M. The default time format is h:mm:ss.
AM/PM Use the 12-hour clock and display an uppercase AM with any hour before noon; display an uppercase PM with any hour between noon and 11:59 P.M.
am/pm Use the 12-hour clock and display a lowercase AM with any hour before noon; display a lowercase PM with any hour between noon and 11:59 P.M.
A/P Use the 12-hour clock and display an uppercase A with any hour before noon; display an uppercase P with any hour between noon and 11:59 P.M.
a/p Use the 12-hour clock and display a lowercase A with any hour before noon; display a lowercase P with any hour between noon and 11:59 P.M.
AMPM Use the 12-hour clock and display the AM string literal as defined by your system with any hour before noon; display the PM string literal as defined by your system with any hour between noon and 11:59 P.M. AMPM can be either uppercase or lowercase, but the case of the string displayed matches the string as defined by your system settings. The default format is AM/PM.
0
Digit placeholder Display a digit or a zero. If the expression has a digit in the position where the 0 appears in the format string, display it; otherwise, display a zero in that position. If the number has fewer digits than there are zeros (on either side of the decimal) in the format expression, display leading or trailing zeros. If the number has more digits to the right of the decimal separator than there are zeros to the right of the decimal separator in the format expression, round the number to as many decimal places as there are zeros. If the number has more digits to the left of the decimal separator than there are zeros to the left of the decimal separator in the format expression, display the extra digits without modification.
#
Digit placeholder
Display a digit or nothing. If the expression has a digit in the position where the # appears in the format string, display it; otherwise, display nothing in that position. This symbol works like the 0 digit placeholder, except that leading and trailing zeros aren't displayed if the number has the same or fewer digits than there are # characters on either side of the decimal separator in the format expression.
.
Decimal placeholder
In some locales, a comma is used as the decimal separator. The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. If you always want a leading zero displayed with fractional numbers, use 0 as the first digit placeholder to the left of the decimal separator instead. The actual character used as a decimal placeholder in the formatted output depends on the Number Format recognized by your system.
%
Percent placeholder The expression is multiplied by 100. The percent character (%) is inserted in the position where it appears in the format string.
,
Thousand separator In some locales, a period is used as a thousand separator. The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. Standard use of the thousand separator is specified if the format contains a thousand separator surrounded by digit placeholders (0 or #). Two adjacent thousand separators or a thousand separator immediately to the left of the decimal separator (whether or not a decimal is specified) means "scale the number by dividing it by 1000, rounding as needed." You can scale large numbers using this technique. For example, you can use the format string "##0,," to represent 100 million as 100. Numbers smaller than 1 million are displayed as 0. Two adjacent thousand separators in any position other than immediately to the left of the decimal separator are treated simply as specifying the use of a thousand separator. The actual character used as the thousand separator in the formatted output depends on the Number Format recognized by your system.
:
Time separator In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings.
/
Date separator In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings.
E- E+ e- e+
Scientific format If the format expression contains at least one digit placeholder (0 or #) to the right of E-, E+, e-, or e+, the number is displayed in scientific format and E or e is inserted between the number and its exponent. The number of digit placeholders to the right determines the number of digits in the exponent. Use E- or e- to place a minus sign next to negative exponents. Use E+ or e+ to place a minus sign next to negative exponents and a plus sign next to positive exponents.
- + $ ( ) space
Display a literal character To display a character other than one of those listed, precede it with a backslash (\) or enclose it in double quotation marks (" ").
\
Display the next character in the format string Many characters in the format expression have a special meaning and can't be displayed as literal characters unless they are preceded by a backslash. The backslash itself isn't displayed. Using a backslash is the same as enclosing the next character in double quotation marks. To display a backslash, use two backslashes (\). Examples of characters that can't be displayed as literal characters are the date- and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, and /:), the numeric-formatting characters (#, 0, %, E, e, comma, and period), and the string-formatting characters (@, &, <, >, and !).
"ABC"
Display the string inside the double quotation marks To include a string in format from within code, you must use Chr(34) to enclose the text (34 is the character code for a double quotation mark).
@
Character placeholder Display a character or a space. If the string has a character in the position where the @ appears in the format string, display it; otherwise, display a space in that position. Placeholders are filled from right to left unless there is an ! character in the format string. See below.
&
Character placeholder Display a character or nothing. If the string has a character in the position where the & appears, display it; otherwise, display nothing. Placeholders are filled from right to left unless there is an ! character in the format string. See below.
<> Display all characters in lowercase format.
>
Force uppercase Display all characters in uppercase format.
!
Force left to right fill of placeholders The default is to fill from right to left.
Named Formats
Visual Basic provides several standard formats to use with the Format function. Instead of using symbols, you specify these formats by name in the format argument of the Format function. Always enclose the format name in double quotation marks (""). The following table lists the format names you can use.

Named format Description
General Number Shows numbers as entered.
Currency Shows negative numbers inside parentheses.
Fixed Shows at least one digit.
Standard Uses a thousands separator.
Percent Multiplies the value by 100 with a percent sign at the end.
Scientific Uses standard scientific notation.
General Date Shows date and time if expression contains both. If expression is only a date or a time, the missing information is not displayed.
Long Date Uses the Long Date format specified in the Regional Settings dialog box of the Microsoft Windows Control Panel.
Medium Date Uses the dd-mmm-yy format (for example, 03-Apr-93)
Short Date Uses the Short Date format specified in the Regional Settings dialog box of the Windows Control Panel.
Long Time Shows the hour, minute, second, and "AM" or "PM" using the h:mm:ss format.
Medium Time Shows the hour, minute, and "AM" or "PM" using the "hh:mm AM/PM" format.
Short Time Shows the hour and minute using the hh:mm format.
Yes/No Any nonzero numeric value (usually - 1) is Yes. Zero is No.
True/False Any nonzero numeric value (usually - 1) is True. Zero is False.
On/Off Any nonzero numeric value (usually - 1) is On. Zero is Off.
Multiple Formats
A user-defined format expression can have from one to four sections separated by semicolons. (If the format argument contains one of the named formats, only one section is allowed.)

If you use The result is
One section The format expression applies to all values.
Two sections The first section applies to positive values and zeros, the second to negative values.
Three sections The first section applies to positive values, the second to negative values, and the third to zeros.
Four sections The first section applies to positive values, the second to negative values, the third to zeros, and the fourth to Null values.
The following example has two sections: the first defines the format for positive values and zeros; the second section defines the format for negative values.

$#,##0;($#,##0)
If you include semicolons with nothing between them, the missing section is printed using the format of the positive value. For example, the following format displays positive and negative values using the format in the first section and displays "Zero" if the value is zero.
$#,##0;;\Z\e\r\o
Note If you try to format a number without specifying format, Format provides the same functionality as the Str function. However, positive numbers formatted as strings using Format lack the leading space reserved for displaying the sign of the value; whereas, those converted using Str retain the leading space.
Examples
The following conversions assume that the country in the Windows Control Panel is set to "English (United States)."

Format syntax Result
Format(8315.4, "00000.00") 08315.40
Format(8315.4, "#####.##") 8315.4
Format(8315.4, "##,##0.00") 8,315.40
Format(315.4, "$##0.00") $315.40
Format(7, "0.00%") 700.00%
Format("This Is A Test", "<") this is a test
Format("This Is A Test", ">") THIS IS A TEST
Format(Now, "m/d/yy") 1/27/93
Format(Now, "dddd, mmmm dd, yyyy") Wednesday, January 27, 1993
Format(Now, "d-mmm") 27-Jan
Format(Now, "mmmm-yy") January-93
Format(Now, "hh:mm AM/PM") 07:18 AM
Format(Now, "h:mm:ss a/p") 7:18:00 a
Format(Now, "d-mmmm h:mm" 27-January 7:18
Format(Now, "d-mmmm-yy") 27-January-93
Format(Now, "d mmmm") 27 January
Format(Now, "mmmm yy") January 93
Format(Now, "hh:mm AM/PM") 08:50 PM
Format(Now, "h:mm:ss a/p") 8:50:35 p
Format(Now, "h:mm") 20:50
Format(Now, "h:mm:ss") 20:50:35
Format(Now, "m/d/yy h:mm") 1/27/93 20:50
Format (format) Positive 5 Negative 5 Decimal .5 Null
Zero-length string 5 -5 0.5
0 5 -5 1
0.00 5.00 -5.00 0.50
#,##0 5 -5 1
#,##0.00;;;Nil 5.00 -5.00 0.50 Nil
$#,##0;($#,##0) $5 ($5) $1
$#,##0.00;($#,##0.00) $5.00 ($5.00) $0.50
0% 500% -500% 50%
0.00% 500.00% -500.00% 50.00%
0.00E+00 5.00E+00 -5.00E+00 5.00E-01
0.00E-00 5.00E00 -5.00E00 5.00E-01

Baca Selengkapnya...