Announcement

Collapse
No announcement yet.

PureBasic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    การใช้งาน PureForm Visual Designer
    (ต่อจากที่ค้างไว้) พอดีไปได้โปรแกรม Visual Designer มาโปรแกรมนึง เห็นว่าใช้ดีกว่าตัวที่ติดมากับ PureBasic เลยนำมาแจกให้ลองใช้กัน
    FileSize: 863 KB
    Download: http://upload.one2car.com/download.a...9XXYB9JY7PM5OW

    Comment


    • #17
      คำสั่ง: Control Loop
      ผมจะใช้ ProgressBar เป็นตัวอย่าง ใช้คำสั่ง Repeat Until , For Next และ While Wend
      คำสั่ง1: For Next ..ใช้โปรแกรม PureForm สร้างและเขียนคำสั่งเพิ่มเติมลงไป
      วิธีทดสอบโค๊ดคำสั่ง ท่านสามารถทำได้ ง่ายนิดเดียว เพียงแต่ท่านก๊อบปี้โค๊ดคำสั่งทั้งหมด
      นำไป paste หรือวางลงไปในโปรแกรม PureBasic editor ก็สามารถทดสอบได้ทันที หรือ
      วางลงใน Notepad แล้ว Save As เป็นไฟล์สกุล .pb ก็ใช้ได้เช่นกัน
      Code:
      ;{- Enumerations / DataSections
      ;{ Windows
      Enumeration
        #Window_0
      EndEnumeration
      ;}
      ;{ Gadgets
      Enumeration
        #ProgressBar_0
        #Text_1
        #Text_2
        #Button_3
      EndEnumeration
      ;}
      Define.l Event, EventWindow, EventGadget, EventType, EventMenu
      ;}
      Procedure OpenWindow_Window_0()
        If OpenWindow(#Window_0, 171, 135, 395, 117, "For Next Statement", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
          ProgressBarGadget(#ProgressBar_0, 55, 30, 300, 20, 0, 100, #PB_ProgressBar_Smooth)
          TextGadget(#Text_1, 15, 35, 35, 15, "Status:")
          TextGadget(#Text_2, 360, 35, 30, 15, "0%", #PB_Text_Center)
          ButtonGadget(#Button_3, 175, 70, 65, 30, "Start")
        EndIf
      EndProcedure
      
      OpenWindow_Window_0()
      
      ;{- Event loop
      Repeat
        Event = WaitWindowEvent()
        Select Event
          ; ///////////////////
          Case #PB_Event_Gadget
            EventGadget = EventGadget()
            EventType = EventType()
            If EventGadget = #ProgressBar_0
            ElseIf EventGadget = #Text_1
            ElseIf EventGadget = #Text_2
            ElseIf EventGadget = #Button_3
            DisableGadget(#Button_3, 1)
      
            For x = 0 To 100 Step 1
            SetGadgetState(#ProgressBar_0, x)
            SetGadgetText(#Text_2, Str(x) + "%")
            Delay(100)
            Next
            For x = 100 To 0 Step -1
            SetGadgetState(#ProgressBar_0, x)
            SetGadgetText(#Text_2, Str(x) + "%")
            Delay(100)
            Next
            DisableGadget(#Button_3, 0)
            EndIf
          ; ////////////////////////
          Case #PB_Event_CloseWindow
            EventWindow = EventWindow()
            If EventWindow = #Window_0
              CloseWindow(#Window_0)
              Break
            EndIf
        EndSelect
      ForEver
      ;
      ;}
      Last edited by sak2005; 14 Dec 2009, 00:45:38.

      Comment


      • #18
        คำสั่ง2: Repeat Until ..คำสั่งนี้ ถ้าเปรียบเทียบกับภาษาือื่น เหมือนจะคล้ายๆกับคำสั่ง Do Until

        Code:
        ;{- Enumerations / DataSections
        ;{ Windows
        Enumeration
          #Window_0
        EndEnumeration
        ;}
        ;{ Gadgets
        Enumeration
          #ProgressBar_0
          #Text_1
          #Text_2
          #Button_3
        EndEnumeration
        ;}
        Define.l Event, EventWindow, EventGadget, EventType, EventMenu
        ;}
        Procedure OpenWindow_Window_0()
          If OpenWindow(#Window_0, 171, 135, 395, 117, "Repeat Until Statement", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
        
            ProgressBarGadget(#ProgressBar_0, 55, 30, 300, 20, 0, 100, #PB_ProgressBar_Smooth)
            TextGadget(#Text_1, 15, 35, 35, 15, "Status:")
            TextGadget(#Text_2, 360, 35, 30, 15, "0%", #PB_Text_Center)
            ButtonGadget(#Button_3, 175, 70, 65, 30, "Start")
          EndIf
        EndProcedure
        
        OpenWindow_Window_0()
        
        ;{- Event loop
        Repeat
          Event = WaitWindowEvent()
          Select Event
            ; ///////////////////
            Case #PB_Event_Gadget
              EventGadget = EventGadget()
              EventType = EventType()
              If EventGadget = #ProgressBar_0
              ElseIf EventGadget = #Text_1
              ElseIf EventGadget = #Text_2
              ElseIf EventGadget = #Button_3
              DisableGadget(#Button_3, 1)
              x = 0
              Repeat 
              SetGadgetState(#ProgressBar_0, x)
              SetGadgetText(#Text_2, Str(x) + "%")
              x = x + 1
              Delay(100)
              Until x > 100
              If x > 100
              MessageRequester("", "Completed.", 64)
              SetGadgetState(#ProgressBar_0, 0)
              SetGadgetText(#Text_2, "0%")
              DisableGadget(#Button_3, 0)
              EndIf
              EndIf
            ; ////////////////////////
            Case #PB_Event_CloseWindow
              EventWindow = EventWindow()
              If EventWindow = #Window_0
                CloseWindow(#Window_0)
                Break
              EndIf
          EndSelect
        ForEver
        ;
        ;}

        Comment


        • #19
          คำสั่ง3: While Wend
          จริงๆแล้วคำสั่ง Loop Control ยังมีมากกว่านี้ ถ้ามีโอกาส จะนำมาลงเป็นตัวอย่างให้

          Code:
          ;{- Enumerations / DataSections
          ;{ Windows
          Enumeration
            #Window_0
          EndEnumeration
          ;}
          ;{ Gadgets
          Enumeration
            #ProgressBar_0
            #Text_1
            #Text_2
            #Button_3
          EndEnumeration
          ;}
          Define.l Event, EventWindow, EventGadget, EventType, EventMenu
          ;}
          Procedure OpenWindow_Window_0()
            If OpenWindow(#Window_0, 171, 135, 395, 117, "While Wend Statement", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
          
              ProgressBarGadget(#ProgressBar_0, 55, 30, 300, 20, 0, 100, #PB_ProgressBar_Smooth)
              TextGadget(#Text_1, 15, 35, 35, 15, "Status:")
              TextGadget(#Text_2, 360, 35, 30, 15, "0%", #PB_Text_Center)
              ButtonGadget(#Button_3, 175, 70, 65, 30, "Start")
            EndIf
          EndProcedure
          
          OpenWindow_Window_0()
          
          ;{- Event loop
          Repeat
            Event = WaitWindowEvent()
            Select Event
              ; ///////////////////
              Case #PB_Event_Gadget
                EventGadget = EventGadget()
                EventType = EventType()
                If EventGadget = #ProgressBar_0
                ElseIf EventGadget = #Text_1
                ElseIf EventGadget = #Text_2
                ElseIf EventGadget = #Button_3
                DisableGadget(#Button_3, 1)
                x = 0
                While x <= 100 
                If x <= 100
                SetGadgetState(#ProgressBar_0, x)
                SetGadgetText(#Text_2, Str(x) + "%")
                x = x + 1
                Delay(100)
                EndIf
                Wend
                If x >= 100
                MessageRequester("", "Completed.", 64)
                SetGadgetState(#ProgressBar_0, 0)
                SetGadgetText(#Text_2, "0%")
                DisableGadget(#Button_3, 0)
                EndIf
                EndIf
                ; ////////////////////////
              Case #PB_Event_CloseWindow
                EventWindow = EventWindow()
                If EventWindow = #Window_0
                  CloseWindow(#Window_0)
                  Break
                EndIf
            EndSelect
          ForEver
          ;
          ;}

          Comment


          • #20
            สุดยอดเลยครับ ความรู้จริงๆ ขอบคุณมากมายครับ

            Comment


            • #21
              รอดูเนื้อหาต่อไปครับ

              Comment


              • #22
                Windows Timer
                เรียนรู้เกี่ยวกับControl Loopกันไปแล้ว คราวนี้เรามาเรียนรู้ Control Timer กันบ้าง
                คำสั่งTimerนี้ต้องใช้งานร่วมกับ Form Object คือหมายถึงต้องมีการสร้าง Form Desigh ขึ้นมา
                จึงจะสามารถใช้คำสั่ง Timer ได้ ดังตัวอย่างโค๊ดคำสั่งด้านล่าง
                รูปแบบ:
                AddWindowTimer(#Window, Timer, Timeout)
                ------------------------------------------------------------------
                Example:Control progressbar ด้วยคำสั่ง Windows Timer

                Code:
                If OpenWindow(0, 0, 0, 400, 100, "Timer Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
                    ProgressBarGadget(0, 10, 10, 380, 20, 0, 100)
                    AddWindowTimer(0, 123, 250)
                    
                    Value = 0
                    Repeat
                      Event = WaitWindowEvent()
                      
                      If Event = #PB_Event_Timer And EventTimer() = 123
                        Value = (Value + 5) % 100
                        SetGadgetState(0, Value)
                      EndIf    
                      
                    Until Event = #PB_Event_CloseWindow
                  EndIf
                -------------------------------------------
                Last edited by sak2005; 12 Jan 2010, 22:57:55.

                Comment


                • #23
                  คำสั่งDate - Time ใช้ Window Timer
                  คำสั่งนี้มีให้เลือกใช้หลายรูปแบบ ไม่ว่าจะเป็นการสร้าง วันและเวลาในที่เดียวกัน หรือสร้างวันและเวลาแยกอิสระออกจากกัน ขึ้นอยู่กับการออกแบบ ว่าต้องการให้ไปในแนวไหน? เรามาดูตัวอย่างกันเลยครับ
                  ---------------------------------------------------------------------
                  รูปแบบ: Date$ = FormatDate("%yyyy/%mm/%dd", Date())
                  รูปแบบ: Time$ = FormatDate("%hh:%ii:%ss", Date())
                  -------------------------------------------------------------------------------
                  Exsample สร้าง Form Object ตามรูปเลยครับ แล้วเขียนคำสั่งเพิ่มเติมลงไปดังนี้



                  Code:
                  Enumeration
                    #Window_0
                  EndEnumeration
                  
                  Enumeration
                    #Button_0
                    #Button_1
                  EndEnumeration
                  
                  Enumeration
                    #Font_Button_0
                    #Font_Button_1
                  EndEnumeration
                  
                  Define.l Event, EventWindow, EventGadget, EventType, EventMenu
                  
                  Procedure OpenWindow_Window_0()
                    If OpenWindow(#Window_0, 533, 261, 325, 178, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
                      ButtonGadget(#Button_0, 5, 5, 315, 65, "Gadget_0")
                      ButtonGadget(#Button_1, 5, 75, 315, 100, "Gadget_1")
                      SetGadgetFont(#Button_0, LoadFont(#Font_Button_0, "Microsoft Sans Serif", 24, 16))
                      SetGadgetFont(#Button_1, LoadFont(#Font_Button_1, "Microsoft Sans Serif", 36, 16))
                      AddWindowTimer(0, 1000, 200)
                  
                    EndIf
                  EndProcedure
                  
                  OpenWindow_Window_0()
                  
                  Repeat
                      
                      Event = WaitWindowEvent()
                    
                    If Event = #PB_Event_Timer And EventTimer() = 1000
                       
                       Date$ = FormatDate("%yyyy/%mm/%dd", Date())
                        
                        SetGadgetText(#Button_0, Date$)
                       
                       Time$ = FormatDate("%hh:%ii:%ss", Date())
                        
                        SetGadgetText(#Button_1, Time$)
                    
                    EndIf    
                  
                  Until Event = #PB_Event_CloseWindow
                  Last edited by sak2005; 13 Jan 2010, 23:50:27.

                  Comment


                  • #24
                    อันนี้เป็นการสร้าง วันและเวลา รวมกันไปเลย แถมมี Cylender หรือ ปฏิทินด้วย

                    Code:
                    Enumeration
                      #Window_0
                    EndEnumeration
                    
                    Enumeration
                      #Button_0
                      #Date_2
                    EndEnumeration
                    
                    Enumeration
                      #Font_Button_0
                    EndEnumeration
                    
                    Define.l Event, EventWindow, EventGadget, EventType, EventMenu
                    
                    Procedure OpenWindow_Window_0()
                      If OpenWindow(#Window_0, 533, 261, 381, 111, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
                        ButtonGadget(#Button_0, 5, 5, 370, 65, "Gadget_0")
                        DateGadget(#Date_2, 140, 80, 90, 20, "%dd/%mm/%yyyy", Date())
                        SetGadgetFont(#Button_0, LoadFont(#Font_Button_0, "Microsoft Sans Serif", 24, 16))
                        AddWindowTimer(0, 1000, 200)
                      EndIf
                    EndProcedure
                    
                    OpenWindow_Window_0()
                    
                    Repeat
                        
                        Event = WaitWindowEvent()
                      
                      If Event = #PB_Event_Timer And EventTimer() = 1000
                         
                         Text$ = FormatDate("%yyyy/%mm/%dd <> %hh:%ii:%ss", Date())
                          
                          SetGadgetText(#Button_0, Text$)
                         
                         EndIf    
                    
                    Until Event = #PB_Event_CloseWindow
                    Last edited by sak2005; 14 Jan 2010, 00:25:34.

                    Comment

                    Working...
                    X