Re: How is this conditional able to execute?
- From: "Stephany Young" <noone@localhost>
- Date: Mon, 18 Apr 2005 08:42:31 +1200
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
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: How is this conditional able to execute?
- From: Brett
- Re: How is this conditional able to execute?
- References:
- How is this conditional able to execute?
- From: Brett
- Re: How is this conditional able to execute?
- From: Stephany Young
- Re: How is this conditional able to execute?
- From: Brett
- Re: How is this conditional able to execute?
- From: Stephany Young
- Re: How is this conditional able to execute?
- From: Brett
- How is this conditional able to execute?
- Prev by Date: Replacement for IIS
- Next by Date: Re: Replacement for IIS
- Previous by thread: Re: How is this conditional able to execute?
- Next by thread: Re: How is this conditional able to execute?
- Index(es):
Relevant Pages
|