VERSION 5.00 Begin VB.Form Form1 Caption = "MXM Scripter" ClientHeight = 7905 ClientLeft = 60 ClientTop = 450 ClientWidth = 8145 LinkTopic = "Form1" ScaleHeight = 7905 ScaleWidth = 8145 StartUpPosition = 3 'Windows Default Begin VB.TextBox Text3 BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 6375 Left = 4230 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 2 Top = 300 Width = 3585 End Begin VB.CommandButton Command1 Caption = "Fix script" BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 285 Left = 660 TabIndex = 1 Top = 6750 Width = 6945 End Begin VB.TextBox Text1 BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 6375 Left = 360 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Text = "Form1.frx":0000 Top = 300 Width = 3795 End Begin VB.Label Label1 Caption = "(C) 2003 geniusalz" BeginProperty Font Name = "Tahoma" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 315 Left = 690 TabIndex = 3 Top = 7230 Width = 6975 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim str() As String Dim outstr As String Dim labelcount As Integer Private Sub Command1_Click() labelcount = 0 outstr = "" str = Split(Text1, vbCrLf) Text3 = ffix(0, UBound(str)) 'MsgBox outstr End Sub Private Function ffix(x As Integer, z As Integer) As String If x >= UBound(str) Or x > z Then Exit Function Else For x = x To z Select Case LCase(getfirstword(str(x))) Case "if" Dim y As Integer Dim count2 As Integer y = getEndOfBlock(x) ffix = ffix & fixIF(x, y) x = y Case Else ffix = ffix & str(x) & vbCrLf End Select Next x End If End Function Private Function getfirstword(inp As String) As String Dim wor() As String wor = Split(inp, " ") If UBound(wor()) > -1 Then getfirstword = LCase(wor(0)) End Function Private Function newlabel() As String labelcount = labelcount + 1 newlabel = "label" & labelcount End Function Private Sub addLine(lin As String) outstr = outstr & lin & vbCrLf End Sub Private Function fixIF(start1 As Integer, stop1 As Integer) As String Dim lbl As String Dim endlbl As String Dim ifbody As String Dim count As Integer Dim lbls() As String Dim start2() As Integer Dim u As Integer Dim h As Integer Dim elsestart As Integer count = 1 ReDim Preserve lbls(1) As String ReDim Preserve start2(1) As Integer start2(1) = start1 lbls(1) = newlabel fixIF = fixIF & trimIf(str(start1), lbls(1)) For u = start1 + 1 To stop1 If iscommand(u) Then u = getEndOfBlock(u) If getfirstword(str(u)) = "elseif" Then count = count + 1 ReDim Preserve lbls(count) As String ReDim Preserve start2(count) As Integer lbls(count) = newlabel start2(count) = u End If If getfirstword(str(u)) = "else" Then elsestart = u End If Next u endlbl = newlabel For u = 1 To count If u <> 1 Then fixIF = fixIF & trimIf(str(start2(u)), lbls(u)) ifbody = ifbody & ":" & lbls(u) & vbCrLf If u <> count Then ifbody = ifbody & ffix(start2(u) + 1, start2(u + 1) - 1) Else If elsestart <> 0 Then ifbody = ifbody & ffix(start2(u) + 1, elsestart - 1) Else ifbody = ifbody & ffix(start2(u), stop1 - 1) End If End If If u <> count Then ifbody = ifbody & "GOTO " & endlbl & vbCrLf Next u If elsestart <> 0 Then fixIF = fixIF & ffix(elsestart + 1, stop1 - 1) End If fixIF = fixIF & "GOTO " & endlbl & vbCrLf fixIF = fixIF & ifbody fixIF = fixIF & ":" & endlbl & vbCrLf End Function Private Function trimIf(inp As String, lbl As String) As String If getfirstword(inp) = "elseif" Then trimIf = Right(Left(inp, Len(inp) - 5), Len(inp) - 5 - 4) & " GOTO " & lbl & vbCrLf Else trimIf = Left(inp, Len(inp) - 5) & " GOTO " & lbl & vbCrLf End If End Function Private Function getEndOfBlock(starting As Integer) Dim count2 As Integer Dim k As Integer Dim startCommand As String startCommand = getfirstword(str(starting)) For k = starting To UBound(str) 'MsgBox str(y) If getfirstword(str(k)) = startCommand Then count2 = count2 + 1 If getfirstword(str(k)) = getClosing(startCommand) Then count2 = count2 - 1 If count2 = 0 Then getEndOfBlock = k Exit Function End If End If Next k End Function Private Function getClosing(cmmd As String) As String Select Case cmmd Case "if" getClosing = "endif" Case "do" getClosing = "until" Case "while" getClosing = "loop" End Select End Function Function iscommand(x As Integer) As Boolean If getfirstword(str(x)) = "if" Then iscommand = True If getfirstword(str(x)) = "do" Then iscommand = True If getfirstword(str(x)) = "while" Then iscommand = True End Function