Showing posts with label VB6. Show all posts
Showing posts with label VB6. Show all posts

Saturday, January 3, 2009

Adler-32 - VB6

Adler-32 Digest in VB6

Function Adler32(sBuffer$) As Long
Dim Seed As Long
Dim S1 As Long
Dim S2 As Long
Dim N As Long
Dim CrcBase As Long
CrcBase = 65521
Seed = 1
S1 = Seed And &HFFFF
S2 = (Seed / 65536) And &HFFFF
For N = 1 To Len(sBuffer$)
S1 = (S1 + Asc(Mid$(sBuffer$, N, 1))) Mod CrcBase
S2 = (S2 + S1) Mod CrcBase
Next
Adler32 = (S2 * 65536) + S1
End Function

Friday, December 26, 2008

Levenshtein distance - Code Snippets - Wikibooks

Levenshtein distance - Code Snippets - Wikibooks

VBA (with Damerau extension)
This VBA version uses recursion and a maximum allowed distance. The analysis to identify quasi-duplicated strings or spelling mistakes can be narrowed down to a corridor in the result matrix. The Damerau extension has also been added to the Levenshtein algorithm.


Function damerau_levenshtein(s1 As String, s2 As String, Optional limit As Variant, Optional result As Variant) As Integer
'This function returns the Levenshtein distance capped by the limit parameter.
'Usage : e.g. damerau_levenshtein("Thibault","Gorisse") to get the exact distance
' or damerau_levenshtein("correctly written words","corectly writen words",4) to identify similar spellings

Dim diagonal As Integer
Dim horizontal As Integer
Dim vertical As Integer
Dim swap As Integer
Dim final As Integer

'set a maximum limit if not set
If IsMissing(limit) Then
limit = Len(s1) + Len(s2)
End If

'create the result matrix to store intermediary results
If IsMissing(result) Then
Dim i, j As Integer ' pointeur
ReDim result(Len(s1), Len(s2)) As Integer
End If

'Start of the strings analysis
If result(Len(s1), Len(s2)) <>= limit Then
final = limit
Else
If Len(s1) = 0 Or Len(s2) = 0 Then
'End of recursivity
final = Len(s1) + Len(s2)
Else

'Core of levenshtein algorithm
If Mid(s1, 1, 1) = Mid(s2, 1, 1) Then
final = damerau_levenshtein(Mid(s1, 2), Mid(s2, 2), limit, result)
Else

If Mid(s1, 1, 1) = Mid(s2, 2, 1) And Mid(s1, 2, 1) = Mid(s2, 1, 1) Then
'Damerau extension counting swapped letters
swap = damerau_levenshtein(Mid(s1, 3), Mid(s2, 3), limit - 1, result)
final = 1 + swap
Else
'The function minimum is implemented via the limit parameter.
'The diagonal search usually reaches the limit the quickest.
diagonal = damerau_levenshtein(Mid(s1, 2), Mid(s2, 2), limit - 1, result)
horizontal = damerau_levenshtein(Mid(s1, 2), s2, diagonal, result)
vertical = damerau_levenshtein(s1, Mid(s2, 2), horizontal, result)
final = 1 + vertical
End If
End If

End If
End If
Else
'retrieve intermediate result
final = result(Len(s1), Len(s2)) - 1
End If

'returns the distance capped by the limit
If final < limit Then
damerau_levenshtein = final
'store intermediate result
result(Len(s1), Len(s2)) = final + 1
Else
damerau_levenshtein = limit
End If

End Function

Monday, August 18, 2008

Using SQL Server 2005 Express from Visual Basic 6

Using SQL Server 2005 Express from Visual Basic 6
Microsoft Desktop Storage Engine (MSDE) has been replaced with a new product called SQL Server 2005 Express, which addresses several limitations of MSDE and can be used with Visual Basic 6.
Click here to download the code sample for this article.

Resources:
T-SQL Enhancements in SQL Server 2005
Using CLR Integration in SQL Server 2005
Sqlexpress's Weblog
SQL Server Developer Center
Visual Basic Developer Center

Thursday, January 3, 2008

Using ADO to Execute SQLXML 4.0 Queries | SQL Server 2005

Using ADO to Execute SQLXML 4.0 Queries (SQL Server 2005 Books Online, September 2007)
In previous versions of SQLXML, HTTP-based query execution was supported using SQLXML IIS virtual directories and the SQLXML ISAPI filter. In SQLXML 4.0, these components have been removed as similar and overlapping functionality is now provided with native XML Web services in SQL Server 2005.

As an alternative, you can execute queries and use SQLXML 4.0 with your COM-based applications, by leveraging the SQLXML extensions to ActiveX Data Objects (ADO) that were first introduced in Microsoft Data Access Components (MDAC) 2.6 and later.

This topic demonstrates using SQLXML and ADO as part of a Visual Basic Scripting Edition (VBScript) application (a script with the .vbs file extension). It provides initial setup procedures to help you recreate and test query samples in the SQLXML 4.0 documentation.


WScript.Echo "Query process may take a few seconds to complete. Please be patient."

' Note that for SQL Server Native Client to be used as the data provider,
' it needs to be installed on the client computer first. Also, SQLXML extensions
' for ADO are used and available in MDAC 2.6 or later.

'Set script variables.
inputFile = "@@FILE_NAME@@"
strServer = "@@SERVER_NAME@@"
strDatabase = "@@DATABASE_NAME@@"
dbGuid = "{5d531cb2-e6ed-11d2-b252-00c04f681b71}"

' Establish ADO connection to SQL Server 2005 and
' create an instance of the ADO Command object.
Set conn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
conn.Open "Provider=SQLXMLOLEDB.4.0;Data Provider=SQLNCLI;Server=" & strServer & _
";Database=" & strDatabase & ";Integrated Security=SSPI"
Set cmd.ActiveConnection = conn

' Create the input stream as an instance of the ADO Stream object.
Set inStream = CreateObject("ADODB.Stream")
inStream.Open
inStream.Charset = "utf-8"
inStream.LoadFromFile inputFile

' Set ADO Command instance to use input stream.
Set cmd.CommandStream = inStream

' Set the command dialect.
cmd.Dialect = dbGuid

' Set a second ADO Stream instance for use as a results stream.
Set outStream = CreateObject("ADODB.Stream")
outStream.Open

' Set dynamic properties used by the SQLXML ADO command instance.
cmd.Properties("XML Root").Value = "ROOT"
cmd.Properties("Output Encoding").Value = "UTF-8"

' Connect the results stream to the command instance and execute the command.
cmd.Properties("Output Stream").Value = outStream
cmd.Execute , , 1024

' Echo cropped/partial results to console.
WScript.Echo Left(outStream.ReadText, 1023)

inStream.Close
outStream.Close

Wednesday, January 2, 2008

Visual Basic 6 Asynchronous File IO Using the .NET Framework

Visual Basic 6 Asynchronous File IO Using the .NET Framework (MSDN)
Summary: Learn how to pass information to a background thread from an existing Visual Basic 6 application and how the results of the background work can then return from the background thread to the Visual Basic 6 application.

Extend Visual Basic 6.0 Applications with Visual Basic .NET

VB Fusion - Extend Your Visual Basic 6.0 Applications
We will show you how to extend your Visual Basic 6.0 applications using Visual Basic .NET and how to take advantage of your Visual Basic 6.0 components from Visual Basic .NET. You can take advantage of the best of both worlds!

Visual Basic 6.0 with Visual Basic 2005
Using .NET from Visual Basic 6.0
In early January of 2002, Microsoft released the Microsoft .NET 1.0 which included a massive class library with functionality that wasn’t available in Visual Basic 6.0. This article will show you how you can use this free resource when enhancing your existing Visual Basic 6.0 or ASP applications.
Use 5000 Classes from Visual Basic 6.0
In this article, you will see how anything in the .NET Framework can be utilized in Visual Basic 6.0 by creating simple wrapper classes. This can let you quickly add powerful functionality to existing Visual Basic 6.0 applications, without the need to rewrite those applications in .NET.
Best Practices to Use Visual Basic 6.0 and Visual Basic .NET Together
A Microsoft Visual Basic 6.0 application can access .NET class libraries, but to do so, it must go through an interoperability layer, known as a client callable wrapper. This wraps the desired .NET class, and exposes it so that it appears as a traditional COM object, which can be used from any environment that can consume COM objects. Learn how to create these wrappers.
Using SQL Express from Visual Basic 6.0
SQL Express provides the developer power of SQL Server. This article will show how SQL Express can be used for Visual Basic 6.0 development. Best of all, it is completely free, and can be redistributed with your application.
Automatic Updating of Visual Basic 6 Applications: Part I
This article shows how you can add automatic updating functionality to your existing Visual Basic 6.0 applications, using features now available with the .NET Framework 2.0.
Launch and Control System Processes using the “Process” Class from a Visual Basic 6 Application
This article examines the functionality provided by the .NET Framework “System.Diagnostics” classes. In specific, this article looks at the very useful “Process” class, which lets you launch and control system processes, and shows how to use this class from a Visual Basic 6 application.
Calling Web Services from Visual Basic 6
This article shows you how to build an application that downloads satellite photos of a given street address from Visual Basic 6.
Visual Basic 6 and Visual Basic 2005 Application Configuration
It's common to have applications that need to load and store configuration information. Applications may expose options to the users, track recently opened files, remember previous form sizes, or more. By writing some simple Visual Basic .NET code, you can easily add this kind of configuration capability to your existing Visual Basic 6 applications.
Using Background Threads with Visual Basic 6
Learn how to use the .NET Framework 2.0 BackgroundWorker component from Visual Basic 6 applications to perform long running operations on background threads. This article shows you how to inform the user of progress, how to allow the user to cancel the background task, and how to debug multi-threaded applications.
Adding File Compression and Encryption in Visual Basic 6.0 Using the Microsoft .NET Framework - Part 1
In this two-part article series, you’ll see how you can easily add encryption and data compression (ZIP) capabilities to existing Visual Basic 6.0 applications using the .NET Framework.
Adding File Compression and Encryption in Visual Basic 6.0 Using the Microsoft .NET Framework - Part 2
Add data compression (ZIP) capabilities to existing Visual Basic 6.0 applications using the .NET Framework.

Accessing Data from Visual Basic 6.0
Accessing Operating System Information and More with Visual Basic 6
This article explains how you can use Visual Basic 6 with the .NET Framework to access user and operating system information that normally would require Win32 API calls.
Accessing the Event Log from Visual Basic 6.0 using the Microsoft .NET Framework
Instrument your applications so that other people can look at the event logs to diagnose issues from Visual Basic 6.0 applications using .NET.
Access the File System with .NET Framework Classes from Visual Basic 6.0
Accessing the file system is a common application requirement, and in the spirit of Microsoft Visual Basic Fusion, this article shows how to access some of the best Microsoft .NET Framework file system functionality from existing Visual Basic 6.0 applications. Learn how to get the extension for a file, the directory portion or a path, or the file name portion of a path. Learn how to fire events every time the contents of a directory change.


---