新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'form1 窗体上添加一个button1
成都创新互联公司主要业务有网站营销策划、成都做网站、网站设计、微信公众号开发、微信小程序、H5高端网站建设、程序开发等业务。一次合作终身朋友,是我们奉行的宗旨;我们不仅仅把客户当客户,还把客户视为我们的合作伙伴,在开展业务的过程中,公司还积累了丰富的行业经验、全网整合营销推广资源和合作伙伴关系资源,并逐渐建立起规范的客户服务和保障体系。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Button1.DialogResult = Windows.Forms.DialogResult.OK
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Close()
End Sub
'以上是form1的代码
'然后就可以
dim a as new form1
dim b as dialogresult
b=a.showdialog()
Public Class Form1
Public Class SquareClass '把多线程调用的函数封装到类中,通过类事件返回
Public Value As Double
Public Square As Double
Public Event ThreadComplete(ByVal Square As Double)
Public Sub CalcSquare()
Square = Value * Value
RaiseEvent ThreadComplete(Square)
End Sub
End Class
Dim WithEvents oSquare As SquareClass
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click '多线程返回值测试,当线程运行完成激发事件
oSquare = New SquareClass()
Dim t As New Threading.Thread(AddressOf oSquare.CalcSquare)
oSquare.Value = 30
t.Start()
End Sub
Sub SquareEventHandler(ByVal Square As Double) Handles oSquare.ThreadComplete '响应事件函数
MsgBox("The square is " Square)
End Sub
End Class
1、我有一个function,如下:
function b()
'...
return "abc"
end function
2、调用时,这样子用:
Response.write(b());
3、运行结果:
abc
public function createstringarr() as string()
return new string(){"d1","d2","d3","d4"}
end function
你的 sub过程这个是子过程,无返回值的,这里Form1_Load中b仍然 b=""
如果你想b="注释",将你的sub过程改成自定义函数,用b来接收返回值就行了,代码如下
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As String = "rem"
Dim b As String = ""
b = sub过程(b, a)
Me.Text = b '为什么“b”不是等于 "注释"
End Sub
Private Function sub过程(ByVal 输出 As String, ByRef 输入 As String) As String
If 输入 = "rem" Then
输出 = "注释"
End If
Return 输出
End Function
这两个函数都是错误的,首先C变量没有定义,其次作为Function函数没有Return返回结果。
所以两个函数运行起来不会返回任何结果!
像下面这个例子:返回值就是(obj Is Nothing),在VB.Net中最好使用Return (obj Is Nothing),而不是IsNothing=(obj Is Nothing)。
Public Function IsNothing(obj As Object) As Boolean
Return (obj Is Nothing)
End Function