VB 2008中的dataArrival事件 [英] dataArrival event in vb 2008

查看:126
本文介绍了VB 2008中的dataArrival事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮忙解决vb 2008上的dataarrival事件吗,我正在尝试开发一个聊天应用程序,但每次我有类似内容时,它都会给我警告

could you help with dataarrival event on vb 2008, i am trying to develop a chat application but it gives me warning each time i have something like

dim recievedData as string
sckClient.GetData(recievedata)


请我快速完成.
还在聊天时讲口语,这给我的声明带来了错误


please i need complete this fast.
also working on a chat the speaks written messages and it gives error in my declaration

dim listener As New TCPlistener


拜托,我已经在这些上待了几个星期了.期待中的感谢


OP发表的答案:
"这是出现的警告
变量"receevedata"在被赋值之前先通过引用传递.空引用异常可能在运行时导致
.谢谢"


Please, i have been on these for weeks now. Thanks in anticipation


Posted by OP as an answer:
"this is the warning that comes up
variable ''recievedata'' is passed by reference before it has been assigned a value. A null reference exception could result at runtime
. thanks"

推荐答案

它抱怨是因为您正在做它认为很愚蠢的事情!而且,实际上是.
It complains because you are doing something it thinks is silly! And, in truth it is.
dim recievedData as string
sckClient.GetData(recievedata)

您声明一个变量"recievedData",然后将其作为参数调用一个函数.

因为您在声明和使用之间的任何时候都没有分配值,所以编译器知道输入该函数的值将为null-在声明它时会给出它的值.
由于方法"GetData"不使用ref参数,因此"recievedData"中的值只能进入函数-函数中没有发生任何事情都可以返回,因此"recievedData"在之后始终为null函数调用.

您需要做的就是修改GetData函数,使其返回一个字符串,并将其分配给recievedData:

You declare a variable "recievedData" and then call a function with it as a parameter.

Because you do not assign a value at any point between the declaration and the use, the compiler knows that the value entering the function will be null - it will give it that when you declare it.
Because the method "GetData" does not use a ref paramater, the value in "recievedData" can only go into the function - nothing that happens to it in the function can be returned, so "recievedData" will always wtill be null after the function call.

What you need to do is modify the GetData functionso that either it returns a string, which you assign to recievedData:

dim recievedData as string
recievedData = sckClient.GetData()

,或者如果要在函数中分配参数,请设置参数ByRef:

or make the parameter ByRef if you are going to assign it in the function:

Private Sub GetData(ByRef str As String)
...
str = "hello"
End Sub


这篇关于VB 2008中的dataArrival事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆