Rabu, 20 Desember 2017

Mencegah Aplikasi yang sama berjalan lebih dari 1

Selamat berkreatifitas sobat pecinta visual basic 6

Trik kali ini adalah mencegah aplikasi yang sama dijalankan lebih dari 1x. Kegunaan fitur ini untuk mencegah user menjalankan aplikasi lebih dari 1 dalam satu waktu.

Langsung saja ke sourcenya

1. Buat satu project
2. Buat Form dengan 1 textbox didalamnya
3. Masih di Form1. Masukkan Kode berikut ini

Dim PreviewsInstanceExists As Boolean
Private Sub Form_Load()
On Error GoTo ErrorHandler
     PreviewsInstanceExists = True
     Text1.LinkTopic = App.Title & "|" & Me.Name
     Text1.LinkItem = "Text1"
     Text1.LinkMode = 1 'If no Application is listening it will cause an error no DDE responce
     'If the code continues without error means ths is not the first instance
     'and we have connected with the first via DDE.
     Text1.Text = "NEW INSTANCE OPENED " & Interaction.Command
     Text1.LinkPoke
     Unload Me
ErrorHandler:
  If Err.Number = 282 Then
     'Seems no application is listening in DDE this means its the first instance.
     'Me.LinkMode = 1 'Done manualy
     Me.LinkTopic = Me.Name
     Me.Caption = "This is the first instance"
     PreviewsInstanceExists = False
  End If
End Sub


Private Sub Text1_Change()
  'NOTE: Do not have any modal forms or textboxes popping up in the _Change event
  'because after the commands in this event are executed a DDE transfer ok is sent
  If (PreviewsInstanceExists = False) And Left(Text1.Text, 19) = "NEW INSTANCE OPENED" Then
     Me.Visible = True
     Me.WindowState = vbNormal
     Me.SetFocus
     If Len(Text1.Text) > 20 Then Label2.Caption = "Command line parameters of the other instance:" & vbCrLf & Mid(Text1.Text, 20)
     Text1.Text = ""
  End If
End Sub

Sumber: Planet Source Code

control resposive ( Auto Resize ) di Fom visual basic 6

Selamat beraktifitas sobat pecinta vb6


di artikel ini aku meminjam kata yang lagi ngetrend saat ini "responsive". Kalau di web responsive, web yang bentuk tampilannya bisa mengikuti resolusi layar.

Di artikel ini, sebenarnya tidak membahas tentang resolusi layar. Tetapi komponen form ukurannya bisa berubah-ubah sesuai lebar form.

Langsung saja kita mulai acaranya, eh kodingnya.

1. Buat Form baru
2. Masukkan kontrol ke form baru, sebagai contoh aku buat 1 txtbox, 1 command button dan 1 flexgrid

 3. Buat modul baru, masukkan kode dibawah ini:

'**************************************
'Windows API/Global Declarations for :Auto Resizer
'**************************************
'Put this code in a module
Option Explicit
Dim PrevResizeX As Long
Dim PrevResizeY As Long
Public Function ResizeAll(FormName As Form)
Dim tmpControl As Control
On Error Resume Next
'Ignores errors in case the control doesn't
'have a width, height, etc.
If PrevResizeX = 0 Then
'If the previous form width was 0
'Which means that this function wasn't run before
'then change prevresizex and y and exit function
PrevResizeX = FormName.ScaleWidth
PrevResizeY = FormName.ScaleHeight
Exit Function
End If
For Each tmpControl In FormName
'A loop to make tmpControl equal to every
'control on the form
If TypeOf tmpControl Is Line Then
'Checks the type of control, if its a
'Line, change its X1, X2, Y1, Y2 values
tmpControl.X1 = tmpControl.X1 / PrevResizeX * FormName.ScaleWidth
tmpControl.X2 = tmpControl.X2 / PrevResizeX * FormName.ScaleWidth
tmpControl.Y1 = tmpControl.Y1 / PrevResizeY * FormName.ScaleHeight
tmpControl.Y2 = tmpControl.Y2 / PrevResizeY * FormName.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
Else
'Changes everything elses left, top
'Width, and height
tmpControl.Left = tmpControl.Left / PrevResizeX * FormName.ScaleWidth
tmpControl.Top = tmpControl.Top / PrevResizeY * FormName.ScaleHeight
tmpControl.Width = tmpControl.Width / PrevResizeX * FormName.ScaleWidth
tmpControl.Height = tmpControl.Height / PrevResizeY * FormName.ScaleHeight
'These four lines see the previous ratio
'Of the control to the form, and change they're
'current ratios to the same thing
End If
Next tmpControl
PrevResizeX = FormName.ScaleWidth
PrevResizeY = FormName.ScaleHeight
'Changes prevresize x and y to current width
'and height
End Function

Beri nama modResize

4. Buka Fom1, masukkan kode ini dibagian kode paling atas

'**************************************
' Name: Auto Resizer
' Description:I was sick and tired of seeing all the control resizers in planetsource, so i just made this myself and wanted to post it, cause someone might actually find it useful. All it does is when the form is resized, it changes all the controls (command buttons, lines, text boxes etc) to make the controls still look like they're in the right place. ie: If i had a command button that wa the size of the form, normally when i change the forms size, the command button is either too big for the form, or too little. With this, the command button is automatically resized so its still in the same proportion with the form.
' By: MidTerror (from psc cd)
'
' Inputs:A form
'**************************************

Option Explicit
Private Sub Form_Resize()
 ResizeAll Form1
'Calls for the ResizeAll function to run
'Change Form1 to the form name
End Sub


5. Jalankan aplikasi, lalu coba sobat merubah(resize) ukuran form. Kontrol di form sobat akan berubah ukurannya mengikuti besarnya form.

Form diresize dengan berbagai macam pose



Sumber: Planet Source Code

Mengganti warna dasar Command Button di Visual Basic 6

Selamat beraktifitas para pecinta visual basic.

Kali ini aku bagi tips sederhana mengganti warna background di command button

1. Pertama-tama buat form dan tombol/button didalamnya.
2. Klik tombol/button. Lihat di jendela propertis kanan bawah, scroll ke bawah, nanti sobat akan melihat setting "Style". Klik dropdown, ubah valuenya menjadi "Graphic".

3. Setelah itu scroll keatas lagi, Klik Setting backcolor. Sobat bisa memilih warna-warna sistem windows, atau bisa juga memilih warna-warna lain. Pada contoh kali ini aku akan membuat tombol yang berwarna hijau. Jadi klik dropdown Backcolor, kemudian pilih "Pallete". Pilih warna yang sobat suka. aku sih pilih hijau muda.

4. Lihat hasilnya, background text box akan berubah seperti ini.

Selamat Mencoba

Membatasi Textbox Hanya Bisa Diisi Angka

Selamat apa saja para pecinta vb classic.

Adakalanya kita ingin membatasi isian  di textbox. Cara membatasi isian di textbox sangat mudah sekali.

Sebagai contoh:
1. Buatlah form baru di Visual Basic 6
2. Buat 1 textbox ke dalamnya
3. Masukkan kode ini

Private Sub text1_KeyPress(KeyAscii As Integer)
Dim Numbers As Integer
Dim Msg As String

If ((KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8) Then
 Msg = MsgBox("Hanya Bisa diisi Angka", vbCritical, "System Error")
 KeyAscii = 0
End If
End Sub

4. Run aplikasinya, lalu isi textbox dengan selain angka.

 Selamat Mencoba