CodeItBetter Programming Another VB Programming Blog

Are you Upgrading Visual Basic 6.0 Projects to Visual Basic .NET ? Here are the Best Practices

Posted on September 14, 2009

Here are the best practices to Upgrade your Visual Basic 6 Project to Visual Basic .NET project:

Author: V Sanchez

Filed under: Presentations No Comments

How to create rounded Form

Posted on September 4, 2009

Sometimes we may need to create a form little differently like rounded form. Here is the way to set your form as rounded:

Instructions:

  • Create a new Project
  • Add a new Form to it and name it as Form1
  • Add a new command button to it and name it as Command1
  • Add a new Module to it and name it as Module1

Now, add the following code to Module1:

1
2
3
4
Option Explicit
 
Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Add the following code to Form1:

1
2
3
4
5
6
7
8
9
Option Explicit
 
Private Sub Command1_Click()
  Unload Me
End Sub
 
Private Sub Form_Load()
  SetWindowRgn hWnd, CreateEllipticRgn(0, 0, 300, 200), True
End Sub

How to check whether you are connected with internet

Posted on September 2, 2009

On your projects, you might require to know whether you are connected with Internet. So that you can decide to connect the internet or not. There are few ways to check whether you are connected to internet or now. Here is one of the way.

This piece of VB 6 code will help you to accomplish that.

Instructions:

  • Create a new Project
  • Add a new Module to it

Now, add the following code to that module:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Option Explicit
 
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40
Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
Public Const INTERNET_RAS_INSTALLED As Long = &H10
 
Sub Main()
  If AmIOnline Then
    Call MsgBox("You are connected with internet.", vbInformation, App.Title)
  Else
    Call MsgBox("You are not connected with internet.", vbInformation, App.Title)
  End If
End Sub
 
Private Function AmIOnline() As Boolean
  AmIOnline = InternetGetConnectedState(0&, 0&)
End Function

How to move a Form without Title bar

Posted on August 25, 2009

On some occasions, your client may ask you to use the form without title bar and however, he will ask you to make the form movable. As there is no title bar, we need to capture the move move, mouse up and mouse down events and move the form. So, here is the piece of code that will help you to accomplish that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Option Explicit
 
Dim OldX As Integer, OldY As Integer
Dim blnMove As Boolean
 
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  blnMove = True
  OldX = X
  OldY = Y
End Sub
 
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If blnMove = True Then
    Me.Left = Me.Left + (X - OldX)
    Me.Top = Me.Top + (Y - OldY)
  End If
End Sub
 
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Me.Left = Me.Left + (X - OldX)
  Me.Top = Me.Top + (Y - OldY)
  blnMove = False
End Sub

How to set the form to Top of all other windows

Posted on August 22, 2009

In some instance, you may need to set your form on top of all other windows. To accomplish that, you can use the following sample code: