len() function returning byte length instead of string length

D

Demosthenes

I think what is happening here is that the string length is being reported
as the size of memory needed to store the string.

'code in my thread
Dim inData As String = "hello world"
Dim dlg As New ShowReceiveDataDelegate(AddressOf populate_grid) 'instantiate
delegate
Dim args() As Object = {inData} 'put the received string into an object for
the delegate
Me.Invoke(dlg, args) 'execute the delegate on the parent of this thread
(Form1)

Private Delegate Sub ShowReceiveDataDelegate(ByVal Data As String)

Private Sub populate_grid(ByVal net_data As String)
Dim thing As Int32 = len(net_data) 'this gives me a number like 32558



I have tried several things like copying the string to local variables and
such but the string always reports a crazy length. Also after operating on
the string and making it blank, even when the string = "" in the debugger,
my if statement does not see it as "".

If net_data = "" Then net_data never ever passes this test even when it
is ""
rows_flag = False
flag = "stop"
End If
 
Z

zacks

I think what is happening here is that the string length is being reported
as the size of memory needed to store the string.

'code in my thread
Dim inData As String = "hello world"
Dim dlg As New ShowReceiveDataDelegate(AddressOf populate_grid) 'instantiate
delegate
Dim args() As Object = {inData} 'put the received string into an object for
the delegate
Me.Invoke(dlg, args) 'execute the delegate on the parent of this thread
(Form1)

Private Delegate Sub ShowReceiveDataDelegate(ByVal Data As String)

Private Sub populate_grid(ByVal net_data As String)
  Dim thing As Int32 = len(net_data) 'this gives me a number like 32558

I have tried several things like copying the string to local variables and
such but the string always reports a crazy length.  Also after operatingon
the string and making it blank, even when the string = "" in the debugger,
my if statement does not see it as "".

  If net_data = "" Then  net_data never ever passes this test even when it
is ""
    rows_flag = False
    flag = "stop"
  End If

How come you are not using the net_data.Length property?
 
A

Armin Zingler

Demosthenes said:
Private Sub populate_grid(ByVal net_data As String)
Dim thing As Int32 = len(net_data) 'this gives me a number like
32558

Copied your code. I get 11 as expected.


Armin
 
P

Patrice

Unable to repro here. I called the code using a BackgroundWorker
component... You may want to try to create the smallest possible program
that shows what goes wrong and :
- either you'll find some error or suppress something that finally make your
code works during this process
- or you'll end finally with no more than 20 lines of code that demonstrates
the problem allowing others to give this a closer look

(and BTW avoid to create a new thread).
 
P

Patrice

Also just in case, mention in your sample code if you are using VB2003, 2005
or 2008...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top