Enumeration helper (simple)

Share your advanced PureBasic knowledge/code with the community.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Enumeration helper (simple)

Post by Joakim Christiansen »

I often start to write my window code like this:
CheckBoxGadget(#Main_Option_Startup,20,105,105,15,"Start with windows")
CheckBoxGadget(#Main_Option_Invisible,20,125,105,15,"Start invisible")
CheckBoxGadget(#Main_Option_Cloak,20,145,110,15,"Cloak process")
CheckBoxGadget(#Main_Option_BypassFirewall,20,165,135,15,"Bypass any firewall")
CheckBoxGadget(#Main_Option_Encrypt,20,185,125,15,"Encrypt network data")
CheckBoxGadget(#Main_Option_SaveLogs,20,205,125,15,"Automatically save logs")
And then afterwards I have to go through the code and cut out all the constants and enumerate them which is a boring job to do.

So I made this little code to cut them out and enumerate them for me; just copy the code you want constants from and run this (with debugger) then paste the result:

Code: Select all

Text.s = GetClipboardText()
ReplaceString(Text,#CRLF$,#LF$)

Debug "Enumeration"
For i=1 To CountString(Text,#LF$)+1
  Line.s   = StringField(Text,i,#LF$)
  StartPos = FindString(Line,"#",1)
  EndPos   = FindString(Line,",",StartPos)
  If StartPos And EndPos
    Debug "  "+Mid(Line,StartPos,EndPos-StartPos)
  EndIf
Next
Debug "EndEnumeration"
Sure it can be adjusted to also remove duplicates; but you can have fun adding that yourself.
I like logic, hence I dislike humans but love computers.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

thank you! :D
i allowed myself to modify it, so that you have the output in the clipboard too and you don't need necessarily the debugger (as in an exe)

Code: Select all

Text.s = GetClipboardText()
ReplaceString(Text,#CRLF$,#LF$)

NewList out.s()
AddElement(out()):out()="Enumeration"

For i=1 To CountString(Text,#LF$)+1
  Line.s   = StringField(Text,i,#LF$)
  StartPos = FindString(Line,"#",1)
  EndPos   = FindString(Line,",",StartPos)
  If StartPos And EndPos
    AddElement(out()):out()="  "+Mid(Line,StartPos,EndPos-StartPos)
  EndIf
Next
AddElement(out()):out()="EndEnumeration"
Text=""
ForEach out()
  Debug out()
  Text.s + out()+#CRLF$
Next
SetClipboardText(Text)
Post Reply