10 Tips & Trik Visual Basic
1.Denied deletion file, this trick are open the file for simultan so the windows couldn’t delete the file until the aplication end or stoppedPrivate sub form_load()
timer1.interval = 1
end sub
Private sub timer1_timer()
Open PathFilenya For Input As 1
end sub
2.Random Coloured label, this trick will change your label each sec
Private Sub Timer1_Timer()
randomize()
Label1.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End Sub
3.Set the Attributes file without API function
Private Sub Command1_Click()
Setattr pathname,vbhidden+vbsystem+vbreadonly
End Sub
‘To make it normal
Private Sub Command1_Click()
Setattr pathname,vbnormal
End Sub
4. Animated form when unload
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
‘The form go upDo Until Me.Top <= -5000
DoEvents
Me.Move Me.Left, Me.Top - 10
DoEvents
Loop
UnloadMe
End Sub
5.Gradiation Back Color Form
Private Sub Form_Load()
Form1.AutoRedraw = True
For x = 0 To ScaleHeight
Line (1, x)-(ScaleWidth, x), RGB(5, 10, 255 - (x * 255) \ ScaleHeight)
Next x
End Sub
6. Select all content in textbox the easiest way and always used by POS or accounting application just insert these code to event proc
SendKeys “{home}+{end}”
7. UnClosed Form
Private Sub Form_Unload (Cancel as Integer)
Cancel = 1
End Sub
8. ASCII Detector
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Me.Caption = KeyCode
End Sub
9. Check the existence of Folder or Files
‘Check the FolderIf
Dir$(Text1.Text, vbDirectory) = “” Then
msgbox “Folder Not Exist”, vbinformation
ElseIf Dir$(Text1.Text, vbDirectory) <> “” Then
msgbox “Folder Exist”, vbinformation
End If
‘Check The File
If Dir(Text1.Text) = “” Then
msgbox “File Not Exist”, vbinformation
ElseIf Dir(Text1.Text) <> “” Then
msgbox “File Exist”, vbinformation
End If
10. Dragging the Form from around of your form
Private move_x As Integer
Private move_y As Integer
Private move_form As Boolean
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)move_x = X
move_y = Y
move_form = True
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If move_form Then
Me.Move Me.Left + X - move_x, Me.Top + Y - move_y
DoEvents
End If
End Sub
Private Sub form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)move_form = False
End Sub
okey thanks for your attention, critics and suggestion are welcome speciall thx to all poster at vb-bego.netmoderator and admin…
0 komentar: