Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Try Catch example App - Load file and read lines
Author:
Nick Smith
Website:
http://www.applefeed.info
Submitted:
1/14/2010
Version:
VB 2008
Compatibility:
VB.NET 2002, VB.NET 2003, VB 2005, VB 2008
Category:
Miscellaneous
Views:
9426
Try Catch example App - Load file and read the number of lines, if lines is more that 100 throw an error.
Declarations:
'You will need a button, OpenfileDialogBox and two labels for this app should be simple enough though.
Code:
'Code By Nick Smith 2010, www.nicksweb.co.uk Imports System.IO 'Load Namespace for stream Reader Public Class Form1 Private testFileName As String Private liveStream() As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try OFD1.ShowDialog() testFileName = OFD1.FileName Dim tmpStream As New StreamReader(testFileName, System.Text.Encoding.Default) liveStream = tmpStream.ReadToEnd().Split(Environment.NewLine) 'Stream File in line by line 'Use this to test that message exception handleing is working countLines() ' load function to show line count on form If liveStream.Length > 100 Then 'Check to see if the Array has more than 100 eliments, if it does force an error exception to be thrown Throw New Exception("File Open Error Has Occured File size too big") End If Catch ex As Exception MsgBox("Error : " & ex.Message) Finally testFileName = "" End Try End Sub Private Sub countLines() 'Simple Function to display the ammount of lines on the main form lblNumOut.Text = liveStream.Length End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement