我不能顺行VB

时间:2013-09-22 16:49:15

标签: vb.net minecraft

我已经按照教程编写了一个Minecraft服务器,但是我想要不同行的所有信息,如下所示:

Server online!
The message of the day is ...
There are 0/2 players

我的代码

Imports Wrapped
Imports System.Net.Sockets

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles    Button1.Click
    Label3.Text = PingServer(TextBox1.Text, TextBox2.Text)

End Sub
Private Function PingServer(ByVal IP As String, ByVal port As Integer)
    Dim MySocket As New TcpClient(IP, port)
    Dim Socket As New Wrapped.Wrapped(MySocket.GetStream)
    Socket.writeByte(254)
    Socket.writeByte(1)
    If Socket.readByte() = 255 Then
        Dim mystring As String = Socket.readString()
        Dim mysplit() As String = mystring.Split(ChrW(CByte(0)))
        Return "The server is online"
        Return Environment.NewLine & "The message of the day is " & mysplit(3)
        Return Environment.NewLine & "There are" & mysplit(4) & "/" & mysplit(5) & "players"
    Else


        Return "Something went wrong! Please try again."



    End If
    Return ""

End Function
End Class

1 个答案:

答案 0 :(得分:1)

Return关键字将返回执行给调用者。因此,第一次返回它将返回它旁边的内容而不是其他内容。在您的情况下,您将只获得The server is online

你需要的是一个连续的字符串。有很多种方法,其中之一如下。

    Return "The server is online" & _
    Environment.NewLine & "The message of the day is " & mysplit(3) & _
    Environment.NewLine & "There are" & mysplit(4) & "/" & mysplit(5) & "players"

请注意,您不必将它们放在不同的行中,但最好是阅读代码。