我正在使用下面的代码在加载时更改应用程序的标题。我希望能够做到这一点,而不是将它单独放在一个不同的私有子中,我希望能够将它加载到我的主私有子中,以便我可以避免必须联系Web服务器两次。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim wc As WebClient = New WebClient()
Dim Details As String()
Try
Details = wc.DownloadString("http://(IP GOES HERE):8080/launcher/Details.php").Split("#")
wc.Dispose()
Catch ex As Exception
MsgBox("Failed to connect to server. Please make sure you're connected to the internet.", MsgBoxStyle.Critical, "Server Connection Failed")
Return
End Try
Me.Text = Details(7)
End Sub
我在我的主私有子中使用相同的函数来做另一件事,所以如果我可以把它放在那里代码会更有效。
答案 0 :(得分:0)
Dim CommDetails As String()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim wc As WebClient = New WebClient()
Try
CommDetails = wc.DownloadString("http://(IP GOES HERE):8080/launcher/Details.php").Split("#")
wc.Dispose()
Catch ex As Exception
MsgBox("Failed to connect to server. Please make sure you're connected to the internet.", MsgBoxStyle.Critical, "Server Connection Failed")
Return
End Try
Me.Text = CommDetails(7)
End Sub
在你的另一个Sub:
some_text = CommDetails(7)