Hosting Gratis

Pages

Showing posts with label Vb6. Show all posts
Showing posts with label Vb6. Show all posts

Sunday, December 30, 2012

Listview pada VB6

Haii brother smua....
Kali ini ane mau share tentang code vb6 khususnya listview. Bagaimana menambahkan itemas baru ke dalam list view. Berikut code nya....

listview1.ListItems.Add ,,"items1"
listview1.ListItems.Add ,,"items2"
listview1.ListItems.Add ,,"items3"
listview1.ListItems.Add ,,"items4"
dst.....

Untuk menambahkan chechbox kedalam listview, berikut code:


ListView1.Checkboxes = True

Untuk menambahkan checkbox dan item (menjadikan listview menjadi 2 kolom), berikut code:

ListView1.Checkboxes = True
listview1.ListItems.Add ,,"items1"
listview1.ListItems.Add ,,"items2"
listview1.ListItems.Add ,,"items3"
listview1.ListItems.Add ,,"items4"
dst.....


Untuk Operasi ListView lainya, silahkan ditunggu yach....

Ane tunggu komennya....

Monday, December 3, 2012

Update ODBC Records in VB6

  
  • Open a new Standard EXE Visual Basic project. From the menu, select "Project" and then "References." Click the check box next to "Microsoft ActiveX Data Objects 2.x" where "x" is the highest number available on your machine. Click the "OK" button to save and close.

  • Add a new button to the default "Form1" that was created by default. Name the button "cmdUpdate" and set the caption equal to "Update." This button will save any updates directly to the appropriate table(s).
  • Declare variables to store the ADODB objects and a string variable for the SQL statement itself.
    Dim oConn As ADODB.Connection
    Dim strSQL As String
    Dim oCmd as ADODB.Command

  • Connect to the database in the "Form_Load" event of "Form1."
    Set oConn = New ADODB.Connection
    oConn.ConnectionString = "DSN=MyDBName;Uid=admin;Pwd=password;"
    oConn.Open

  • Code the SQL for the "update" statement in the click event of "cmdUpdate."
    strSQL = "UPDATE myTable SET columnName = 'NewName' WHERE ID = 3;"
    oCmd.CommandText = strSQL
    oCmd.Execute

  • Tuesday, November 27, 2012

    Membuat Progressbar Pada VB 6.0

    Kalau dalam artikel sebelumnya kita membuat tampilan menggunakan shockwave flash, sekarang saya akan membagikan ilmu saya menggunakan progress bar, mungkin rekan2 pembaca udah pernah liat yang bagaimana progress bar. Nah sekarang mungkin sekarang langsung aja ya.

    Buatlah project baru dengan pilihan standart exe, kemudian tambahkan component progress bar, dengan cara klik kanan pada area toolbox. Pilih component, pada tab control. Kemudian pilih dengan cara beri tanda centang Microsoft windows common control 6.0 (SP6).
    Sudah semuanyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. LANJUT
    Sekarang kembali kearea kerja kemudian klik icon progress bar. Buatlah sebuah progressbar pada form anda. Dan buatlah sebuah command button, Seperti pada gambar berikut:

    Kemudian ketikkan coding (kalo malas copy paste aja) berikut pada coding editor anda dengan cara klik icon view code yang ada pada sudut kanan properties project:
    Private Sub Command1_Click()
    For manusia_biasa = 1 To 100000 //nilai dapat ditentukan sendiri
    Manusia_biasa = manusia_biasa + 1
    ProgressBar1.Value = i
    Next i
    End
    End Sub

    Private Sub Form_Load()
    Dim manusia_biasa As Integer
    ProgressBar1.Max = 100000 //nilai dapat ditentukan sendiri
    ProgressBar1.Min = 1
    End Sub

    Setelah itu klik tombol start atau tekan F5 pada keyboard anda.
    Sekian artikel dari saya semoga bermanfaat bagi anda sekalian. SELAMAT MENCOBA!!!!!

    Saturday, November 24, 2012

    Membuat Aplikasi Trial VB 6

    Aplikasi trial adalah aplikasi yang mempunyai batasan waktu penggunaan berdasarkan lama hari atau berapa kali aplikasi dijalankan.
    Pembuatanya biasanya digunakan pada aplikasi shareware (berbayar) yang bertujuan agar user dapat menikmati aplikasi (demo) sebelum membeli aplikasi.
    Berikut ini adalah contoh pembuatan aplikasi trial yang menggunakan lama hari penggunaan, lengkap dengan prosedur input kode registrasinya.

    [ VB 6.0 ]
    Buat Project baru dengan sebuah Form. Di bagian '(Declarations)' dari Form ketikkan :

    Const LocationReg = "System\Windows\User" 'lokasi penyimpanan d registry (ubah sesuai selera)
    Const PasswordReg = "kode" 'kode kunci registrasi

    Function GetInfoReg() As String 'fungsi utk mendapatkan info registrasi
    On Error GoTo Ero
    Dim Reg As Object
    Set Reg = CreateObject("WScript.Shell")
    GetInfoReg = Reg.RegRead("HKEY_CLASSES_ROOT\" & LocationReg & "\")
    Exit Function
    Ero:
    Reg.RegWrite "HKEY_CLASSES_ROOT\" & LocationReg & "\", Format(Now, "short date") 'memasukkan tgl sekarang
    GetInfoReg = Format(Now, "short date")
    End Function

    Function SuccessReg() As Boolean 'fungsi utk prosedur pemasukan kode registrasi
    Dim s As String
    Lagi:
    s = InputBox("Masukkan kode registrasi", "Registrasi")
    If s = PasswordReg Then
    Dim Reg As Object
    Set Reg = CreateObject("WScript.Shell")
    Reg.RegWrite "HKEY_CLASSES_ROOT\" & LocationReg & "\", "Registered" 'mendaftarkan k registry
    MsgBox "Terima kasih telah melakukan registrasi", vbInformation, "Registrasi Sukses"
    SuccessReg = True
          
    ElseIf s = "" Then
    SuccessReg = False
      
    Else
    If MsgBox("Maaf kode registrasi salah, coba lagi ?", vbYesNo + vbExclamation, "Registrasi") = vbYes Then GoTo Lagi
    SuccessReg = False
    End If
    End Function

    Lalu di bagian 'Form_Load' ketikkan :
    Dim s As String, l As Long
      
    s = GetInfoReg
    If s <> "Registered" Then 'jika belum terdaftar"
    l = 30 - (CDate(Format(Now, "short date")) - CDate(s)) 'max penggunaan trial 30 hari
          
    If l > 0 And l <= 30 Then 'jika masih ada sisa hari
    If MsgBox("Aplikasi ini hanya dapat digunakan sampai " & l & " hari lagi." & vbCrLf & _
    "Jika ingin menggunakan tanpa batasan waktu, masukkan kode registrasi" & vbCrLf & vbCrLf & _
    "Masukkan kode registrasi sekarang ?", vbYesNo + vbInformation, "Registrasi") = vbYes Then SuccessReg
              
    Else 'jika kadaluarsa
    If MsgBox("Aplikasi ini sudah tidak dapat digunakan lagi." & vbCrLf & _
    "Jika ingin menggunakannya kembali, masukkan kode registrasi" & vbCrLf & vbCrLf & _
    "Masukkan kode registrasi sekarang ?", vbYesNo + vbExclamation, "Registrasi") = vbYes Then
                  
    If SuccessReg = False Then End 'mengakhiri aplikasi
    Else
    End 'mengakhiri aplikasi
    End If
              
    End If
    End If

    FUNGSI STRING VISUAL BASIC 6


    Berhubung saya sendiri baru belajar menggunakan Visual Basic, dan kebetulan saya mendapatkan sedikit masalah ketika akan mengambil nilai dari suatu karakter di VB, saya mau coba share fungsi-fungsi string pada VB , ya sekalian kalo lupa saya bisa langsung cari dari blog saya sendiri… Hehe… Semoga saja bisa membantu teman-teman yang lain yang sama-sama lupa sintaks seperti saya… hehe…
    Fungsi-fungsi VB 6 di bawah ini digunakan untuk mengolah data string.

    Left : mengambil n karakter di sebelah kiri suatu string
    karakter = Left(“abcdef”,2) ‘karakter = “ab”
    Right : mengambil n karakter di sebelah kanan suatu string
    karakter = Right(“abcdef”,2) ‘karakter = “ef”
    Trim : menghilangkan spasi kosong di awal dan akhir suatu string
    karakter = Trim(“ abc def ”) ‘karakter = “abc def”
    Ltrim : menghilangkan spasi kosong di awal suatu string
    MyStr = Ltrim(AnyString)
    Rtrim : menghilangkan spasi kosong di akhir suatu string
    MyStr = Rtrim(AnyString)
    Ucase : mengubah suatu string menjadi huruf besar semua
    MyStr = UCase(AnyString)
    Lcase : mengubah suatu string menjadi huruf kecil semua
    MyStr = LCase(AnyString)
    Mid : mengambil n karakter dari suatu posisi yang ditetapkan
    MyStr = Mid(“abcdefghij”, 3, 4) ‘hasil “cdef”
    Len : menghitung jumlah karakter yang membentuk suatu string
    MyStr = Len(“abcdef”) ‘hasil=6
    LSet : menempatkan string di dalam string yang lain, di sebelah kiri
    MyStr = “0123456789”
    Lset MyStr = “<-Left” ‘hasil “<-Left “
    RSet : menempatkan string di dalam string yang lain, di sebelah kanan
    MyStr = “0123456789”
    Rset MyStr = “>-Right” ‘hasil “ >-Right“
    Format : mengatur string sehingga terformat sesuai yang ditentukan
    A$ = Format (5455.4, “##,##0.00”) ‘A$ = “5,459.40”
    A$ = Format (334.9, “####.##”) ‘A$ = “334.9”
    A$ = Format (5, “0.00%”) ‘A$ = “500.00%”
    A$ = Format (“HELLO”, “<”) ‘A$ = “hello”
    A$ = Format (“This is”, “>”) ‘A$ = “THIS IS”
    String: membuat string yang berisi sejumlah karakter yang digandakan
    A$ = String (5, “*”) ‘A$ = “*****”
    Chr: menghasilkan karakter yang terwakili oleh suatu angka tertentu
    A$ = Chr (65) ‘A$ = A
    A$ = Chr (97) ‘A$ = a
    A$ = Chr (62) ‘A$ = >
    Asc: menghasilkan angka ASCII dari suatu karakter tunggal
    MyNumber = Asc(‘A’) ‘’hasilnya 65
    MyNumber = Asc(‘a’) ‘’hasilnya 97
    MyNumber = Asc(‘Apple’) ‘’hasilnya 65
    Space: menghasilkan ruang kosong sebanyak n karakter
    MyStr = Space(10) ‘buat string 10 spasi
    MyStr = “Hello” & Space(10) & “World” ‘menyisipkan 10 spasi diantara kata Hello World
    InStr: menentukan apakah string tertentu berada pada string lain
    Dim CariString, CariChar, MyPos
    CariString = ‘XXpXXpXXPXXP” ‘String yang dianalis
    CariChar = “P” ‘String yang dicari “P”
    ‘mencari mulai dari kolom ke-4, hasilnya 6
    MyPos = InStr(4, CariString, CariChar, 1)
    ‘mencari mulai dari kolom ke-1, hasilnya 9
    MyPos = InStr(1, CariString, CariChar, 0)
    MyPos = InStr(CariString, CariChar) ‘hasilnya 9
    MyPos = InStr(1, SearchString, “W”) ‘hasilnya 0
    InStrRev: cari posisi string dalam string yang lain, mulai dari akhir
    i = InStrRev(StringCheck, StringMatch[, start[, compare]])
    StrComp: membandingkan dua variabel string
    StrComp(string1, string2 [, compare] )
    Jika
    Hasilnya
    string1 < string 2
    -1
    string1= string 2
    0
    string1> string 2
    1
    string1atau string 2 = Null
    Null
    Dim MyStr1, MyStr2, MyComp
    MyStr1 = “ABCD” : MyStr2 = “abcd” ‘nilai awal
    A = StrComp(MyStr1, MyStr2, 1) ‘A = 0
    A = StrComp(MyStr1, MyStr2, 0) ‘A = -1
    A = StrComp(MyStr2, MyStr1) ‘A = 1
    StrConv: mengubah huruf besar atau kecil suatu karakter string
    A$ = StrConv(“Semua Besar”, 1) ‘A$ = “SEMUA BESAR”
    A$ = StrConv(“Semua Kecil”, 2) ‘A$ = “semua kecil”
    A$ = StrConv(“pertama BESAR”, 3) ‘A$ = “Pertama Besar”
    StrReverse: mengubah urutan karakter suatu string
    A$ = StrReverse(“12345678”) ‘A$ = “87654321”
    A$ = StrReverse(“abcdefg”) ‘A$ = “gfedcba”
    Replace: menggantikan string dari kelompok string
    Replace(expression, find, replace[, start[, count[, compare]]])
    FormatCurrency: string memakai format currency yang ditetapkan
    A$ = FormatCurrency(12000, 1) ‘A$ = “$12,000.0”
    A$ = FormatCurrency(12000, 2) ‘A$ = “$12,000.00”
    Catatan, untuk mengubah mata uang, gunakan Regional Settings Currency dari sistem operasi Windows
    FormatDateTime: menghasilkan ekspresi tanggal dan waktu
    A$ = FormatDateTime(Now) ‘hasilnya “10/8/02 11:15:46 AM”
    A$ = FormatDateTime(Now, vbLongDate) ‘hasilnya “Tuesday, March 02, 2008”
    A$ = FormatDateTime(“3/2/99”, vbShortDate) ‘hasilnya “3/2/99”
    A$ = FormatDateTime(“3/2/99”, vbLongDate) ‘hasilnya “12:00:00 AM”
    FormatNumber: membuat format bilangan sesuai option yang diberikan
    FormatNumber(var1, 2)
    FormatPerCent: membuat format bilangan dalam prosentase
    A$ = FormatPerCent(0.1255, 2) ‘A$ = 12.55%
    A$ = FormatPerCent(0.12555) ‘A$ = 12.56%
    A$ = FormatPerCent(12.55, 2) ‘A$ = 1,255.00%
    A$ = FormatPerCent(12.55) ‘A$ = 1,255.00%

    Monday, November 19, 2012

    Conect Oracle with Visual Basic using ADO


    This VB6 tutorial explains how you can access an Oracle database from within Visual Basic. It is a bit short as it was thrown together from a post on thevbforums.com page. However if you check out the Sample VB6 and Oracle Source Code that goes along with it. You should be able to easily understand what is going on. Read on and enjoy as you develop your Visual Basic Oracle application.
    Oracle databases have been around for years, and although they are not as popular as their Microsoft counterpart, many business rely on Oracle backends for all their needs. Because of this, we must know how to interface with an Oracle database from within our VB6 application. This VB6 tutorial will walk us through exactly how to do this.
    To access an Oracle database it is very similar to how you access any other database. We can simply use an ADO Connection object. We set the provider to be our Oracle provider and setup our connection string and password.
    Set dbConn = New ADODB.Connection
    With dbConn
        .Provider = "OraOLEDB.Oracle"
        .Properties("Data Source") = "DatabaseName"
        .Properties("User Id") = "someuser"
        .Properties("Password") = "somepassword"
        .Open
    End With
    
    After we setup the connection all we do next is setup an ADO Command object that will be used with our oracle database. This is the same things we do for any Visual Basic database application.
    Set Cmd = New ADODB.Command
    Set Cmd.ActiveConnection = dbConn
    With Cmd
        .Parameters.Append .CreateParameter(, adVarChar, adParamOutput, 50)
        .Parameters.Append .CreateParameter(, adNumeric, adParamOutput)
    End With
    
    Now is where things start being specific to our Oracle database. Getting a result set back from an Oracle SP is not as simple as it is in SQL Server. The results must come back to the calling program in something called a reference cursor (ref cursor). This will discuss what a ref cursor is and how to implement them and get data back.

    Oracle creates an implicit cursor for every select query (I think that is the same for any database system). The cursor is simple the recordset results. If you are not going to use that result set for anything else (ie: to generate another query to execute) then you do not need to declare a cursor. But to get the result set out of Oracle you need something that is called a ref cursor. This ref cursor is more or less the same as and ADO recordset. You declare the ref cursor in code some where on the Oracle database, that ref cursor (sort of a structure in .Net) is then listed as an In and Out parameter of the SP.

    You generate the select statement you want to run then open the ref cursor you created as follows:
        Open cRefCur For 
           Select ....... (columns form whatever tables)
             From (table names)
             Where (conditions and Joins).
    
    Standard SQL here with one big exception since if using Oracle 8i or earlier, Oracle at that release level did not support the Inner and Outer Join statements. You must use the Oracle version of them. Inners are just and equal sign as in Sales.ProductID = Prodcuts.ProductID. The Outer join is a lot messier, outer joins use the same equals sign and also a plus (+) sign on the deficient side of the equal sign.

    This is the way to create the cursor:

    First we create a package that will hold all the different return types:
    CREATE OR REPLACE PACKAGE cv_types AS
      
     TYPE WellData IS RECORD(  
      WellName  Varchar2(50),
      ResultsCount Number
     );
     TYPE CV_WEllData IS REF CURSOR RETURN WellData;
        
    End;
    /
    
    Next we create a stored procedure that will use that ref cursor declared above:
    (This procedure does not have any inputs, only output paramters).
    Create Or Replace Procedure WellCounting (    
     pWellName   OUT VARCHAR2,
        pCount  OUT NUMBER,
        rsWellData IN OUT cv_types.CV_WEllData)
    
    AS
     
    BEGIN
     Open rsWellData For
      Select 
       Wells.WELLNAME,Count(RESULTS.WELLID) 
      Into 
       pWellName,
       pCount
      From 
       Wells, Results 
      Where 
       Wells.WellID = Results.WellID
       group by 
        WEllName;
                
    EXCEPTION 
      WHEN OTHERS THEN         
          ROLLBACK WORK;
          RAISE;
    
    End WellCounting;
    /
    
    We can then call the stored procedure from VB as shown in the included VB Projects.

    An example of a stored procedure with input parameters is here:
    Create Or Replace Procedure OneWellCount (    
     pWellID  IN  Number,
     pWellName   OUT VARCHAR2,
        pCount  OUT NUMBER,
        rsWellData IN OUT cv_types.CV_WEllData
        )
    
    AS
    BEGIN
     Open rsWellData For
      Select 
       Wells.WELLNAME,Count(RESULTS.WELLID) 
      Into 
       pWellName,
       pCount
      From 
       Wells, Results 
      Where 
       Wells.WellID = pWellID And 
       Wells.WellID = Results.WellID
       group by 
        WEllName;
    EXCEPTION 
      WHEN OTHERS THEN         
          ROLLBACK WORK;
          RAISE;
    
    End OneWellCount;
    /
    
    We can also test these procedures (and ref cursors) from the SQL*Plus prompt by doing the following:
    1. Enter the command SET SERVEROUTPUT ON;
    2. Now we set up variables to hold data going into and out of the SP:
      Assuming we are using the first SP displayed, the we will need 3 variables:
        VARIABLE P1   VARCHAR2(50) This is because the field we are returning is 50 chars
        VARIABLE P2   Number           This is a number coming back from the SP;
        VARIABLE P3   REFCURSOR     This will hold the result set that is coming back
    3. From the SQL prompt enter:
        EXECUTE WellCounting( :P1, :P2, :P3);
    4. If the procedures completes successfully we can now display the output.
      The variable P1 and P2 will hold the last Well Name and number of results
      for that well name. The variable P3 will hold the complete recordset that
      is being returned. To display that result in SQL*Plus enter:
        Print P3

    Saturday, November 17, 2012

    Membuat Menu Pop‐Up



    Menu pop‐up adalah menu yang muncul ketika kita mengklik kanan ketika menjalankan sebuah aplikasi,
    menu pop‐up juga sering disebut dengan menu shortcut atau menu konteks. Kita bisa menambahkan
    menu pop‐up ke dalam aplikasi yang dibuat dengan menggunakan Visual Basic yaitu dengan
    menggunakan Menu Editor dan Event MouseUp. Untuk lebih jelasnya ikuti langkah‐langkah berikut :
    1. Buat project baru pada Visual Basic 6.0 kemudian pilih Standard.exe
    2. Kemudian Klik kanan pada form dan pilih Menu Editor



    3. Kemudian Buatlah menu pada Menu Editor sebagai berikut :


    4. Langkah selanjutnya pada kode editor Copy Paste Source Code Berikut :

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
    Me.PopupMenu mnuPopup
    End If
    End Sub

    5. Selesai …. Sekarang coba jalankan program yang telah dibuat tadi kemudian test apakah pop‐up
    menunya berhasil denngan cara klik kanan pada form.

    Mengubah format currency di visual basic 6


    Sekedar sharing lagi. Berhubung dengan kerjaan saya sebagai programmer di Indonesia, terkadang customer menginginkan format currency yang sesuai dengan format yang berlaku di Indonesia, yaitu xx.xxx.xxx,xx
    Jika menggunakan format luar negeri maka dengan mudah kita dapat menggunakan syntax berikut
    Text1.Text = Format(1000000000, “currency”) atau
    Text1.Text = Format(1000000000, “$##,##0.00″)
     menghasilkan output yg sama dengan format currency
    Namun setelah mencari-cari format untuk Indonesia tidak ada, sehingga harus dimodif sendiri. Berikut cara yang saya lakukan
    Text1.Text = Format(1000000000, “currency”)
    Text2.Text = Replace(Text1.Text, “$”, “Rp. “) ‘ Rp. 1,000,000,000.00
    Text2.Text = Replace(Text2.Text, “.00″, “;00″) ‘ Rp. 1,000,000,000;00
    Text2.Text = Replace(Text2.Text, “,”, “.”) ‘ Rp.1.000.000.000;00
    Text2.Text = Replace(Text2.Text, “;00″, “,00″) ‘ Rp. 1,000,000,000;00
    Jika ada yang bisa mengubah ke format Indonesia dengan menggunakan syntax format langsung, tolong dishare disini ya.