0

チュートリアルに従って、Minecraft サーバーの pinger を作成しましたが、次のように、すべての情報を異なる行に表示したいと思います。

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
4

1 に答える 1

1

Return キーワードは、呼び出し元に実行を返します。したがって、最初に Return に到達すると、その隣にあるものだけが返されます。あなたの場合、あなただけが得られますThe server is online

必要なのは、連結された文字列です。その方法はいくつかありますが、そのうちの 1 つが次のとおりです。

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

これらを別の行に配置する必要はありませんが、コードを読むのには適していることに注意してください。

于 2013-09-22T17:03:03.933 に答える