2013-09-22 31 views
0

我按照一個教程,並提出了我的世界服務器聲波發射器,但我想在不同線路上的所有信息,如:我不能下去一行VB

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

Return關鍵字將執行返回給調用者。所以它第一次得到它將返回它旁邊的東西,沒有別的。在你的情況下,你將只獲得The server is online

你需要的是一個concatanated字符串。有很多方法可以做到這一點,其中之一如下。

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

請注意,您不必將它們放在不同的行中,但更適合閱讀代碼。