How to create simple Text Encoder/Decoder
Here is the simple vb6 function which can encode/decode any simple text:
Instructions:
- Create a new Project
- Add a new module to it and name it as Module1
Now, add the following code to Module1:
1 2 3 4 5 6 7 8 9 10 | Option Explicit Public Function GetEnCodedDecodedText(ByVal sText As String) As String Dim I As Long Dim sResult As String For I = 1 To Len(sText) sResult = sResult & Chr$(255 - Asc(Mid$(sText, I, 1))) Next I GetEnCodedDecodedText = sResult End Function |
How to call this function:
1 | Debug.print GetEnCodedDecodedText("testing") |
How to set system wide hotkey to open an application
I was looking for a simple solution to open calculator whenever I click a shortcut key. There are many ways to do that. I don't want to spend more time on this project, as I am the only person going to use it. So created a simple application using GetAsyncKeyState API. Here is the code for you to try:
Instructions:
- Create a new Project
- Add a new Form to it and name it as Form1
- Add a new timer control to it and name it as tmrTicker
Now, add the following code to Form1:
1 2 3 4 5 6 7 8 9 10 11 12 13 | Option Explicit Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Sub tmrTicker_Timer() If GetAsyncKeyState(vbKeyControl) And GetAsyncKeyState(vbKeyQ) Then Call Shell("C:\WINDOWS\system32\calc.exe", vbNormalFocus) End If End Sub Private Sub Form_Load() Me.Hide End Sub |
Create the exe file and add it to windows startup. Now, whenever you click Ctrl + Q, the calculator will be opened. In this way you can open-up any application you want.
Are you Upgrading Visual Basic 6.0 Projects to Visual Basic .NET ? Here are the Best Practices
Here are the best practices to Upgrade your Visual Basic 6 Project to Visual Basic .NET project:
Author: V Sanchez
How to create rounded Form
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
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 |