Thursday, June 22, 2006

CH Save Process, Accomplished !

Thursday, June 22th 2006

Pheeww .... akhirnya sistem Entri Data dari spreadsheet Curah Hujan ke DB Access rampung juga. Beda dengan pembuatan sistem penyimpanan data FKlim yg makan waktu semalaman, sistem penyimpanan CH bisa gw selesaikan cuman dalam waktu 1 Jam (Rekor tercepat sampe saat ini .. hehehe emoticon).

Padahal sistemnya rada beda dengan FKlim. Keuntungan yg gw dapat dr database CH adalah tanggal yg dipisah menjadi field2 tersendiri, jd gw bisa jadikan sebagai Array di VB-nya. Kalo udah pake array gampang, variabel yg tadi jumlahnya sampe 30 bisa dijadikan dalam satu variabel array saja. Karena jadi satu variabel, otomatis statement di prosedur jg lebih pendek dan gampang dibaca.

Sub SaveCH(NamaGrid As VSFlexGrid, NamaTabel As String)
    Dim NoSta As String, Stasiun As String, Tahun As Integer
    Dim Kolom As Integer, Baris As Integer
    Dim R(31) As String, JumlahBaris As Integer, Query As String
   
    With NamaGrid
        NoSta = Mid(FormCH.CombStasiun.Text, 2, 6)
        Stasiun = Mid(FormCH.CombStasiun.Text, 11)
        Tahun = FormCH.CombThn.Text
       
        For Kolom = 1 To 12
            SystemProcess.RangeData NamaGrid, Kolom, Tahun, JumlahBaris
            For Baris = 1 To JumlahBaris
                SystemEntriDB.ValueCheck NamaGrid, Baris, Kolom, R(Baris - 1)
            Next Baris
           
            Query = "INSERT INTO " & NamaTabel & " ([NoSta],[Sta],[Year],[Month],[R1],[R2],[R3],[R4]," & _
                    "[R5],[R6],[R7],[R8],[R9],[R10],[R11],[R12],[R13],[R14],[R15],[R16],[R17],[R18]," & _
                    "[R19],[R20],[R21],[R22],[R23],[R24],[R25],[R26],[R27],[R28],[R29],[R30],[R31]) " & _
                    "VALUES ('" & NoSta & "','" & Stasiun & "','" & Tahun & "','" & Kolom & "'," & _
                    R(0) & "," & R(1) & "," & R(2) & "," & R(3) & "," & R(4) & "," & R(5) & "," & _
                    R(6) & "," & R(7) & "," & R(8) & "," & R(9) & "," & R(10) & "," & R(11) & "," & _
                    R(12) & "," & R(13) & "," & R(14) & "," & R(15) & "," & R(16) & "," & R(17) & "," & _
                    R(18) & "," & R(19) & "," & R(20) & "," & R(21) & "," & R(22) & "," & R(23) & "," & _
                    R(24) & "," & R(25) & "," & R(26) & "," & R(27) & "," & R(28) & "," & R(29) & "," & _
                    R(30) & ")"
            RSData.Open Query, DBData
        Next Kolom
    End With
End Sub

Mungkin ada masalah waktu penyimpanan data FKlim ada hikmahnya jg. Sekarang gw jadi ngerti kalo database nggak bisa sembarangan dimasukin data yang tipenya beda dengan fieldnya, jg gunanya tanda petik waktu nyimpan atau ngeload data dari database.

Cuman kalo gw liat dr query gw yg kepanjangan, kayaknya sia2 gw pake array, bisa nggak ya disingkat lagi ? Misalnya ada array yg indeksnya 30, bisa nggak ya di query gw nggak perlu tulis semua ? Jadi kayak gini :

Query = "INSERT INTO " & NamaTabel & " ([NamaField]) VALUES ('" & Array1 ... 30 & "')" 

Pasti ada caranya, ntar gw cari lg di MSDN :)

No comments:

Post a Comment