Re: Passing a String as Pointer

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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



.



Relevant Pages

  • Re: Modify a .doc document with a macro without Word ?
    ... Const LL_ITEMPTR = 4 ' Pointer to the item ... Public Sub Add(Item As Variant, Optional Key As String, Optional Before As Variant, Optional After As Variant) ... Dim lpArray As Long ' Pointer to the first element of the array ... Dim lpItem As Long ' Pointer to the item ...
    (microsoft.public.scripting.vbscript)
  • Re: Pointers in vb6
    ... then mszReaders is converted to a pointer to a byte ... ByVal lpString1 As String, ByVal lpString2 As Long) As Long ... Dim hContext As Long ...
    (microsoft.public.pocketpc.developer)
  • Re: Passing a String as Pointer
    ... If pStr1 is a string then perhaps you want to know the length of the ... The trouble is pStr1 and pStr2 are typed so they could be anything! ... '* Normally Levenshtein edit distance is symmetric. ... Dim n As Integer, m As Integer, matrixAs Integer ...
    (microsoft.public.word.vba.general)
  • Re: Fallbeispiel1, VB6 - VB.NET
    ... Private Function concat2As String ... Dim i As Integer, r As Integer, c As Integer ... tb = LeftB$(Buffer, Pointer - 1) ...
    (microsoft.public.de.vb)
  • Re: How to return a sting of numbers from a longer string
    ... I needed to change the msgbox into Alert. ... how can I look for a string within a string ... Dim whatimlookingfor ... Dim pointer ...
    (microsoft.public.scripting.vbscript)