Menu Horisontal

Sabtu, 07 September 2013

Efficiently Paging Through Large Amounts of Data (VB)

Sumber : http://www.asp.net/web-forms/tutorials/data-access/paging-and-sorting/efficiently-paging-through-large-amounts-of-data-vb


Introduction

As we discussed in the preceding tutorial, paging can be implemented in one of two ways:
  • Default Paging can be implemented by simply checking the Enable Paging option in the data Web control s smart tag; however, whenever viewing a page of data, the ObjectDataSource retrieves all of the records, even though only a subset of them are displayed in the page
  • Custom Paging improves the performance of default paging by retrieving only those records from the database that need to be displayed for the particular page of data requested by the user; however, custom paging involves a bit more effort to implement than default paging
Due to the ease of implementation just check a checkbox and you re done! default paging is an attractive option. Its na�ve approach in retrieving all of the records, though, makes it an implausible choice when paging through sufficiently large amounts of data or for sites with many concurrent users. In such circumstances, we must turn to custom paging in order to provide a responsive system.
The challenge of custom paging is being able to write a query that returns the precise set of records needed for a particular page of data. Fortunately, Microsoft SQL Server 2005 provides a new keyword for ranking results, which enables us to write a query that can efficiently retrieve the proper subset of records. In this tutorial we ll see how to use this new SQL Server 2005 keyword to implement custom paging in a GridView control. While the user interface for custom paging is identical to that for default paging, stepping from one page to the next using custom paging can be several orders of magnitude faster than default paging.
Note: The exact performance gain exhibited by custom paging depends on the total number of records being paged through and the load being placed on the database server. At the end of this tutorial we ll look at some rough metrics that showcase the benefits in performance obtained through custom paging.

Step 1: Understanding the Custom Paging Process

When paging through data, the precise records displayed in a page depend upon the page of data being requested and the number of records displayed per page. For example, imagine that we wanted to page through the 81 products, displaying 10 products per page. When viewing the first page, we d want products 1 through 10; when viewing the second page we d be interested in products 11 through 20, and so on.
There are three variables that dictate what records need to be retrieved and how the paging interface should be rendered:
  • Start Row Index the index of the first row in the page of data to display; this index can be calculated by multiplying the page index by the records to display per page and adding one. For example, when paging through records 10 at a time, for the first page (whose page index is 0), the Start Row Index is 0 * 10 + 1, or 1; for the second page (whose page index is 1), the Start Row Index is 1 * 10 + 1, or 11.
  • Maximum Rows the maximum number of records to display per page. This variable is referred to as maximum rows since for the last page there may be fewer records returned than the page size. For example, when paging through the 81 products 10 records per page, the ninth and final page will have just one record. No page, though, will show more records than the Maximum Rows value.
  • Total Record Count the total number of records being paged through. While this variable isn t needed to determine what records to retrieve for a given page, it does dictate the paging interface. For example, if there are 81 products being paged through, the paging interface knows to display nine page numbers in the paging UI.
With default paging, the Start Row Index is computed as the product of the page index and the page size plus one, whereas the Maximum Rows is simply the page size. Since default paging retrieves all of the records from the database when rendering any page of data, the index for each row is known, thereby making moving to Start Row Index row a trivial task. Moreover, the Total Record Count is readily available, as it s simply the number of records in the DataTable (or whatever object is being used to hold the database results).
Given the Start Row Index and Maximum Rows variables, a custom paging implementation must only return the precise subset of records starting at the Start Row Index and up to Maximum Rows number of records after that. Custom paging provides two challenges:
  • We must be able to efficiently associate a row index with each row in the entire data being paged through so that we can start returning records at the specified Start Row Index
  • We need to provide the total number of records being paged through
In the next two steps we ll examine the SQL script needed to respond to these two challenges. In addition to the SQL script, we ll also need to implement methods in the DAL and BLL.

Selasa, 09 Juli 2013

Visual Basic 6 Check Windows Service Running Or Not

kadangkala dalam program dengan visual basic 6 kita perlu untuk mengecek beberapa service windows, apakah sudah jalan apa tidak. Nah bagi yang membutuhkan kode untuk mengeceknya inilah function nya


Function IsServiceRunning(sServiceName As String) As Boolean
    Dim objInst As Object, objSet As Object
    IsServiceRunning = False
    Set objSet = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Service")
    For Each objInst In objSet
        If (UCase(sServiceName) = UCase(objInst.Name)) And (UCase(objInst.State) = UCase("Running")) Then
            IsServiceRunning = True
        End If
    Next
End Function


Sumber : http://vbgue.blogspot.com/

Sabtu, 15 Juni 2013

Enkripsi dan Dekripsi di SQL Server

Sumber : http://ngisorceri.wordpress.com/2010/12/20/enkripsi-dan-dekripsi-di-sql-server/

Seringkali kita memerlukan enkripsi data dalam salah satu Field di database kita, fungsi ini kita perlukan karena bisa jadi kita tidak menginginkan  seseorang membaca data dari tabel kita. Salah satu contoh nya adalah password. Penyimpanan password dalam suatu table database  memerlukan suatu pengamanan yang tidak sembarangan, sangat disarankan password disimpan dalam keadaan terenkripsi sehingga apabila ada seseorang yang tidak berkepentingan mendapatkan isi dari database user kita dan didalamnya tersimpan password dari user di system kita, orang tersebut masih relatif sulit menebak password user tersebut.
Ada banyak sekali metode encrypt data, tapi inti dari metode -metode tersebut dikatakan bagus jika,
  • Hasilnya sulit di tebak : bisa jadi dengan password yang sama dan keyworld yang sama dalam waktu yang berbeda akan menghasilkan nilai yang berbeda, maka metode ini akan sulit sekali dibongkar.
  • proses encrypt /decrypt cepat : seringkali suatu encrypt yang sulit di  bongkar memerlukan waktu saat melakukan encrypt, proses ini sebenarnya tidak terlalu pengaruh jika pengakses system kita tidak banyak,tapi akan sangat mengganggu jika pengakses kita banyak.
Untuk melakukan encrypt/decrypt dalam perintah Transact SQL, SQL Server telah menyediakan beberapa fungsi internal yang dapat kita gunakan, fungsi itu relatif cepat , mudah digunakan, dan yang terpenting relatif sulit di bongkar, karena selalu menghasilkan nilai yang berubah. Kita tinggal mengkombinasikan fungsi convert dan  EncryptByPassPhrase untuk membuat perintah encrypt, dan fungsi convert dan decryptbypassphrase untuk mengembalikan nilai fungsi. Berikut ini adalah perintahnya
create Function [dbo].[encrypt] (@Password varchar(100) ,@Key varchar(100))
  RETURNS varbinary(max)WITH EXECUTE AS CALLER
      BEGIN
         return EncryptByPassPhrase(@key, convert(varchar(100),@password))
      END
untuk membuat fungsi decrypt
Create Function [dbo].[decrypt] (@Key varchar(100),@EncryptPwd  varbinary(max))
   RETURNS varchar(100)WITH EXECUTE AS CALLER
    BEGIN
       return convert(varchar(100),convert(varchar(100),decryptbypassphrase(@Key,@encryptPwd)))
    END
Setelah anda buat, selanjutnya kita test hasilnya dengan script berikut
declare @password as varchar(100)
declare @key as varchar(100)
set @password='Passw0rd'
set @key='Supriyanto'
declare @hsl1 as  varbinary(max)
declare @hsl2 as varbinary(max)
declare @decr as varchar(100)
declare @decr1 as varchar(100)
print 'Eksekusi pertama '
SELECT @hsl1= [dbo].[encrypt] (@password,@Key)
print @hsl1
select @decr=dbo.decrypt(@key,@hsl1)
print @decr 
print '' 
print 'eksekusi kedua'
SELECT @hsl2= [dbo].[encrypt] (@password,@Key)
print @hsl2
select @decr1=dbo.decrypt(@key,@hsl2)
print @decr1
Test Hasil encrypt/decrypt
Test Hasil encrypt/decrypt
Hasilnya,dengan key dan password yang sama hasil dari @hsl1 dan @hsl2 berbeda, dan dari hasil @hsl1 dan @hsl2 ketika di decrypt dengan key yang sama akan kembali ke nilai aslinya. Selamat mencoba

Selasa, 11 Juni 2013

Ascii Kode Untuk Garis (Untuk Print Dot Matrix VB6)




Cara Penggunaan :
Buat Fungsi seperti dibawah ini


Function Ln(KodeDesimal As Integer, Optional Jumlah As Integer) As String
Dim i As Integer
    If Jumlah = 0 Then Jumlah = 1
    For i = 1 To Jumlah
        Ln = Ln & Chr$(KodeDesimal)
    Next i
End Function

Cara penggunaannya
Contoh Membuat garis dobel sebanyak 10 karakter :

 Ln(205, 10)


Jumat, 07 Juni 2013

CRUD Dengan CodeIgniter + Ajax + JQuery (PART I - Instalasi CodeIgniter)

Sumber : http://coretanasha21.blogspot.com/2012/07/crud-dengan-codeigniter-ajax-jquery.html#more
Hello pembaca! Pada tulisan kali ini saya akan menjelaskan bagaimana cara membuat sebuah aplikasi CRUD sederhana dengan menggunakan CodeIgniter dengan sedikit sentuhan JQuery dan Ajax agar aplikasi yang kita buat lebih ciamik. Kenapa membuat aplikasi CRUD? Yups karena itu merupakan dasar dari semua jenis website yang nantinya dikembangkan.

Sebelum lanjut, ada baiknya kita berkenalan dengan CodeIgniter terlebih dahulu. Jadi apa itu CodeIgniter? CodeIgniter adalah sebuah Framework PHP yang membantu kita dalam mengembangkan sebuah aplikasi web lebih cepat. Tunggu dulu, apa itu Framework? Jadi Framework itu adalah sebuah kerangka kerja, bisa diibaratkan sebagai bahan setengah jadi. Bahan setengah jadinya PHP? Okay saya makin bingung, coba jelaskan lagi! Okay saya jelaskan lagi lebih detailnya.


Okay jadi begini, misalkan saya sedang mendapatkan project dari seorang client. Kemudian client tersebut meminta saya untuk membuat sebuah website A dengan spesifikasi  A, B, C, dan D. Saya membuat project itu dengan menuliskan code dari awal sehingga aplikasi tersebut rampung dan siap digunakan. Nah, beberapa bulan kemudian seorang client yang berbeda meminta saya untuk membuat sebuah website B dengan spesifikasi A,B,C,D, dan E. Agar pembuatan aplikasi lebih cepat, maka saya menggunakan source code dari website A. Dengan demikian pada website B saya hanya perlu menambahkan spesifikasi E saja, karena spesifikasi A,B,C, dan D sudah dibuat sebelumnya, sehingga tentu pembuatan aplikasi akan lebih cepat dari sebelumnya. Jadi website A tersebut bisa disebut sebagai sebuah Framework.

Jadi saya bisa dong membuat Framework saya sendiri? Oh tentu saja bisa! Sekarang sudah mengerti kan apa yang disebutkan dengan Framework?

Okay cukup sudah penjelasan tentang Framework, mari kita langsung menyentuh si CodeIgniter.

1. Langkah pertama, download terlebih dahulu CodeIgniter di sini
2. Kemudian jika kamu sudah mendownload CodeIgniter, extract CodeIgniter_2.x.x.zip ke folder web server kamu baik htdocs atau www. Kemudian, ubahlah nama folder CodeIgniter_2.x.x tersebut sesuai dengan keinginan kamu. Jadi pada tuturial ini saya akan menggunakan nama webku. Jadi untuk latihan gunakan saja nama webku
3. Kemudian, buka web browser kamu, boleh Firefox, Google Chrome atau IE. Pastikan sebelumnya Apache dan PHP kamu sudah jalan.
4. Nah untuk mencoba apakah CodeIgniter sudah terinstall, ketika http://localhost/webku di web browser kamu. Jika kamu melihat halaman seperti gambar di bawah ini, berarti kamu sudah berhasil menginstall CodeIgniter di server kamu.


Okay, sekian untuk installasi CodeIgniter

Rabu, 01 Mei 2013

Mengenal Dasar SQL Server 2008

Sumber : http://news.palcomtech.com/2012/05/tutorial-1-mengenal-dasar-sql-server-2008/
 
 Sasaran:
  1. Dapat mengubah properties SQL Server 2008 agar bisa diakses banyak Client
  2. Dapat membuat Database dan Tabel di SQL Server 2008
  3. Dapat membuat User login ke SQL Server 2008
PENDAHULUAN
Pembuatan aplikasi database menggunakan Delphi 2007 dan SQL Server 2008 dapat dibedakan 2(dua) jenis dari sisi pemakainya, yaitu:
  1. Aplikasi Stand Alone, artinya aplikasi yang akan dibuat hanya akan dipakai/digunakan oleh satu komputer.
  2. Aplikasi Client-Server, artinya aplikasi yang akan dibuat akan digunakan oleh banyak client didalam jaringan.
Pemilihan jenis aplikasi yang akan dibuat akan berpengaruh terhadap Setting SQL Server 2008 dan Folder tempat penyimpanan Database. Pada studi kasus yang akan dibuat “Sistem Informasi Mini Market” akan dibuat aplikasi jenis Client-Server agar aplikasi yang dibuat bisa digunakan oleh banyak client (Operator Kasir, bagian persediaan, admin aplikasi dan pemilik).
SQL Server 2008 yang sudah terinstall hanya jalan di local server, artinya database dan tabel yang ada hanya bisa diakses dari komputer server tetapi tidak bisa diakses dari komputer lain (client) dalam jaringan. Agar bisa diakses oleh Client maka SQL Server 2008 yang sudah terinstall ada beberapa Properties SQL Server 2008 yang harus di setting ulang.
MENGATUR PROPERTIES SQL SERVER 2008
Sebelum mengatur properties SQL Server 2008 buat folder terlebih dahulu untuk penyimpanan database dan tempat membackup database (buat folder  D:\DatabaseMiniMarket dan D:\BackUpDatabase)

Langkah 1

Login ke SQL Server Athentication Windows
Untuk bisa mengatur properties server, login terlebih dahulu ke Server Authentication windows, dengan cara :
  1. Buka Microsoft SQL Server 2008
  2. Pilih SQL Server Managemen Studio
  3. Isi Dialog Login
  • Server type : Pilih Database Engine
  • Server name : Tuliskan Nama Server, atau Pilih Browse dikotak Server name, klik Folder Database Engine, klik Nama Server
Authentication  : Windows Authentication

Klik Tombol Connect.

Langkah 2

Merubah Properties Server
Langkah-langkah mengatur properties SQL Server 2008, adalah :
  1. Klik Kanan di Nama Server pilih Properties
  2. Klik Folder Security, dikotak Select Page
  • Klik radiobutton SQL Server and Windows Authentication
  • Klik radiobutton Failed Only
        3. Klik Folder Database Setting dikotak Select Page
Pada Kotak data, tuliskan tempat database akan disimpan atau klik tombol Browse dan pilih dimana database akan disimpan. (d:\DatabaseMiniMarket)
Pada Kotak Log, tuliskan tempat log database akan disimpan atau klik tombol Browse dan pilih dimana Log database akan disimpan. (d:\DatabaseMiniMarket)

Langkah 3

Membuat  User login
Tujuan pembuatan user login adalah menentukan orang-orang yang berhak masuk ke SQL Server 2008 dan pengaturan hak akses user login. Adapun langkah-langkah membuat user login adalah sebagai berikut :
  1. Klik Folder Security
  2. Klik SubFolder Login
  3. Klik Kanan Pilih New Login

  • Klik Folder General pada kotak Select page.
Pada Kotak Login name tuliskan user yang akan dibuat misal adminserver. Klik radiobutton SQL Server authentication. Kemudian Tuliskan password pada kotak passwor misal 123. Lalu luliskan Confirm Password yaitu 123. Buang tanda Check pada Enforce password expiration.
  • Klik Folder Server Role pada Kotal Select Page.

Pilih sysadmin, artinya user sebagai admin server.
  •  Klik Folder User Mapping pada kotak Select Page

  • Pilih salah satu database yang ada misal master
  • Pilih dbowner pada kotak dibawahnya
Dan ikuti langkah-langkahnya dibawah ini :
  1. Klik Tombol OK
  2. Klik Kanan Mouse Pada Nama Server
  3. Pilih ReStart, agar semua perubahan Propert.ies akan dijalankan
  4. Keluar dari SQL Server (File-Exit)

Langkah 4

Login SQL Server Authentication
1. Buka SQL Server 2008
2. Isi Dialog Login,
  • Server type, Pilih Database Engine
  • Server name, Tuliskan Nama Server, atau
  • Pilih Browse dikotak Server name
  • Klik Folder Database Engine
  • Klik Nama Server
Authentication: SQL Server Authentication
  • Login, isi dengan username yang telah dibuat (adminserver)
  • Password, masukan password untuk username (123)
3. Klik Tombol Connect, Jika Perubahan properties dan pembuatan user berhasil maka connect akan berhasil

Langkah 5

Membuat  Database
Sebelum database dan tabel dibuat sebaiknya anda melakukan pengecekan terlebih dahulu option designer database, dengan cara :
Klik Menu Tools – Pilih Options.
  1. Pada Kotak Options klik Designers
  2. Pada table options, buang tanda check pada ‘Prevent saving changes that required tabel re-creation’  karena jika tanda check belum dibuang maka tabel yang dibuat tidak bisa diedit/modifikasi.
  3. Klik Tombol OK.
Langkah-langkah membuat database adalah sebagai berikut,
  1. Klik Folder Database
  2. Klik Kanan Mouse
  3. Pilih New Database


  • Pada Kotak database name Tuliskan: MiniMarket
  • Pada Kotak owner tuliskan : adminserver
Klik Tombol OK.

Langkah 6

Menambahkan Tabel Ke Database
Untuk menambahkan tabel kedalam database yang dibuat adalah sebagai berikut,
  1. Klik Folder Database
  2. Klik Subfolder MiniMarket
  3. Klik Subfolder Table
  4. Klik Kanan Mouse
  5. Pilih New Table

  • Pada kotak Column Name, tuliskan Field-Field tabel yang akan dibuat
  • Pada kotak Data Type, tuliskan/pilih tipe data dan ukuran field
  • Jika table mempunyai Primary Key, klik di Column Name yang akan dijadikan Primary Key, Klik Kanan Mouse pilih Set Primary Key
  • Simpan Table, dengan cara mengklik icon Disket dibagian atas dan tuliskan nama tabel ‘Person’
Untuk menambahkan tabel lainnya ulangi langkah a s/d e. Buat Semua tabel yang akan digunakan pada Sistem Informasi MiniMarket (11 Tabel) yang ada dibagian akhir tutorial 1 ini.

Langkah 7

Membackup Database
Membackup database bertujuan membuat cadangan database untuk digunakan  pada saat dibutuhkan.
Langkah-langkah untuk membackup database pada SQL Server adalah sbb :
  •  Klik Folder Server Object
  •  Klik SubFolder Backup Device
  •  Klik Kanan Mouse
  •  Pilih Backup a Database

  • Remove Folder backup dikotak dibawah Back up to.
  • Pada Kotak database pilih database yang akan di Backup (Pilih MiniMarket)
  • Klik Tombol Add.

Pada Kotak File name, Tuliskan Folder tempat Data akan dibackup beserta nama file backupnya, contoh:
D:\BackUpDatabase\MiniMarket_Backup
Artinya folder tempat backup adalah D:\BackUpDatabase, sedangkan nama file Backup adalah MiniMarket_Bakcup
  • Klik Tombol OK dan OK

Langkah 8

Merestore Database
Langkah-langkah Restore Database adalah sbb:
  • Klik Folder Database
  • Klik Kanan Mouse
  •  Pilih Restore Database
 

  •  Pada kotak to Database pilih MiniMarket
  •  Klik RadioButton From Device
  •  Klik tombol Browse disamping kota From Device

  •  Klik Tombol Add.

  •  Dikotak Select the file, pilih folder tempat database hasil backup (D:\BackUpDatabase)
  •  Dikotak File name, tuliskan nama file backup yang akan di restore tuliskan MiniMarket_BackKUp
  •  Klik Tombol OK dan OK
  •  Klik  CheckBox  Restore,
  •  Pilih Folder Options

  •  Klik CheckBox Overwrite the existing database
  •  Klik Tombol OK

Sabtu, 16 Maret 2013

Cara Membaca & Menulis INI File Vb6


Sumber : http://arifsoftgames.blogspot.com/2013/02/cara-membaca-menulis-ini-file-vb6.html

Pasti ada orang bertanya-tanya bagaimana menggunakan file INI untuk VB6???, nah Pada kesempatan ini saya akan memberikan cara untuk membaca dan menulis INI File pada VB6. Semoga membantu :)





Bahan - Bahan :
1. Visual Basic 6, kalo belom punya pake yang portable gak apa-apa. Download disini | Password : arifsoftgames
2. Kesabaran

Caranya :
1. Tambahkan 3 TextBox, 1 Timer dan 1 Command Button
Saya Menyusun Seperti ini.
2. Buat 2 Module
Module 1 kasih nama : Read
Module 2 kasih nama : Write
Klik kanan, pilih Add lalu klik Module
Sekarang Tahap Codingnya :
Klik 2x pada daerah form 1 dan masukkan code ini :
'Coding Form
Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
Text1.Text = ReadIniValue(App.Path & "\INFO.ini", "Default", "Text1")
    Text2.Text = ReadIniValue(App.Path & "\INFO.ini", "Default", "Text2")
    Text3.Text = ReadIniValue(App.Path & "\INFO.ini", "Default", "Text3")
    Timer1.Enabled = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = 0 Then Cancel = 1
End Sub

Private Sub Timer1_Timer()
WriteIniValue App.Path & "\INFO.ini", "Default", "Text1", Text1.Text
    WriteIniValue App.Path & "\INFO.ini", "Default", "Text2", Text2.Text
    WriteIniValue App.Path & "\INFO.ini", "Default", "Text3", Text3.Text
End Sub

Pada Module 1 / Read masukkan Code ini
'Fungsi Module Read
Option Explicit

Public Function ReadIniValue(INIpath As String, KEY As String, Variable As String) As String
Dim NF As Integer
Dim Temp As String
Dim LcaseTemp As String
Dim ReadyToRead As Boolean
    
AssignVariables:
        NF = FreeFile
        ReadIniValue = ""
        KEY = "[" & LCase$(KEY) & "]"
        Variable = LCase$(Variable)
    
EnsureFileExists:
    Open INIpath For Binary As NF
    Close NF
    SetAttr INIpath, vbArchive
    
LoadFile:
    Open INIpath For Input As NF
    While Not EOF(NF)
    Line Input #NF, Temp
    LcaseTemp = LCase$(Temp)
    If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
    If LcaseTemp = KEY Then ReadyToRead = True
    If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
        If InStr(LcaseTemp, Variable & "=") = 1 Then
            ReadIniValue = Mid$(Temp, 1 + Len(Variable & "="))
            Close NF: Exit Function
            End If
        End If
    Wend
    Close NF
End Function

Pada Module 2 / Write masukkan Code ini :
'Fungsi Module Write
Option Explicit

Public Function WriteIniValue(INIpath As String, PutKey As String, PutVariable As String, PutValue As String)
Dim Temp As String
Dim LcaseTemp As String
Dim ReadKey As String
Dim ReadVariable As String
Dim LOKEY As Integer
Dim HIKEY As Integer
Dim KEYLEN As Integer
Dim VAR As Integer
Dim VARENDOFLINE As Integer
Dim NF As Integer
Dim X As Integer

AssignVariables:
    NF = FreeFile
    ReadKey = vbCrLf & "[" & LCase$(PutKey) & "]" & Chr$(13)
    KEYLEN = Len(ReadKey)
    ReadVariable = Chr$(10) & LCase$(PutVariable) & "="
        
EnsureFileExists:
    Open INIpath For Binary As NF
    Close NF
    SetAttr INIpath, vbArchive
    
LoadFile:
    Open INIpath For Input As NF
    Temp = Input$(LOF(NF), NF)
    Temp = vbCrLf & Temp & "[]"
    Close NF
    LcaseTemp = LCase$(Temp)
    
LogicMenu:
    LOKEY = InStr(LcaseTemp, ReadKey)
    If LOKEY = 0 Then GoTo AddKey:
    HIKEY = InStr(LOKEY + KEYLEN, LcaseTemp, "[")
    VAR = InStr(LOKEY, LcaseTemp, ReadVariable)
    If VAR > HIKEY Or VAR < LOKEY Then GoTo AddVariable:
    GoTo RenewVariable:
    
AddKey:
        Temp = Left$(Temp, Len(Temp) - 2)
        Temp = Temp & vbCrLf & vbCrLf & "[" & PutKey & "]" & vbCrLf & PutVariable & "=" & PutValue
        GoTo TrimFinalString:
        
AddVariable:
        Temp = Left$(Temp, Len(Temp) - 2)
        Temp = Left$(Temp, LOKEY + KEYLEN) & PutVariable & "=" & PutValue & vbCrLf & Mid$(Temp, LOKEY + KEYLEN + 1)
        GoTo TrimFinalString:
        
RenewVariable:
        Temp = Left$(Temp, Len(Temp) - 2)
        VARENDOFLINE = InStr(VAR, Temp, Chr$(13))
        Temp = Left$(Temp, VAR) & PutVariable & "=" & PutValue & Mid$(Temp, VARENDOFLINE)
        GoTo TrimFinalString:

TrimFinalString:
        Temp = Mid$(Temp, 2)
        Do Until InStr(Temp, vbCrLf & vbCrLf & vbCrLf) = 0
        Temp = Replace(Temp, vbCrLf & vbCrLf & vbCrLf, vbCrLf & vbCrLf)
        Loop
    
        Do Until Right$(Temp, 1) > Chr$(13)
        Temp = Left$(Temp, Len(Temp) - 1)
        Loop
    
        Do Until Left$(Temp, 1) > Chr$(13)
        Temp = Mid$(Temp, 2)
        Loop
    
OutputAmendedINIFile:
        Open INIpath For Output As NF
        Print #NF, Temp
        Close NF
    
End Function
' Selesai

Nah sekarang kita tinggal compile exe aja caranya :
Masuk menu file > Make EXE file
Make EXE file
Sekedar info aja, nanti file *.ini bernama INFO.ini

Membaca File Text VB6

Cara membaca file Text adalah dengan menggunakan fungsi berikut :

Versi 1
Private Function OpenTextFile() As String 
    Dim nFileNum As Integer, sText As String 
    Dim sNextLine As String, lLineCount As Long 
    nFileNum = FreeFile 
    Open "C:\daftar_driver.txt" For Input As nFileNum 
        lLineCount = 1 
        Do While Not EOF(nFileNum) 
            Line Input #nFileNum, sNextLine 
            MsgBox sNextLine 'ini akan membaca file text baris per baris 
            sNextLine = sNextLine & vbCrLf 
            sText = sText & sNextLine 
        Loop 
        OpenTextFile = sText 
    Close nFileNum 
End Function 


Versi 2
1. Menulis Ke File Text  
  Dim LocTextFile As String     LocTextFile = “C:\windows\SvAdd.txt”         Open LocTextFile For Output As #1   ‘Buka file text        Print #1, “Server_Name”    ‘Modify Baris Pertama”        Print #1, “Database_Name”  ‘Modify Baris Kedua        Print #1, “User”           ‘Modify Baris Ketiga        Print #1, “Pwd”            ‘Modify Baris Keempat     Close #1
2. Membaca dari File Text
    Dim LocTextFile As String     Dim ServerAddress  As String     Dim DatabaseName As String     Dim UserID As String     Dim PwdSql As String     LocTextFile = “C:\windows\SvAdd.txt”     Open LocTextFile For Input As #1    ‘Buka file text        Line Input #1, ServerAddress      ‘Baca Baris Pertama        Line Input #1, DatabaseName       ‘Baca Baris Kedua        Line Input #1, UserID             ‘Baca Baris Ketiga        Line Input #1, PwdSql             ‘Baca Baris Keempat     Close #1 ‘Tutup File file text
Versi 3
Ini Fungsinya
Function ReadTextFileContents(filename As String) As String
    Dim fnum As Integer, isOpen As Boolean
    On Error GoTo Error_Handler
    fnum = FreeFile()
    Open filename For Input As #fnum
    isOpen = True
    ReadTextFileContents = Input(LOF(fnum), fnum)
    
Error_Handler:
    If isOpen Then Close #fnum
    If Err Then Err.Raise Err.Number, , Err.Description
End Function

Ini Cara Pakainya
TxtPesan.Text = ReadTextFileContents(App.Path & "\service.log")



Kamis, 07 Maret 2013

How to Communicate to the Arduino in Visual Basic .NET

Sumber : http://social.technet.microsoft.com/wiki/contents/articles/14194.how-to-communicate-to-the-arduino-in-visual-basic-net.aspx

Communicating to the Arduino in the .NET platform is pretty much straightforward: The Arduino uses a virtual serial port to allow programs to be written onto it, but we can also use this port to get and send data to and from the Arduino.
Materials:

  • Arduino or Arduino Compatible Board (UNO, Mega, Etc.)
  • Compatible USB Cable to Connect the Arduino to the Host Computer
  • The Arduino Software (Available Here )
  • VB.NET 2010 or 2012 (Available Here )
I am assuming that you already have a simple knowledge of the .NET and Arduino (software & hardware) platforms. If not, there are many tutorials on the internet to help get you started. Let's begin by putting the program on the Arduino.


Step 1: Adding a Program to Send Data From the Arduino
Let's start by opening up the Arduino software, and copying/pasting in the following code:

void setup() {              
    Serial.begin(9600); 
}
 
//Sends the Number 1234 Over the Serial Port Once Every Second
void loop() {
Serial.write(1234)
delay(1000)
}

This program opens up a serial port, and sends the number string, 1234, over the port once every second in an infinite loop. The number '1234' has no special meaning, you could place any number there in place of it. Then plug in your Arduino board and upload the code to it. Leave it plugged in.

Step 2: Creating the .NET Program
Creating the .NET code in VB.NET is actually quite simple and easy to understand. Open a new VB.NET console program, clear all of the code, and paste in the following:

Module Module1
    Sub Main()
        Dim userRespond
        Dim fetchedData
        Dim writeString
        Console.WriteLine("Type R to Read Serial Port.")
        userRespond = Console.ReadLine
        If userRespond = "R" Or userRespond = "r" Then
            Dim port As New System.IO.Ports.SerialPort
            port.PortName = "COM4"
            port.Open()
            port.BaudRate = 9600
            fetchedData = port.ReadByte
            Console.WriteLine(fetchedData)
            Console.ReadLine()
  Else
            Console.WriteLine("Not a Recognized Command.")
        End If
    End Sub
End Module

This code should be fairly simple. It opens a new console window, then it asks the user if they want to get the data from the port, next (if they said yes), it opens up a new COM port and gets the data, finally it writes it to the console. You may need to change COM4 to the correct port for your Arduino. It lists what port Arduino is on in the Arduino software bottom right corner. You can not write a new program to the Arduino when this software is running, for it gives an error that says that the COM port is busy.

Step 3: Testing
To use this program, be sure your Arduino is plugged in, and it is running the code from step 1. Now, run the program from above and type in R. It may take a second (the Arduino only sends it once per second), but the number 1234 will come up! If you change the number 1234 in the Arduino code to "hello" and upload it and run the .NET program, it will only give you the decimal value for a lower-case h. This is because this program can only read one byte at a time. See if you can change it up to read the whole word and convert it to unicode! Post your inventions!