mookie
04-06-2004, 12:22 PM
is there a way for me to format code easily
i.e. indenting all code inbetween if and endif?
i am writing an editor for working with code and i would like to be able to have it do that easily.
I have it so it does it now but large files take forever to process.
wakjah
04-06-2004, 12:44 PM
if you're reading the file and processing the code with, i presume, the instr() function, then it will take aged and i don't think theres a lot of other ways to do it. if its taking ages and taking up loads of system resources then you can use the doevents statement to allow other programs to do things and you can also add a progressbar to tell the user that the program is doing something
the only other way i can think of is to use a piece of modified spellchecker code (theyre all over the place) - find the fastest one - to searchthe text for certain things and then process the text
hope this helps
Why don't you post the method (pseudocode or general algorithm may be sufficient) that you're currently using, and perhaps we can give you some advice on optimization techniques.
mookie
04-06-2004, 04:00 PM
Private Function processtext(temp As String)
For i = 0 To 30
vprint = True
If vkeywords(i) = Trim(list(0)) Then
If Trim(list(0)) = "$TOOL=$NULLFRAME" Then
' debug.print "here"
End If
Select Case vkeywords(i)
Case "ELSE"
'indent = False
indentno = indentno - 4
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & vbCrLf
indentno = indentno + 4
vprint = False
Exit For
Case "CASE"
'indent = False
indentno = 0
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & vbCrLf
indentno = indentno + 4
vprint = False
Exit For
Case "ENDIF"
numindents = numindents - 2
If numindents >= 1 Then
indentno = indentno - 4 'changed on feb 13 to try to keep up with end ifs
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & ";ENDIF STATMENT # " & numindents & vbCrLf
vprint = False
indentno = indentno + 4
Else
indentstart = False
End If
Exit For
Case "ENDSWITCH"
numindents = numindents - 2
If numindents >= 1 Then
indentno = indentno - 4 'changed on feb 13 to try to keep up with end ifs
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & vbCrLf
vprint = False
indentno = indentno + 4
Else
indentstart = False
End If
Exit For
Case "END"
indent = False
indentno = indentno - 4
If printline = "END" Then
frmDocument.rtftext.Text = frmDocument.rtftext.Text & printline
vprint = False
Else
End If
Exit For
Case "SWITCH"
numindents = numindents + 1
If indentstart = True Then
indentno = indentno - 3
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & vbCrLf
vprint = False
indentno = indentno + 2
Exit For
End If
indent = True
indentno = indentno + 2
vprint = False
frmDocument.rtftext.Text = frmDocument.rtftext.Text & printline & vbCrLf
Exit For
Case "IF"
numindents = numindents + 1
If indentstart = True Then
indentno = 4
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & vbCrLf
vprint = False
indentno = indentno + 4
Exit For
End If
indent = True
indentno = 4
vprint = False
frmDocument.rtftext.Text = frmDocument.rtftext.Text & printline & vbCrLf
Exit For
'Case Else
' indent = True
' indentno = indentno + 4
' Exit For
End Select
End If
Next i
If ((indentstart = True) And (vprint = True)) Then
'frmDocument.rtfText.appendtext (printline)
frmDocument.rtftext.Text = frmDocument.rtftext.Text & String(indentno, " ") & printline & vbCrLf
indent = False
Else
If indent = True Then
indentstart = True
End If
If vprint = True Then
frmDocument.rtftext.Text = frmDocument.rtftext.Text & printline & vbCrLf
End If
If vprint = False Then vprint = True
End If
End Function
i have enclosed the zip file as well
the menuworks folder will contain the vb code.
you will have to open a file under the archive
krc/r1/program
a .src file should load..
be warned that the s5965 file is so large i cant ever get it to load. that is why i want to condese the code
wakjah
04-06-2004, 05:12 PM
one thing you can do to make it faster is change where it says frmDocument.rtftext.Text = frmDocument.rtftext.Text into frmDocument.rtftext.selText = blahblah