Re: Passing a String as Pointer
- From: "Karl E. Peterson" <karl@xxxxxxxx>
- Date: Wed, 20 Dec 2006 10:28:15 -0800
Hi Bob --
Public Function LevDist(ByVal pStr1, ByVal pStr2) As Integer
Never use Variants when you don't have to. This is such a case. 32-bit
pointers are, uh, 32-bits. Exactly. Use Long variables to hold them. To
obtain a pointer to a String in VB, use the StrPtr() function. Ex:
Call LevDist(StrPtr(MyStr1), StrPtr(MyStr2))
When I copy the code into a Access 2003 Module and attempt to execute
it fails with a mis-match type error upon the statement 'n =
UBound(pStr1)' which seems correct as a string is being passed.
What is "correct" in this situation? I have absolutely no concept what the
UBound of a pointer may be. VB won't either. I think this algorithm needs
to be re-examined in light of what datatypes you have available to work
with.
Later... Karl
--
Working without a .NET?
http://classicvb.org/
robertjhuff@xxxxxxxxx wrote:
Hi,'***************************************************************************
Below is a snippet of code that works compiled in a MDE application:
============= SNIP BEGIN =====================
Public Function LevDist(ByVal pStr1, ByVal pStr2) As Integer
'******************** Levenshtein Distance
**************************************************
'* Levenshtein Distance algorithm is named after the Russian scientist
'* Vladimir Levenshtein, who devised the algorithm in 1965
'*
'* Levenshtein edit distance is the number of insertions, deletions,
or '* replacements of single characters that are required to convert
one '* string to the other.
'*
'* Character transposition is detected in Step 6A.
'* Transposition is given a cost of 1.
'*
'* Normally Levenshtein edit distance is symmetric.
'* That is, LevDist(pStr1 , pStr2) is the same as LevDist(pStr2 ,
pStr1).
'*
*****************
Dim n As Integer, m As Integer, matrix() As Integer
Dim i As Integer, j As Integer, cost As Integer, t_j, s_i
Dim above As Integer, left As Integer, diag As Integer, cell As
Integer
Dim trans As Integer
' Step 1
n = UBound(pStr1)
m = UBound(pStr2)
============= SNIP ENDS=====================
When I copy the code into a Access 2003 Module and attempt to execute
it fails with a mis-match type error upon the statement 'n =
UBound(pStr1)' which seems correct as a string is being passed.
And yet the code works in the MDE!
What am I missing?
Thanks,
Bob
.
- References:
- Passing a String as Pointer
- From: robertjhuff
- Passing a String as Pointer
- Prev by Date: Re: Passing a String as Pointer
- Next by Date: Re: Passing a String as Pointer
- Previous by thread: Re: Passing a String as Pointer
- Next by thread: Re: Passing a String as Pointer
- Index(es):
Relevant Pages
|