@Welbog said:@vr602 said:Devi obviously likes typing. Even in old VB it's simpler than that. Working from L to R, f you get a start bracket, add it to the end of a test string. If you get an end bracket, then if it matches the last byte in your test string, remove last byte from test string, otherwise it's an error. At end, ensure all have been paired off.
Function CalcBraces(sInput As String)Dim sOutput As String, lLen As Long, lPos As Long, sByte As String lLen = Len(sInput) For lPos = 1 To lLen sByte = Mid(sInput, lPos, 1)' Opening bracket, add to end of test string If sByte = "{" Or sByte = "[" Or sByte = "(" Then sOutput = sOutput & sByte Else' Closing bracket. If matches last byte, clear last byte. Else error. If (sByte = "}" And Right(sOutput, 1) <> "{") Or _ (sByte = "]" And Right(sOutput, 1) <> "[") Or _ (sByte = ")" And Right(sOutput, 1) <> "(") Then MsgBox "Error " & sByte & " at position " & CStr(lPos) Exit Function End If sOutput = Left(sOutput, Len(sOutput) - 1) End If Next' Check all paired off If sOutput <> "" Then MsgBox "Error " & sByte & " at position " & CStr(lPos) Exit Function End If MsgBox "OK"End FunctionUsing a string when you should be using a stack? WTF?!
Thanks... My thinking :)