I am a novice Visual Basic user. I am an engineer, but I don't have much programming experience.
I recently purchased the source code for a data recovery tool. I have decided to work through it, line by line, in order to become familiar with the tool itself and VB in general. Hopefully I will be able to maintain what would otherwise be a defunct project.
After reading the "tour" guide for this forum, I am a little concerned that my questions will not be appropriate.
https://softwareengineering.stackexchange.com/tour
"Don't ask about explaining, writing or debugging code."
Anyway, my first question relates to the following function.
Public Function GetExtension(FileName As String) As String
Dim i1 As Long
Dim II As Long
For i1 = Len(FileName) To 1 Step -1
Select Case Mid$(FileName, i1, 1)
Case "."
II = Len(Left$(FileName, i1))
GetExtension = Mid(FileName, II + 1, Len(FileName))
Exit Function
Case ":", "\"
Exit For
End Select
Next
End Function
AIUI, the above routine gets the extension from a filespec by extracting everything after the last period.
ISTM that a simpler way to achieve the same end would be by way of the InstrRev function, as follows.
Public Function GetExtension( FileName As String ) As String
Dim i1 As Long
i1 = InstrRev( FileName, "." )
If i1 <> 0 Then
GetExtension = Mid(FileName, i1 + 1, Len(FileName))
Else
GetExtension = ""
End If
End Function
Would there be any reason why InstrRev would not be appropriate? Could it be that InstrRev was not available at the time the code was written?
My second observation is that the following statement seems redundant:
II = Len(Left$(FileName, i1))
AFAICT, ...
Len(Left$(FileName, i1)) = i1 for all values of i1 >= 1
Are questions such as this one OK? If so, then you can expect a deluge.