Amusing? Dumb? Useless? Bored?

Share your advanced PureBasic knowledge/code with the community.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Amusing? Dumb? Useless? Bored?

Post by dracflamloc »

Code: Select all

Procedure.s StrRev(string.s)
  For spos = 1 To Len(string)
    new.s=Mid(string,spos,1)+new 
  Next 
  ProcedureReturn new 
EndProcedure


OpenConsole()
prog.s=ProgramParameter()
pid=RunProgram(StringField(prog,1," "),Right(prog,Len(prog)-Len(StringField(prog,1," "))),GetCurrentDirectory(),#PB_Program_Open|#PB_Program_Read|#PB_Program_Hide)

If IsProgram(pid)
While ProgramRunning(pid)

  If AvailableProgramOutput(pid)
    s.s=ReadProgramString(pid)
    
    newstr.s=""
    wc=CountString(s," ")
    For i = 1 To wc+1
      If i = 1
        newstr.s = strrev(StringField(s,i," "))
      Else 
        newstr.s = newstr.s + " "+strrev(StringField(s,i," "))
      EndIf 
    Next 
    
    PrintN(newstr)
  EndIf 

Wend 
EndIf 

End 
Run:
reverse.exe cmd
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Another useless, amusing, etc:

Code: Select all

Enumeration
  #Window_0
  #Editor_0=0
  #Editor_1
  #Text_0
  #Text_1
  #button0
  #button
EndEnumeration
Procedure.b Open_Window_0()
  If OpenWindow(#Window_0, 259, 186, 600, 300, "Text wierd",#PB_Window_SystemMenu|#PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      EditorGadget(#Editor_0, 0, 15, 600, 130)
      EditorGadget(#Editor_1, 0, 170, 600, 130,#PB_Editor_ReadOnly)
      TextGadget(#Text_0, 0, 0, 60, 15, "Input text:")
      TextGadget(#Text_1, 0, 150, 70, 15, "Output text:")
      ButtonGadget(#button0,175,0,100,16,"paste")
      ButtonGadget(#button,175,150,100,16,"push here")
      ProcedureReturn 1
    EndIf
  EndIf
  ProcedureReturn 0
EndProcedure
If Open_Window_0()
  Dim var$(1)
  Repeat
    UIEVENT.l=WaitWindowEvent()
    Select UIEVENT
    Case #PB_Event_Gadget
      Select EventGadget()
      Case #button0
        SetGadgetText(#Editor_0,GetClipboardText())
      Case #button
        Gosub rutina
      EndSelect
    EndSelect
  Until UIEVENT=#PB_Event_CloseWindow
EndIf
End
rutina:
  var$(0)=Trim(ReplaceString(ReplaceString(GetGadgetText(#Editor_0),#LFCR$,#CR$),#CRLF$,#CR$))
  If var$(0)<>""
    ClearGadgetItemList(#Editor_1)
    var$(1)=""
    For g=1 To CountString(var$(0),#CR$)+1
      renglon$=Trim(StringField(var$(0),g,#CR$))
      If renglon$<>""
        For t=1 To CountString(renglon$," ")+1
          palabra$=Trim(StringField(renglon$,t," ")):l$="":r$=""
          While (Asc(UCase(Left(palabra$,1)))<'A' Or Asc(UCase(Left(palabra$,1)))>'Z') And Len(palabra$)>3
            l$+Left(palabra$,1):palabra$=Right(palabra$,Len(palabra$)-1)
          Wend
          While (Asc(UCase(Right(palabra$,1)))<'A' Or Asc(UCase(Right(palabra$,1)))>'Z') And Len(palabra$)>3
            r$=Right(palabra$,1)+r$:palabra$=Left(palabra$,Len(palabra$)-1)
          Wend
          If Len(palabra$)>3
            alabr$=Mid(palabra$,2,Len(palabra$)-2)
            newpalabra$=Left(palabra$,1)
            Repeat
              n=Random(Len(alabr$)-1)+1
              newpalabra$+Mid(alabr$,n,1)
              alabr$=Left(alabr$,n-1)+Right(alabr$,Len(alabr$)-n)
            Until alabr$=""
            palabra$=newpalabra$+Right(palabra$,1)
          EndIf
          var$(1)+l$+palabra$+r$+" "
        Next
      EndIf
      var$(1)=Trim(var$(1))+#CRLF$
    Next
    SetGadgetText(#Editor_1,var$(1))
  EndIf
Return
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply