VB.net
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Windows.Forms Imports System.IO Imports System.Net Imports System.Web Public Partial Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As EventArgs) Try Dim MyClient As New WebClient() Dim s As Stream = MyClient.OpenRead("http://www.flashinthepan.eu/message.txt") Dim MyReader As New StreamReader(s) Dim line As String = "" While (InlineAssignHelper(line, MyReader.ReadLine())) IsNot Nothing listBoxlolcats.Items.Add(line) End While MyReader.Close() Catch x As Exception If MessageBox.Show("Retry?", "Error!", MessageBoxButtons.RetryCancel, MessageBoxIcon.[Error]) = DialogResult.Retry Then Dim MyClient As New WebClient() Dim s As Stream = MyClient.OpenRead("http://www.flashinthepan.eu/message.txt") Dim MyReader As New StreamReader(s) Dim line As String = "" While (InlineAssignHelper(line, MyReader.ReadLine())) IsNot Nothing listBoxlolcats.Items.Add(line) End While MyReader.Close() Else Exit Sub End If End Try End Sub Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T target = value Return value End Function End Class
C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Net; using System.Web; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnLoad_Click(object sender, EventArgs e) { try { WebClient MyClient = new WebClient(); Stream s = MyClient.OpenRead("http://www.flashinthepan.eu/message.txt"); StreamReader MyReader = new StreamReader(s); string line = ""; while ((line = MyReader.ReadLine()) != null) { listBoxlolcats.Items.Add(line); } MyReader.Close(); } catch (Exception x) { if (MessageBox.Show(x + Environment.NewLine + Environment.NewLine + "Retry?", "Error!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { WebClient MyClient = new WebClient(); Stream s = MyClient.OpenRead("http://www.flashinthepan.eu/message.txt"); StreamReader MyReader = new StreamReader(s); string line = ""; while ((line = MyReader.ReadLine()) != null) { listBoxlolcats.Items.Add(line); } MyReader.Close(); } else { return; } } } } }
Edited by ixGAMEOVERxixx, 04 September 2009 - 03:06 PM.