Help Please with Creating in a Class and Calling into main form

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Hi Everyone

I have created code with help from great programmers on this forum, for counting Charactors, words, sentances and Paragraphs and it works under the main form, populates the four fields, which are again Charactor, Word, Sentance and Paragraph. The program is counting these subjects and putting values in. On my main design for I have two buttio, "Analyze File" and "Analyze text" . The "Analyze File" opens a dialog and will read a file text and place counts in respected places. The "Analyze Text" reads text from a large multi-line test box and places counts into respected places.

However I now want to place this code into a "class" and in the main (code) form write code to call the code from the class. The purpose is to get a good understanding between programmers and developers. Example please bare with me.. Programmers will create the classes and all the code.... The developer does not have to do this and can call the new classes created, saves him doing all the big coding work. ( Please not I may have programmers and developers in wrong order on how maybe it is the devloper who does the big code ?? Still learning)

This is what I am trying to do, create all the big code put into a Class and write the code to call these new classes.

The book I have is of no use
mad.gif


Below is the code I have for the two buttons. I have placed the code into a class called StringContents.... Not sure if my code is right at all for setting it up for reading in the main form..?
And I am total stuck on how to right the code in the main form to call up the new class to populate the Design form fields???

Please Help .... Kindest Regards Marcus
VB.NET:
Imports System.IO
 
Namespace Count
 
PublicClass Counting
 
PublicClass AnalyzeFiles
 
PublicFunction ReadFile(ByVal fileAndPath AsString) AsString
 
Dim splitSentArray(3) AsString
 
Dim SplitParArray(3) AsString
 
Dim SplitWordArray(3) AsString
 
Dim SplitCharArray(3) AsString
 
Dim strArray(3) AsString
 
Dim ofd AsNew OpenFileDialog
 
Dim fileToSplit, conCat AsString
 
Dim x AsInteger
 
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)
 
EndTry
 
Dim sR As System.IO.StreamReader
 
Try
 
sR = File.OpenText(fileAndPath)
 
fileToSplit = sR.ReadToEnd()
 
sR.Close()
 
SplitCharArray = Split(fileToSplit, " ")
 
ForEach conCat In SplitCharArray
 
conCat += conCat
 
x += +1
 
Next
 
strArray(3) = CStr(fileToSplit.Length - x)
 
splitSentArray = Split(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
 
PublicClass AnalyzeTexts
 
PublicFunction ReadText(ByVal strToManipulate AsString) AsString
 
Dim splitSentArray(3) AsString
 
Dim SplitParArray(3) AsString
 
Dim SplitCharArray(3) AsString
 
Dim SplitWordArray(3) 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