Advertisement
Guest User

Untitled

a guest
Jan 9th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Dim Starters() As String = {"if", "while", "for", "with"}
  2. Dim Enders() As String = {"end if", "end while", "next", "end with"}
  3. Dim CapsEnders() As String = {"End If", "End While", "Next", "End With"}
  4. If Not e.Ch = ChrW(Keys.Return) Then Exit Sub
  5. Dim P As String = MainTextBox.Lines(MainTextBox.Caret.LineNumber - 1).Text
  6. P = P.Substring(0, P.Length - 2)
  7. If P.Length = 0 Then Exit Sub
  8. Dim SpaceCount As SByte = 0
  9. For i As Byte = 0 To P.Length - 1
  10. If Not P.Substring(i).StartsWith(" ") Then Exit For
  11. SpaceCount += 1
  12. Next
  13. Dim F As String = P.Substring(SpaceCount).ToLower
  14. Dim Amount As Byte = 1
  15. If SpaceCount Mod 2 = 0 Then Amount = 2
  16. Dim FID As Byte = 100
  17. For DOn As Byte = 0 To Starters.Count - 1
  18. If F.StartsWith(Starters(DOn) + " ") Then FID = DOn : Exit For
  19. Next
  20. If Not FID = 100 Then
  21. MainTextBox.InsertText(MakeSpaces(SpaceCount + Amount))
  22. Dim DoAdd As Boolean = True
  23. For i As Byte = MainTextBox.Caret.LineNumber To MainTextBox.Lines.Count - 1
  24. Dim L As String = MainTextBox.Lines(i).Text
  25. L = L.Substring(0, L.Length - 2).ToLower
  26. If L.Length = 0 Or L.Length <= SpaceCount Then Continue For
  27. L = L.Substring(SpaceCount)
  28. If L = Enders(FID).ToLower Then DoAdd = False
  29. Next
  30. If DoAdd Then
  31. Dim BackupPos As Int16 = MainTextBox.Caret.Position
  32. MainTextBox.InsertText(Environment.NewLine + MakeSpaces(SpaceCount) + CapsEnders(FID))
  33. MainTextBox.Caret.Position = BackupPos
  34. MainTextBox.Selection.Length = 0
  35. End If
  36. Exit Sub
  37. End If
  38. Dim IsOne As Boolean = False
  39. For Each D As String In Enders
  40. If F = D Then IsOne = True
  41. Next
  42. If F.StartsWith("next ") Then IsOne = True
  43. If IsOne And SpaceCount = TempSpaces Then
  44. SpaceCount -= Amount
  45. Dim FX As String = P
  46. If FX.StartsWith(MakeSpaces(Amount)) Then
  47. FX = FX.Substring(Amount)
  48. MainTextBox.Lines(MainTextBox.Caret.LineNumber - 1).Text = FX
  49. End If
  50. End If
  51. If SpaceCount < 0 Then SpaceCount = 0
  52. TempSpaces = SpaceCount
  53. MainTextBox.InsertText(MakeSpaces(SpaceCount))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement