Re: How is this conditional able to execute?



What test are you using to determine that returndata.ToString = ""?

Are you , for example, executing a:

Console.Writeline("returndata.ToString = " & returndata.ToString)

and getting the result:

returndata.ToString =

Your comment about returndata 'always' being 8193 bytes gives us the clue as
what is happening.

I suspect that returndata is padded with null characters (chr(0)).

The Trim function (aka Microsoft.VisualBasic.Trim) only 'trims' leading and
trailing Space characters.

The String.Trim Method 'trims' leading and trailing whitespace characters.
'whitespace' comprises a number of characters including the null character
(chr(0)).

I think that if you change the line:

Dim returndata As String = Trim(Encoding.UTF8.GetString(bytes))

to

Dim returndata As String = Encoding.UTF8.GetString(bytes).Trim()

then the test will work correctly.



"Brett" <no@xxxxxxxx> wrote in message
news:OGXwIW1QFHA.3336@xxxxxxxxxxxxxxxxxxxxxxx
>
> "Stephany Young" <noone@localhost> wrote in message
> news:eyxRIGwQFHA.3140@xxxxxxxxxxxxxxxxxxxxxxx
>> The critical thing here is, what is ClientForm.ReturnData? Is it a
>> control on a form? What is it's Type?
>
> Declared in Form1:
> Public Shared ReturnData As String
>
> It is always assigned a string value.
>
>>
>> Are you saying that directly after execution of the line:
>>
>> Dim returndata As String = Trim(Encoding.UTF8.GetString(bytes))
>>
>> returndata contains an empty string? If so how are you testing this?
>
> When I do Len(returndata) in the IF, it has a length of 8193. Same as the
> byte array. How can returndata's value be ""?
>
>>
>> Although it should not hurt anything, returndata.ToString is redundant
>> because returndata is actually a string.
>>
>>
>> "Brett" <no@xxxxxxxx> wrote in message
>> news:epc2VnvQFHA.2736@xxxxxxxxxxxxxxxxxxxxxxx
>>>I only put the values that way to show what they are. I wasn't actually
>>>assigning anything.
>>>
>>> This code is in a loop. Most of the time, returndata is the empty
>>> string.
>>>
>>> networkStream = tcpClient.GetStream()
>>> Dim bytes(tcpClient.ReceiveBufferSize) As Byte
>>> networkStream.Read(bytes, 0,
>>> tcpClient.ReceiveBufferSize)
>>> Dim returndata As String =
>>> Trim(Encoding.UTF8.GetString(bytes))
>>>
>>> If returndata.ToString <> "" And
>>> returndata.ToString <> ClientForm.ReturnData Then
>>> ClientForm.ReturnData = returndata
>>> returndata = Nothing
>>> Else
>>> End If
>>> End If
>>>
>>> bytes always has a length of 8193. Up until about the 35th element of
>>> its array, the values are non zero. After that they are all zero.
>>> Possibly I'm not seeing something that is kept in bytes when I assign it
>>> to returndata? Although returndata appears to be the empty string, it
>>> may have some other value.
>>>
>>>
>>>
>>> "Stephany Young" <noone@localhost> wrote in message
>>> news:e6sPJevQFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
>>>> Did you forget to include the values?
>>>>
>>>> Your code cannot possiblity work because
>>>>
>>>> returndata.ToString = ""
>>>>
>>>> gives a compile-time error:
>>>>
>>>> error BC30068: Expression is a value and therefore cannot be the
>>>> target of an assignment.
>>>>
>>>> It would pay to show the ACTUAL code including the declarations of and
>>>> assignments to variables returndata and ClientForm.ReturnData.
>>>>
>>>>
>>>> "Brett" <no@xxxxxxxx> wrote in message
>>>> news:%23HIUlxuQFHA.1476@xxxxxxxxxxxxxxxxxxxxxxx
>>>>> The following conditional executes given the values listed. I've
>>>>> listed the values below for each of these variables. How is it that
>>>>> the conditional still executes:
>>>>>
>>>>> If (returndata.ToString <> "") And (returndata.ToString <>
>>>>> ClientForm.ReturnData) Then
>>>>>
>>>>> returndata.ToString = ""
>>>>> ClientForm.ReturnData = Nothing
>>>>>
>>>>> The first test fails and the second passes. The AND should then fail
>>>>> correct?
>>>>>
>>>>> Thanks,
>>>>> Brett
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: How is this conditional able to execute?
    ... inside the loop, then each time the loop iterates then a NEW reference to ... Note that the test of returndata is not a type. ... Dim returndata As String = "" ... Not that 'Changing' is only displayed when returndata is NOT an empty string ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How is this conditional able to execute?
    ... > EXACT same results when you executed the EXACT same code. ... returndata still has a large length and value of ... >>> from the beginning and the 14 Null characters from the end which leaves ... >>> It is the Null character at the beginning that is causing your string to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How is this conditional able to execute?
    ... > inside the loop, then each time the loop iterates then a NEW reference to ... > Note that the test of returndata is not a type. ... Here's some of my output starting with the first iteration: ... You can see returndata is the empty string above yet your IF is executed. ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Follow up question. Get value of closed file.
    ... MsgBox ReturnData and it said type mismatch. ... Dim ReturnData as Variant ... SourceSheet As String, _ ... Dim rsData As Object ...
    (microsoft.public.excel.programming)
  • Re: How is this conditional able to execute?
    ... EXACT same results when you executed the EXACT same code. ... 'trimming' of the Null characters does actually work as expected on your ... returndata still has a large length and value of ... >> It is the Null character at the beginning that is causing your string to ...
    (microsoft.public.dotnet.languages.vb)