|
Get list of installed ODBC drivers using ODBC API.
|
Total Hit (7749) |
Here is a small code snippet to list all installed ODBC Drivers (name and attribute). On my machine I got the following output.
«code LangId=0»
SQL Server
UsageCount=3 : SQLLevel=1 : FileUsage=0 : DriverODBCVer=02.50 : ConnectFunctions=YYY : APILevel=2 : CPTimeout=60
--------------------------
....Read More |
Rating
|
|
|
|
Very simple Encryption/Decryption code using VB
|
Total Hit (4742) |
This code will show you how to encrypt/decrypt a string.
Copy/Paste the following code in your VB form and press F5 to run.
«code LangId=1»Const ENCRYPTION_KEY = "MySecreteKey123"
Private Sub Form_Load()
Dim txt As String, enctxt As String
txt = "Your password is : asd$223"
....Read More |
Rating
|
|
|
|
Print Dialogbox without using Common Dialogbox ActiveX control
|
Total Hit (4838) |
This code will show you use of PrintDialog API to show print dialogbox.
«b»Step-By-Step Example«/b»
- Create a standard exe project
- Add one class module
- Rename it to clsPrnDlg
- Add one command button on form1
- Place the following code in form1
«code LangId=1»Private Sub Command1_C
....Read More |
Rating
|
|
|
A generic benchmark routine
|
Total Hit (3367) |
You often need to benchmark a piece of code, which you usually do as follows:
«Code LangId=2»
Dim start As Date = Now
' insert here the code to benchmark
Dim elapsed As TimeSpan = Now.Subtract(start)
Console.WriteLine("Total time: {0} secs.", elapsed)
«/Code»
Thanks to delegates, you can w
....Read More |
Rating
|
|
|
Add exception tracing with one line of code
|
Total Hit (3823) |
At times you want to keep a log of all the exception occurred in your application, including those that are correctly caught by a Catch block. At first you might believe that you need to add a call to the LogException procedure from each and every Catch block, which is clearly a nuisance:
«Code L
....Read More |
Rating
|
|
|
Create a unique GUID
|
Total Hit (4128) |
The System.Guid type exposes several shared and instance methods that can help you work with GUIDs, that is, those 128-bit numbers that serve to uniquely identify elements and that are ubiquitous in Windows programming. The most important member is the NewGuid shared method is useful for generating
....Read More |
Rating
|
|
|
Create console apps that return an exit code
|
Total Hit (3249) |
Writing an application that returns an ERRORLEVEL to Dos is quite difficult in VB6, because you are forced to use a Windows API that ends the application immediately, thus preventing orderly release of resources. Conversely, this task is quite simple in VB.NET, thanks to the Exit static method of th
....Read More |
Rating
|
|
|
Determine the size of a structure
|
Total Hit (4598) |
Unlike previous Visual Basic versions, under VB.NET you can't use the Len function to calculate the length of a Structure or a class. However, it is easy to get this information with the SizeOf static method of the System.Runtime.InteropServices.Mashal class, as in:
....Read More |
Rating
|
|
|
Evaluate an expression using the Microsoft Script Control
|
Total Hit (3502) |
Thanks to COM Interop, you can still use the Microsoft Script Control from VB.NET and any other .NET language. To do so, you must add a reference to the Microsoft Script Control library (from the COM page in the Add Reference dialog box): this action creates a new reference named Interop.MSScriptCon
....Read More |
Rating
|
|
|
Exclude code portions with the Conditional attribute
|
Total Hit (3239) |
VB developers have always used the #IF compiler directive to include or esclude portions of code from the application. The problem with this directive is that you can easily exclude a procedure with a single directive, but it isn't easy to discard all the calls to that procedure (which would raise a
....Read More |
Rating
|
|
|
Leverage the improved Shell function
|
Total Hit (2990) |
The version of the Shell function included in VB.NET expands on the original version and supports an additional argument that enables you to specify whether to wait until the shelled program terminates, with an optional timeout. This solves an old problem known to many Visual Basic developers withou
....Read More |
Rating
|
|
|
Providing a default value for optional arguments
|
Total Hit (3272) |
Unlike VB6, VB.NET requires that you specify the default value of any Optional argument. In general you should use a value that is invalid under normal circumstances, so that the called procedure can discern whether the argument has been actually passed or not. For example, you should use -1 as a sp
....Read More |
Rating
|
|
|
Retrieving the hi/low byte/word of a value, and other operations
|
Total Hit (4240) |
As explained in the tip about the ARGBColor structure (look at the end of this tip for the link), we can define a structure and have its fields that point to the same memory address, but that read a different number of bytes. This makes easier to define a structure that allows us to set a value to a
....Read More |
Rating
|
|
|
Use a ParamArray as a true array
|
Total Hit (2695) |
Unlike VB6, in VB.NET the ParamArray keyword defines a true array object, which you can process using any of the methods of the Array class. For example, here' s a function that evaluates the lowest value among those passed to the procedure, using the static Array.Sort method and then taking the ele
....Read More |
Rating
|
|
|
Use the Err.GetException method to create custom exceptions
|
Total Hit (2922) |
The Visual Basic .NET Err.Raise method and the Throw command are (partially) compatible. For example, you can use a Try...End Try block to catch an error raised with the Err.Raise method, and you can use an On Error Resume Next and the Err object to neutralize and inspect an exception object created
....Read More |
Rating
|
|
|
Using a union to retrieve the RGB components of a color
|
Total Hit (2933) |
In VB.NET you can create what in C is called a union, i.e. a particular structure where you can access the same memory with different names. Here's how you declare such a structure by using the StructLayout attribute, and specifying that you want to define the structure layout explicitly, namely how
....Read More |
Rating
|
|
|
Simple VB Script to check Registry Key
|
Total Hit (6500) |
«code LangId=1»Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\CCleaner"
strValueName = "UpdateCheck"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strVal
....Read More |
Rating
|
|
|
|
How to test CDO email using VB Script.
|
Total Hit (3461) |
Sometimes we need to check CDO on the server with minimum amount of time.
Following script will send an email using CDO object library. If you dont have CDO then it will throw an error.
- Create an empty file in notepad.
- Copy/Paste the following script
- Save file as CDOMailTest.vbs
- Do
....Read More |
Rating
|
|
|
How to Kill Process by name in Windows XP/2003/2k
|
Total Hit (3322) |
Here is the most easiest way to kill running process in WinXP/2003
«code LangId=1»
Private Sub Command1_Click()
KillProcess "notepad.exe" '//Replace with ur process name to kill
End Sub
Function KillProcess(ProcessName As String, Optional strComputer As String = ".")
Dim objProces
....Read More |
Rating
|
|
|
|
How to add path to the PATH environment variable using VB/VBScript
|
Total Hit (5383) |
Many times we need to add application path to the existing environment PATH variable. This can be very tedious job if you have to do for several machine. I came up with some handy script which makes my life easy and hopefully you can use too.
The sample code was used in VB6 but you can use it wit
....Read More |
Rating
|
|
|
How to read data from Excel file
|
Total Hit (3621) |
Many times we have requirements to load data from CSV file, text file or Excel file...
In this article I will show a sample code which reads a specified rows and columns from excel file.
«code LangId=1»Private Sub Command1_Click()
ImportExcelToSQL "c:\temp\diamond_upload.xls", 0, 20, True
....Read More |
Rating
|
|
|
How to move/resize window using API?
|
Total Hit (5018) |
«code LangId=1»Private Const SWP_SHOWWINDOW = &H40
Private Const SW_HIDE = 0
Private Const SW_RESTORE = 9
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameter
....Read More |
Rating
|
|
|
|
How To Use ADO with Excel Data from Visual Basic or VBA
|
Total Hit (1018) |
This article discusses the use of ActiveX Data Objects (ADO) with Microsoft Excel spreadsheets as a data source. The article also highlights syntax issues and limitations specific to Excel. This article does not discuss OLAP or PivotTable technologies or other specialized uses of Excel data.
....Read More |
Rating
|
|
|
How To Transfer Data from ADO Data Source to Excel with ADO
|
Total Hit (1133) |
Because Microsoft Excel is such a powerful data analysis tool, Visual Basic and VBA application developers often want to bring data into an Excel worksheet for analysis purposes. This article describes the ActiveX Data Objects (ADO) approach to this programming task, using Microsoft Jet-specific syn
....Read More |
Rating
|
|
|
How to create folder on remote machine using WMI
|
Total Hit (1080) |
Hey, AN. Life is full of mysteries. To name one, what possessed somebody to think that the world was clamoring for Clamato juice, an unholy concoction combining tomato juice and clam juice? (As long as we’re on the subject: clam juice?) To name another, why is it that neither the FileSystemObject no
....Read More |
Rating
|
|