VB.Net more restrictive?

G

Grahammer

Is it just me, or is VB.Net much more restrictive than VB6?

For example... I'm trying to build a control that will check a POP3 email
account for mail and allow the user to enter POP commands while connected.
Later I'll do the same for SMTP and for a Telnet session... I cannot find
any evidence of any event driven method to read data from the incoming
buffer. Instead, I need to set a timer and repeatedly check to see if there
is any data in the buffer. Am I wrong in this?

Another example. Try printing a RichTextbox control in VB6. It's quite
simple. Try doing the same in VB.Net... Next to impossible and requires
pages of code.

Another example. Try creating a user control with a transparent background.
It can't be done in VB.Net, while is was simply a matter of setting a
transparent color in VB6.

Why are these things so difficult to do?
 
F

Fredrik Fehre

See below regarding your SMTP-client....

Dim client As New System.Net.Sockets.TcpClient()
Dim InBuff() As Byte
While True
While Not client.GetStream.DataAvailable()
Application.DoEvents()
End While
If client.GetStream.DataAvailable() Then
client.GetStream().Read(InBuff, 0, InBuff.Length)
temp = System.Text.Encoding.Default.GetString(InBuff, 0,
InBuff.Length)
InBuff.Clear(InBuff, 0, InBuff.Length)
Return temp
End If
End While

/Fehre
 
J

Jon Skeet [C# MVP]

Fredrik Fehre said:
See below regarding your SMTP-client....

Dim client As New System.Net.Sockets.TcpClient()
Dim InBuff() As Byte
While True
While Not client.GetStream.DataAvailable()
Application.DoEvents()
End While
If client.GetStream.DataAvailable() Then
client.GetStream().Read(InBuff, 0, InBuff.Length)
temp = System.Text.Encoding.Default.GetString(InBuff, 0,
InBuff.Length)
InBuff.Clear(InBuff, 0, InBuff.Length)
Return temp
End If
End While

That will end up with corrupt data - you're assuming that every time
there is *some* data available, there's enough for the whole buffer.
You should *always* use the return value of Stream.Read.
 
P

Phrederick

Fredrik Fehre said:
See below regarding your SMTP-client....

Dim client As New System.Net.Sockets.TcpClient()
Dim InBuff() As Byte
While True
While Not client.GetStream.DataAvailable()
Application.DoEvents()
End While
If client.GetStream.DataAvailable() Then
client.GetStream().Read(InBuff, 0, InBuff.Length)
temp = System.Text.Encoding.Default.GetString(InBuff, 0,
InBuff.Length)
InBuff.Clear(InBuff, 0, InBuff.Length)
Return temp
End If
End While

/Fehre
 

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