Editor


Object yang digunakan :

1. Textbox

2. CommonDialog

3. 5 Command Button

Nb : Komponen CommonDialog dapat diaktifkan dengan cara tekan CTRL+T lalu pilih

Microsoft Common Dialog Control 6.0.

Scrip pada form Load

Private Sub Form_Load()

Dim strFileName As String

Me.Move (Screen.Width - Me.Width) / 2, _

(Screen.Height - Me.Height) / 2

End Sub

Script pada button new

Private Sub new_Click()

‘ cd adalah nama CommonDialog dan saveastxtetc adalah nama form nya

cd.text = ""

saveastxtetc.Caption = "File Opener - Untitled"

End Sub

Script pada button O atau open

Private Sub o_Click()

' Set CancelError dengan nilai true

' jika user menekan tombol cancel,

cd.CancelError = True

On Error GoTo ErrHandler

' Set tipe file yang akan di save nanti

cd.Filter = "Text Files (*.txt)|*.txt| " & _

"All Files (*.*)|*.*| "

'set default save pada format *.txt

cd.FilterIndex = 1

' Menampilkan Dialog Box dan

' menyimpan file yang dipilih ke

'variabel strFileName

cd.ShowOpen

strFileName = cd.FileName

' memasukan file yang dipilih ke textbox.

Open strFileName For Input As #1

cd.text = Input(LOF(1), 1)

Close #1

saveastxtetc.Caption = "File Opener - " & cd.FileTitle

Exit Sub

ErrHandler :

'user menekan tombol cancel

End Sub

Scrip untuk button save

Private Sub save_Click()

cd.CancelError = True

On Error GoTo ErrHandler

cd.Filter = "Text Files (*.txt)|*.txt| " & _

"All Files (*.*)|*.*| "

cd.FilterIndex = 1

cd.ShowSave

strFileName = cd.FileName

Open strFileName For Output As #1

Print #1, text.text

Close #1

saveastxtetc.Caption = "File Opener - " & cd.FileTitle

Exit Sub

ErrHandler:

'User pressed the Cancel button

End sub

Script untuk button print

Private Sub Print_Click()

On Error Resume Next

Dim p As String

p = text.text

Printer.Print p

Printer.EndDoc

End Sub

Script untuk button New

Private Sub new_Click()

text.text = ""

saveastxtetc.Caption = "File Opener - Untitled"

End Sub

Script untuk button exit

Private Sub ex_Click()

End

End Sub

Read more