|
ReadInFile
Opens a given file and looks for the string matching the case intType, and then returns the next line.
Function ReadInFile(intType As Integer) As String
Dim File As String
Dim strType As String
Dim inputdata As String
On Error GoTo Err_ReadInFile
File = "YourFilename"
Select Case intType
Case 1: strType = "[AddRemowe]"
Case 2: strType = "[OtherMS]"
End Select
Open File For Input As #1 ' open file and read first line from top
Do Until EOF(1) ' start the loop
Line Input #1, inputdata ' put the line it in to indputdata
If inputdata = strType Then ' do we got a winner?
Line Input #1, inputdata ' then go to next line
ReadInFile= inputdata ' read it to be returnd from
Close #1 ' close the file
Exit Function ' and get out of there
End If ' or you didn't got it
Loop ' don't worry, just try again
Exit_ReadInFile:
Close #1 ' Always remember to close ( i nearly forgot :)
Exit Function
Err_ReadInFile:
ReadInFile = ReadInFile & vbCrlf & Err.Description ' return error in function
Resume Exit_ReadInFile
End Function
|