How to make this OOP?

BlitzMax Forums/BlitzMax Programming/How to make this OOP?

Hello,
This section of code opens a text file and examines it, byte by byte, for preconceived values.
It works. I have no issues with how it works. There are more checks to be done on the rest of the contents of the file but they don't matter for todays question.

This is all Procedural Programming (from what i understand).
Can you give me some tips on how i should change it to be more OOP?

Files will always be of varying length/size and only the first part will be static (matching byte by byte).

I am happy with responses saying "hey it works, you don't need to change it" but since i am still learning i would like to know the different styles.

Regards
Glenn


SuperStrict

Global FinalOutput:String[100]	' 100 element string array. This is used to store the output comments
Global sFinalOutput:String		' Temporary string to write messages to the array
Global ArrayCounter:Int = 0		' Keep track of where we are up to in the array

Local FileName:String = RequestFile( "Select FTI Client file to be tested","All Files:*" )

Global FileInput:TStream = OpenStream(FileName)
Global LTName:String
Global NumberOfNULLs:Int
Global BadFile:Int = False

If(FileType(FileName)) = 1 		' Only files can be chosen, or the Cancel button is pressed
	' Open the file and read in the first line.
	Local FirstLine:String = ReadLine(FileInput)
	' Check that the first line includes one of the pre-defined values
	Local FirstLineType:String = CheckFirstLine(FirstLine)

	Select FirstLineType
		Case "ChangeLog"		' This is a Change Log message
			FinalOutput[ArrayCounter] = "This appears to be a Change Log file."
			LTName = "CP_CHNG_LOG_2"
			NumberOfNULLs = 83
		Case "Manifest"			' This is a Manifest message 
			FinalOutput[ArrayCounter] = "This appears to be a Manifest file."
			LTName = "CP_FCPS_BOOK"
			NumberOfNULLs = 84
		Case "TrackTrace"		' This is a Track and Trace message
			FinalOutput[ArrayCounter] = "This appears to be a Track and Trace file."
			LTName = "CP_SENQ"
			NumberOfNULLs = 89
		Case "FreightForward"	' This is a Freight Forward message
			FinalOutput[ArrayCounter] = "This appears to be a Freight Forward file."
			LTName = "FF_JOBS"
			NumberOfNULLs = 89
		Default
			FinalOutput[ArrayCounter] = "This doesn't appear to be a valid FTI Client message structure. Please contact ECL customer Integration Team."
			Notify ("This doesn't appear to be a valid FTI Client message structure.~nPlease contact ECL Customer Integration Team.")
			BadFile = True
	End Select
	ArrayCounter:+1

	' Close the file and REOPEN it so we can check if the FTI Header has been written correctly
	CloseStream(FileInput)
	
	If BadFile = False Then
		' Check the FTI Header portion of the file.
		FileInput:TStream = OpenStream(FileName)
		Local CheckFTIHeaderSuccess:Int = CheckFTIHeader(FirstLineType, LTName, NumberOfNULLs)
		CloseStream(FileInput)
		' 
	EndIf

	' Write the Output Log File
	Local success:Int=CreateFile(CurrentDir()+"\FTI_Output.txt")	' this will delete an existing file and create a new file
	If Not success RuntimeError "Error Creating Output File"

	Local FileOutput:TStream = WriteFile(CurrentDir()+"\FTI_Output.txt")
	
	For Local sOutput:String = EachIn FinalOutput
		WriteLine FileOutput, (sOutput)
	Next
	
	CloseFile(FileOutput)
Else	
	Notify ("The Cancel button was chosen in the File Selector")
EndIf

End

Function CheckFTIHeader:Int(MessageType:String, LTName:String, NumberOfNULLs:Int)
	Local Result:Int = True
	Local i:Int = 1
	Local bByte:Byte = ReadByte(FileInput)
	Local sByte:String = ""
	
	' Check the first byte
	If bByte <> 152 Then 
		FinalOutput[ArrayCounter] = "The FTI Client Header should have a (chr(152)) as the first byte but it doesn't - FAILURE."
		Result = False
	Else
		FinalOutput[ArrayCounter] = "The FTI Client Header should have a (chr(152)) as the first byte and it does - SUCCESS."
	EndIf
	ArrayCounter:+1
	
	' Check the second byte
	bByte:Byte = ReadByte(FileInput)
	If bByte <> 1 Then 
		FinalOutput[ArrayCounter] = "The FTI Client Header should have a chr(1) as the second byte but it doesn't - FAILURE."
		Result = False
	Else
		FinalOutput[ArrayCounter] = "The FTI Client Header should have a chr(1) as the second byte and it does - SUCCESS."
	EndIf
	ArrayCounter:+1
	
		' Check the correct LTName is in the header
		For i = 1 To Len(LTName)
			sByte:+Chr(ReadByte(FileInput))
		Next
		If sByte <> LTName Then
			FinalOutput[ArrayCounter] = "The FTI Client Header should have " + LTName + " as the 3rd to " + (Len(LTName)+3) + "th bytes but it doesn't - FAILURE."
			Result = False
		Else
			FinalOutput[ArrayCounter] = "The FTI Client Header should have " + LTName + " as the 3rd to " + (Len(LTName)+3) + "th bytes and it does - SUCCESS."
		EndIf
		ArrayCounter:+1
		' Check the number of NULLs
		Local NullResult:Int = True
		For i = 1 To NumberOfNULLs
			bByte = ReadByte(FileInput)
			If bByte <> 0 Then
				NullResult = False
			EndIf
		Next
		If NullResult = False Then
			FinalOutput[ArrayCounter] = "The FTI Client Header should have " + NumberOfNULLs + " NULLs (Chr(0)) but it doesn't - FAILURE."
			Result = False
		Else
			FinalOutput[ArrayCounter] = "The FTI Client Header should have " + NumberOfNULLs + " NULLs and it does - SUCCESS."
		EndIf
		ArrayCounter:+1
		
		' Check that there is no CRLF and that it flows directly into the Message Header
		bByte = ReadByte(FileInput)
		If bByte = Asc(Left(LTName,1)) Then 
			FinalOutput[ArrayCounter] = "The FTI Client Header should be DIRECTLY followed by first part of the " + MessageType + " Message Header - SUCCESS."
		Else
			FinalOutput[ArrayCounter] = "The FTI Client Header should be DIRECTLY followed by first part of the " + MessageType + " Message Header but it doesn't - FAILURE."
			Result = False
		EndIf
		ArrayCounter:+1

	Return Result
End Function


Function CheckFirstLine:String(Line:String)
	' check the first line for the message type
	Local Result:String

	If Line.contains("CP_CHNG_LOG_2") Then Result = "ChangeLog"
	If Line.contains("CP_FCPS_BOOK") Then Result = "Manifest"
	If Line.contains("CP_SENQ") Then Result = "TrackTrace"
	If Line.contains("FF_JOBS") Then Result = "FreightForward"
	
	Return Result
End Function