Quicky on Proper code for call Class - Different then below message

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Hello

Ok I have created a class I think it is right, I am writing the code to calling up from the class to populate design form fields. Below is the code for a "Analyze File" button ( using Openfiledialog) and "Analyze Text" button. on the File button I get this the below message... not sure what it is asking for? Below is thte code for the "Analyze Text" button, I do not think it is right either????

Can someone please help me this is an assignment due for schools tonight and I am panicking...

Messge :

"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: Input string was not in a correct format.
Code For "Analyze File" button:

VB.NET:
Private Sub btnAnalF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalF.Click
 
Dim ct As New Count.Counting.AnalyzeFile
Dim ofd As New OpenFileDialog
Dim Std As StreamReader
Dim fileToSplit, conCat, fileAndPath As String
Dim sR As System.IO.StreamReader
 
ofd.Filter = "Text Files (*.txt)|*.txt|" & _
"All Files (*.*)|*.*"
ofd.FilterIndex = 1
ofd.ShowDialog()
 
Try
fileAndPath = ofd.FileName
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
 
Try
sR = File.OpenText(fileAndPath)
fileToSplit = sR.ReadToEnd()
sR.Close()
 
ct.SplitCharArray(3) = Convert.ToInt32(txtChar.Text)
Catch
ct.SplitCharArray(3) = 0
txtChar.Text = "0"
End Try
 
ct.SplitWordArray(3) = Convert.ToInt32(txtWords.Text)
ct.SplitSentArray(3) = Convert.ToInt32(txtSent.Text)
ct.SplitParArray(3) = Convert.ToInt32(txtPara.Text)
_____________________________________________________
This is the iError Message I get For "Analyze Text button:

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: Input string was not in a correct format.
Code For "Analyze Text button:

VB.NET:
Private Sub btnAnalT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalT.Click
 
Dim tp As New Count.Counting.AnalyzeText
Dim trToManipulate, conCat As String
 
Try
tp.SplitCharArray(3) = Convert.ToInt32(txtChar.Text)
Catch
tp.SplitCharArray(3) = 0
txtChar.Text = "0"
End Try
 
tp.SplitWordArray(3) = Convert.ToInt32(txtWords.Text)
tp.SplitSentArray(3) = Convert.ToInt32(txtSent.Text)
tp.SplitParArray(3) = Convert.ToInt32(txtPara.Text)
 
This is the Code in my Class - Called String Contents

VB.NET:
Imports System.IO
 
Namespace Count
 
PublicClass Counting
 
PublicEvent Analyze1(ByVal AnalyzeThis As Counting.AnalyzeFile)
 
PublicClass AnalyzeFile
 
Public SplitSentArray(3) AsString
 
Public SplitParArray(3) AsString
 
Public SplitWordArray(3) AsString
 
Public SplitCharArray(3) AsString
 
Public ofd As OpenFileDialog
 
Public fileToSplit,conCat, fileAndPath AsString
 
Public sR As System.IO.StreamReader
 
PublicFunction ReadFile(ByVal fileAndPath AsString) AsString
 
Dim strArray(3) AsString
 
Dim x AsInteger
 
Try
 
sR = File.OpenText(fileAndPath)
 
fileToSplit = sR.ReadToEnd()
 
sR.Close()
 
SplitSentArray(3) = Convert.ToInt32(fileToSplit, " ")
 
ForEach conCat In SplitCharArray
 
conCat += conCat
 
x += +1
 
Next
 
strArray(3) = CStr(fileToSplit.Length - x)
 
SplitSentArray(3) = Convert.ToInt32(fileToSplit, ".")
 
strArray(3) = CStr(SplitSentArray.Length - 1)
 
strArray(3) = CStr(x + SplitSentArray.Length - 1)
 
conCat = ""
 
Dim par AsInteger = 0
 
sR = File.OpenText(fileAndPath)
 
DoWhile sR.Peek <> -1
 
conCat = sR.ReadLine
 
If strArray(3) = "" Then
 
strArray(3) = conCat
 
EndIf
 
If conCat = "" Then
 
par += +1
 
EndIf
 
Loop
 
strArray(3) = CStr(par + 1)
 
Catch System As Exception
 
MessageBox.Show(System.Message)
 
Catch ex As Exception
 
MessageBox.Show(ex.Message)
 
Finally
 
sR = Nothing
 
GC.Collect()
 
EndTry
 
EndFunction
 
EndClass
 
PublicEvent Analyze2(ByVal AnalyzeThat As Counting.AnalyzeText)
 
PublicClass AnalyzeText
 
Public SplitSentArray(3) AsString
 
Public SplitParArray(3) AsString
 
Public SplitWordArray(3) AsString
 
Public SplitCharArray(3) AsString
 
PublicFunction ReadText(ByVal strToManipulate AsString) AsString
 
Dim strArray(3) AsString
 
Dim conCat AsString
 
Dim x AsInteger
 
Try
 
SplitCharArray = Split(strToManipulate, " ")
 
ForEach conCat In SplitCharArray
 
conCat += conCat
 
x += +1
 
Next
 
SplitCharArray(3) = CStr(strToManipulate.Length - x)
 
SplitSentArray = Split(strToManipulate, ".")
 
SplitSentArray(3) = CStr(SplitSentArray.Length - 1)
 
strArray(3) = CStr(x + SplitSentArray.Length - 1)
 
conCat = ""
 
Dim par AsInteger = 0
 
DoWhile strToManipulate <> -1
 
conCat = strToManipulate
 
If SplitParArray(3) = "" Then
 
SplitParArray(3) = conCat
 
EndIf
 
If conCat = "" Then
 
par += +1
 
EndIf
 
Loop
 
SplitParArray(3) = CStr(par + 1)
 
Catch System As Exception
 
MessageBox.Show(System.Message)
 
Catch ex As Exception
 
MessageBox.Show(ex.Message)
 
Finally
 
GC.Collect()
 
EndTry
 
EndFunction
 
EndClass
 
EndClass
 
EndNamespace
 
Back
Top