ixGAMEOVERxixx Posted August 26, 2009 Report Posted August 26, 2009 (edited) Working code. 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 September 4, 2009 by ixGAMEOVERxixx 1
SotG Caboose Posted August 27, 2009 Report Posted August 27, 2009 WebClient MyClient = new WebClient(); Stream s = MyClient.OpenRead("http://www.lolcats.com"); StreamReader MyReader = new StreamReader(s); Listbox1.Items.Add(MyReader.ReadLine()); s.Close(); 1
ixGAMEOVERxixx Posted August 27, 2009 Author Report Posted August 27, 2009 SotG I converted that C# Snippet into VB.net and got this.. Dim MyClient As New WebClient() Dim s As Stream = MyClient.OpenRead("http://www.lolcats.com") Dim MyReader As New StreamReader(s) ListBox1.Items.Add(MyReader.ReadLine()) s.Close() I get the following errors - Type 'WebClient' is not defined.Type 'Stream' is not defined.Type 'StreamReader' is not defined. Any help? Thanks
SotG Caboose Posted August 27, 2009 Report Posted August 27, 2009 At the top, type: Using System.IOUsing System.Web(or Net, I forgot ) 1
iBotPeaches Posted August 27, 2009 Report Posted August 27, 2009 When you download the string from the text file use this to split it into an array with each line a new item in the array. string[] lineArray = Regex.Split(MyReader.ReadToEnd(), "\r\n"); Then like a foreach statement for that array to pull it into a listbox line by line. Or do like do until MyReader.Peek = -1. 1
ixGAMEOVERxixx Posted August 27, 2009 Author Report Posted August 27, 2009 How can I get it to do the last bit you mentioned?
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now