ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


3 posters

    สอบถามเรื่องGuiหน่อยครับ

    avatar
    mnl19160
    มือใหม่เพิ่งสมัคร
    มือใหม่เพิ่งสมัคร


    สอบถามเรื่องGuiหน่อยครับ Empty สอบถามเรื่องGuiหน่อยครับ Empty
    จำนวนข้อความ : 3
    ความนิยม : 0
    เข้าร่วมเมื่อ : 10/09/2013

    สอบถามเรื่องGuiหน่อยครับ Empty สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by mnl19160 11/09/13, 07:13 pm

    คือว่า อาจารย์ให้ไปลองทำโปรแกรมอะไรก็ได้มาอย่างนึง ผมเลยทำโปรแกรมเกี่ยวกับคำนวณเลข
    ผมเลยลองทำโดยที่
    เริ่มเปิดขึ้นมา มีให้ใส่เลข 1 2 3 เพื่อเลือกว่าจะให้คำนวณอะไร
    ปัญหาที่ผมพบคือ
    1.ผมลองใส่เลข1เพื่อทดสอบ(หาพ.ท4เหลี่ยม)  ก็คำนวณสี่เหลี่ยมอะไรออกมาได้ตามปกติ
    แต่พอผมลองใส่เลข2(หาพ.ท3เหลี่ยม)และ3(หาพ.ทวงกลม) มันเปิดขึ้นมาแล้วปิดเลยอ่าครับem229  เป็นเพราะอะไรหรอครับ
    2.ท่าผมเปิดมาแล้วปิดเลยมันจะขึ้นข้อความ "คุณไม่ได้ใส่เลขนะใส่ใหม่" ผมไม่อยากให้มันมีตรงส่วนนี้อ่าครับ
    ใครใจดีช่วยแก้โค้ดให้ผมที ผมมือใหม่มากๆTAT

    นี่โค้ดครับ
    Code:
    $option = InputBox("แจ้งให้ทราบ","กรุณาใส่เลขตามสูตรพื้นที่ที่คุณต้องการหานะจ๊ะ"&@CRLF&@CRLF&"1 คือ หาพื้นที่สีเหลี่ยม"&@CRLF&"2 คือ หาพื้นที่สามเหลี่ยมจ๊ะ"&@CRLF&"3 คือ หาพื้นที่วงกลม","1 or 2 or 3")
    If $option = ""  Then
    MsgBox(0,"Error","คุณไม่ได้ใส่เลขนะใส่ใหม่")
    ElseIf  $option < 0    Then
    MsgBox(0,"Error","ใส่เลขน้อยกว่า0ไม่ได้นะครับ")
    ElseIf   $option =1    Then
    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("โปรแกรมหาพื้นที่สี่เหลี่ยมจ้า", 267, 195, 348, 199)
    $Label1 = GUICtrlCreateLabel("ใส่ความยาว", 16, 56, 59, 17)
    $Input1 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label2 = GUICtrlCreateLabel("ใส่ความกว้าง", 16, 88, 64, 17)
    $Input2 = GUICtrlCreateInput("ใส่ค่าความกว้าง", 80, 88, 161, 21)
    $Input3 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button1 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label3 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label4 = GUICtrlCreateLabel("หาพื้นที่สี่เหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetData($Input3,GUICtrlRead($Input1)*GUICtrlRead($Input2))
    EndSwitch
    WEnd
    ElseIf   $option = 2  Then
    #include <GUIConstantsEx.au3>
    $Form5= GUICreate("โปรแกรมหาพื้นที่สามเหลี่ยมจ้า", 267, 195, 348, 199)
    $Label5 = GUICtrlCreateLabel("ความสูง", 16, 56, 59, 17)
    $Input5 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label6 = GUICtrlCreateLabel("ความยาวฐาน", 16, 88, 64, 17)
    $Input6 = GUICtrlCreateInput("ใส่ค่าความยาวฐาน", 80, 88, 161, 21)
    $Input7 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button2 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label7 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label8 = GUICtrlCreateLabel("หาพื้นที่สามเหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    GUICtrlSetData($Input7,(0.5)*GUICtrlRead($Input5)*GUICtrlRead($Input6))
    EndSwitch
    WEnd
    ElseIf   $option = 3   Then
    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("หาพื่นที่วงกลมจ้า", 346, 126, 577, 305)
    $Label10 = GUICtrlCreateLabel("ใส่รัศมีของวงกลม", 16, 16, 85, 17)
    $Input10 = GUICtrlCreateInput("กรอกค่ารัศมีทรงกลม", 128, 16, 161, 21)
    $Input11 = GUICtrlCreateInput("", 128, 48, 161, 21)
    $Label11 = GUICtrlCreateLabel("ผลที่ได้", 16, 56, 37, 17)
    $Button15 = GUICtrlCreateButton("คำนวณ", 8, 80, 321, 25)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button15
    GUICtrlSetData($Input11,(22/7)*GUICtrlRead($Input10)^2)
    EndSwitch
    WEnd
    EndIf
    flapjack
    flapjack
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Moderator PSsix Master PSsix Game Coder
    จำนวนข้อความ : 314
    ความนิยม : 75
    เข้าร่วมเมื่อ : 05/10/2010

    สอบถามเรื่องGuiหน่อยครับ Empty Re: สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by flapjack 11/09/13, 09:09 pm

    ประมาณนี้เปล่าครับ...
    Code:


    #include <GUIConstantsEx.au3>

    $option = InputBox("แจ้งให้ทราบ","กรุณาใส่เลขตามสูตรพื้นที่ที่คุณต้องการหานะจ๊ะ"&@CRLF&@CRLF&"1 คือ หาพื้นที่สีเหลี่ยม"&@CRLF&"2 คือ หาพื้นที่สามเหลี่ยมจ๊ะ"&@CRLF&"3 คือ หาพื้นที่วงกลม","1 or 2 or 3")
    If $option <> 0  Then
    MsgBox(0,"Error","คุณไม่ได้ใส่เลขนะใส่ใหม่")
    ElseIf  $option < 0    Then
    MsgBox(0,"Error","ใส่เลขน้อยกว่า0ไม่ได้นะครับ")
    ElseIf   $option >0    Then

    $Form1 = GUICreate("โปรแกรมหาพื้นที่สี่เหลี่ยมจ้า", 267, 195, 348, 199)
    $Label1 = GUICtrlCreateLabel("ใส่ความยาว", 16, 56, 59, 17)
    $Input1 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label2 = GUICtrlCreateLabel("ใส่ความกว้าง", 16, 88, 64, 17)
    $Input2 = GUICtrlCreateInput("ใส่ค่าความกว้าง", 80, 88, 161, 21)
    $Input3 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button1 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label3 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label4 = GUICtrlCreateLabel("หาพื้นที่สี่เหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetData($Input3,GUICtrlRead($Input1)*GUICtrlRead($Input2))
    EndSwitch
    WEnd
    ElseIf   $option = 2  Then

    $Form5= GUICreate("โปรแกรมหาพื้นที่สามเหลี่ยมจ้า", 267, 195, 348, 199)
    $Label5 = GUICtrlCreateLabel("ความสูง", 16, 56, 59, 17)
    $Input5 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label6 = GUICtrlCreateLabel("ความยาวฐาน", 16, 88, 64, 17)
    $Input6 = GUICtrlCreateInput("ใส่ค่าความยาวฐาน", 80, 88, 161, 21)
    $Input7 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button2 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label7 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label8 = GUICtrlCreateLabel("หาพื้นที่สามเหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    GUICtrlSetData($Input7,(0.5)*GUICtrlRead($Input5)*GUICtrlRead($Input6))
    EndSwitch
    WEnd
    ElseIf   $option = 3   Then

    $Form1 = GUICreate("หาพื่นที่วงกลมจ้า", 346, 126, 577, 305)
    $Label10 = GUICtrlCreateLabel("ใส่รัศมีของวงกลม", 16, 16, 85, 17)
    $Input10 = GUICtrlCreateInput("กรอกค่ารัศมีทรงกลม", 128, 16, 161, 21)
    $Input11 = GUICtrlCreateInput("", 128, 48, 161, 21)
    $Label11 = GUICtrlCreateLabel("ผลที่ได้", 16, 56, 37, 17)
    $Button15 = GUICtrlCreateButton("คำนวณ", 8, 80, 321, 25)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button15
    GUICtrlSetData($Input11,(22/7)*GUICtrlRead($Input10)^2)
    EndSwitch
    WEnd
    EndIf


    avatar
    mnl19160
    มือใหม่เพิ่งสมัคร
    มือใหม่เพิ่งสมัคร


    สอบถามเรื่องGuiหน่อยครับ Empty สอบถามเรื่องGuiหน่อยครับ Empty
    จำนวนข้อความ : 3
    ความนิยม : 0
    เข้าร่วมเมื่อ : 10/09/2013

    สอบถามเรื่องGuiหน่อยครับ Empty Re: สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by mnl19160 12/09/13, 05:23 am

    ลองก็อปโค้ดแล้วก็ยังไม่ได้อ่ะครับ ขึ้นerror ยาวมาก=___=
    avatar
    foolsopts
    PSsix Member
    PSsix Member


    สอบถามเรื่องGuiหน่อยครับ Empty
    จำนวนข้อความ : 29
    ความนิยม : 17
    เข้าร่วมเมื่อ : 24/08/2010

    สอบถามเรื่องGuiหน่อยครับ Empty Re: สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by foolsopts 12/09/13, 07:16 am

    คุณลืมอะไรทราบมั้ยครับ ลองดูที่ผมแก้ ผมเขียนคำอธิบายกำกับไว้ในส่วนสำคัญแล้ว ข้อมูลเพิ่มเติม กด F1 ในโปรแกรม Autoit

    Code:
    #include <GUIConstantsEx.au3> ;คุณลืม Include ไฟล์นี้ ไฟล์สำหรับสร้างหน้าต่าง
    #include <WindowsConstants.au3> ;คุณลืม Include ไฟล์นี้ ไฟล์สำหรับสร้างหน้าต่าง


    While 1 ;สั่งวนลูปเช็คค่า หากไม่ถูก ก็วนกลับมาแสดง inputbox ใหม่ จากเดิมเมื่อค่าผิด ก็จะ exit

    $option = InputBox("แจ้งให้ทราบ","กรุณาใส่เลขตามสูตรพื้นที่ที่คุณต้องการหานะจ๊ะ"&@CRLF&@CRLF&"1 คือ หาพื้นที่สีเหลี่ยม"&@CRLF&"2 คือ หาพื้นที่สามเหลี่ยมจ๊ะ"&@CRLF&"3 คือ หาพื้นที่วงกลม","1 or 2 or 3")

    If @error =1 Then ;เงื่อนไขนี้ คือ เช็คกรณี กดปุ่ม cancel หรือ กดปุ่ม ปิด parameter @error จะถูกกำหนดให้มีค่าเป็น 1 ดังนั้น ถ้า @error เท่ากับ 1 ก็ให้ exit ทันทีไม่ต้องแสดงอะไร

       Exit

    EndIf

    If Not StringIsAlNum ($option) Then ;อันนี้เพิ่มให้ กรณีใส่อะไรก็ตามที่ไม่ใช่เลข

       MsgBox(0,"Error","ใส่ได้เฉพาะตัวเลข")

    ElseIf $option = ""  Then

       MsgBox(0,"Error","คุณไม่ได้ใส่เลขนะใส่ใหม่")

    ElseIf $option <= 0    Then

       MsgBox(0,"Error","ใส่เลขน้อยกว่า1ไม่ได้นะครับ")

    ElseIf $option > 3 then

     MsgBox(0,"Error","ตอนนี้สามารถรับค่าได้ไม่เกิน 3")

    ElseIf $option <= 3 Then

       ExitLoop

    EndIf

    WEnd

    Switch($option) ;ส่วนนี้ เปลี่ยนจาก IF เป็น Switch ซึ่งง่ายกว่ามาก ในการเลือกเงื่อนไข แล้วทำให้ไม่งงเอง

    Case 1

    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("โปรแกรมหาพื้นที่สี่เหลี่ยมจ้า", 267, 195, 348, 199)
    $Label1 = GUICtrlCreateLabel("ใส่ความยาว", 16, 56, 59, 17)
    $Input1 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label2 = GUICtrlCreateLabel("ใส่ความกว้าง", 16, 88, 64, 17)
    $Input2 = GUICtrlCreateInput("ใส่ค่าความกว้าง", 80, 88, 161, 21)
    $Input3 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button1 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label3 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label4 = GUICtrlCreateLabel("หาพื้นที่สี่เหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetData($Input3,GUICtrlRead($Input1)*GUICtrlRead($Input2))
    EndSwitch
    WEnd

    Case 2

    #include <GUIConstantsEx.au3>
    $Form5= GUICreate("โปรแกรมหาพื้นที่สามเหลี่ยมจ้า", 267, 195, 348, 199)
    $Label5 = GUICtrlCreateLabel("ความสูง", 16, 56, 59, 17)
    $Input5 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label6 = GUICtrlCreateLabel("ความยาวฐาน", 16, 88, 64, 17)
    $Input6 = GUICtrlCreateInput("ใส่ค่าความยาวฐาน", 80, 88, 161, 21)
    $Input7 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button2 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label7 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label8 = GUICtrlCreateLabel("หาพื้นที่สามเหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    GUICtrlSetData($Input7,(0.5)*GUICtrlRead($Input5)*GUICtrlRead($Input6))
    EndSwitch
    WEnd

    Case 3

    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("หาพื่นที่วงกลมจ้า", 346, 126, 577, 305)
    $Label10 = GUICtrlCreateLabel("ใส่รัศมีของวงกลม", 16, 16, 85, 17)
    $Input10 = GUICtrlCreateInput("กรอกค่ารัศมีทรงกลม", 128, 16, 161, 21)
    $Input11 = GUICtrlCreateInput("", 128, 48, 161, 21)
    $Label11 = GUICtrlCreateLabel("ผลที่ได้", 16, 56, 37, 17)
    $Button15 = GUICtrlCreateButton("คำนวณ", 8, 80, 321, 25)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button15
    GUICtrlSetData($Input11,(22/7)*GUICtrlRead($Input10)^2)
    EndSwitch
    WEnd

    EndSwitch
    avatar
    mnl19160
    มือใหม่เพิ่งสมัคร
    มือใหม่เพิ่งสมัคร


    สอบถามเรื่องGuiหน่อยครับ Empty สอบถามเรื่องGuiหน่อยครับ Empty
    จำนวนข้อความ : 3
    ความนิยม : 0
    เข้าร่วมเมื่อ : 10/09/2013

    สอบถามเรื่องGuiหน่อยครับ Empty Re: สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by mnl19160 12/09/13, 05:21 pm

    foolsopts พิมพ์ว่า:คุณลืมอะไรทราบมั้ยครับ ลองดูที่ผมแก้ ผมเขียนคำอธิบายกำกับไว้ในส่วนสำคัญแล้ว ข้อมูลเพิ่มเติม กด F1 ในโปรแกรม Autoit

    Code:
    #include <GUIConstantsEx.au3> ;คุณลืม Include ไฟล์นี้ ไฟล์สำหรับสร้างหน้าต่าง
    #include <WindowsConstants.au3> ;คุณลืม Include ไฟล์นี้ ไฟล์สำหรับสร้างหน้าต่าง


    While 1 ;สั่งวนลูปเช็คค่า หากไม่ถูก ก็วนกลับมาแสดง inputbox ใหม่ จากเดิมเมื่อค่าผิด ก็จะ exit

    $option = InputBox("แจ้งให้ทราบ","กรุณาใส่เลขตามสูตรพื้นที่ที่คุณต้องการหานะจ๊ะ"&@CRLF&@CRLF&"1 คือ หาพื้นที่สีเหลี่ยม"&@CRLF&"2 คือ หาพื้นที่สามเหลี่ยมจ๊ะ"&@CRLF&"3 คือ หาพื้นที่วงกลม","1 or 2 or 3")

    If @error =1 Then ;เงื่อนไขนี้ คือ เช็คกรณี กดปุ่ม cancel หรือ กดปุ่ม ปิด parameter @error จะถูกกำหนดให้มีค่าเป็น 1 ดังนั้น ถ้า @error เท่ากับ 1 ก็ให้ exit ทันทีไม่ต้องแสดงอะไร

    Exit

    EndIf

    If Not StringIsAlNum ($option) Then ;อันนี้เพิ่มให้ กรณีใส่อะไรก็ตามที่ไม่ใช่เลข

    MsgBox(0,"Error","ใส่ได้เฉพาะตัวเลข")

    ElseIf $option = ""  Then

    MsgBox(0,"Error","คุณไม่ได้ใส่เลขนะใส่ใหม่")

    ElseIf $option <= 0    Then

    MsgBox(0,"Error","ใส่เลขน้อยกว่า1ไม่ได้นะครับ")

    ElseIf $option > 3 then

    MsgBox(0,"Error","ตอนนี้สามารถรับค่าได้ไม่เกิน 3")

    ElseIf $option <= 3 Then

    ExitLoop

    EndIf

    WEnd

    Switch($option) ;ส่วนนี้ เปลี่ยนจาก IF เป็น Switch ซึ่งง่ายกว่ามาก ในการเลือกเงื่อนไข แล้วทำให้ไม่งงเอง

    Case 1

    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("โปรแกรมหาพื้นที่สี่เหลี่ยมจ้า", 267, 195, 348, 199)
    $Label1 = GUICtrlCreateLabel("ใส่ความยาว", 16, 56, 59, 17)
    $Input1 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label2 = GUICtrlCreateLabel("ใส่ความกว้าง", 16, 88, 64, 17)
    $Input2 = GUICtrlCreateInput("ใส่ค่าความกว้าง", 80, 88, 161, 21)
    $Input3 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button1 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label3 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label4 = GUICtrlCreateLabel("หาพื้นที่สี่เหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    GUICtrlSetData($Input3,GUICtrlRead($Input1)*GUICtrlRead($Input2))
    EndSwitch
    WEnd

    Case 2

    #include <GUIConstantsEx.au3>
    $Form5= GUICreate("โปรแกรมหาพื้นที่สามเหลี่ยมจ้า", 267, 195, 348, 199)
    $Label5 = GUICtrlCreateLabel("ความสูง", 16, 56, 59, 17)
    $Input5 = GUICtrlCreateInput("ใส่ค่าความสูง", 80, 56, 161, 21)
    $Label6 = GUICtrlCreateLabel("ความยาวฐาน", 16, 88, 64, 17)
    $Input6 = GUICtrlCreateInput("ใส่ค่าความยาวฐาน", 80, 88, 161, 21)
    $Input7 = GUICtrlCreateInput("", 80, 120, 161, 21)
    $Button2 = GUICtrlCreateButton("คำนวณ", 120, 152, 49, 25)
    $Label7 = GUICtrlCreateLabel("ผลที่ได้", 24, 120, 37, 17)
    $Label8 = GUICtrlCreateLabel("หาพื้นที่สามเหลี่ยมจ้า", 72, 16, 134, 28)
    GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button2
    GUICtrlSetData($Input7,(0.5)*GUICtrlRead($Input5)*GUICtrlRead($Input6))
    EndSwitch
    WEnd

    Case 3

    #include <GUIConstantsEx.au3>
    $Form1 = GUICreate("หาพื่นที่วงกลมจ้า", 346, 126, 577, 305)
    $Label10 = GUICtrlCreateLabel("ใส่รัศมีของวงกลม", 16, 16, 85, 17)
    $Input10 = GUICtrlCreateInput("กรอกค่ารัศมีทรงกลม", 128, 16, 161, 21)
    $Input11 = GUICtrlCreateInput("", 128, 48, 161, 21)
    $Label11 = GUICtrlCreateLabel("ผลที่ได้", 16, 56, 37, 17)
    $Button15 = GUICtrlCreateButton("คำนวณ", 8, 80, 321, 25)
    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button15
    GUICtrlSetData($Input11,(22/7)*GUICtrlRead($Input10)^2)
    EndSwitch
    WEnd

    EndSwitch

    ได้แล้วครับ
    แล้วค่าcaseนี่มันขึ้นอยู่กับอะไร/ทำงานอย่างไร หรอครับ ใครรู้อธิบายหน่อยครับem238
    การที่ผมเปลี่ยนส่วนของ case 1,case 2 ,case 3 เป็น Case $option = 1 2 3 ตามเลขที่ผมใส่ เปิดขึ้นได้ ใช้งานได้ แต่มันส่งผลกระทบกับส่วนอื่นไหมครับ
    avatar
    foolsopts
    PSsix Member
    PSsix Member


    สอบถามเรื่องGuiหน่อยครับ Empty
    จำนวนข้อความ : 29
    ความนิยม : 17
    เข้าร่วมเมื่อ : 24/08/2010

    สอบถามเรื่องGuiหน่อยครับ Empty Re: สอบถามเรื่องGuiหน่อยครับ

    ตั้งหัวข้อ by foolsopts 12/09/13, 08:03 pm

    Switch($var)

      case ...


      case ...

    Endswitch


    ค่า case ต้องเป็นค่าเฉพาะนะครับ Switch จะรับค่า ของ $option มาตรวจสอบว่าตรงกับ case ไหน ซึ่งหมายถึง ถ้า $option มีค่าเท่ากับ 1 Switch ก็จะโยน ไปที่ Case 1

    เพราะงั้น function Switch ใช้ แยกแยะตัวแปรที่ต้องการนำไปทำงาน โดยแบ่งเป็น Case หาก ลองศึกษาจากไฟล์ Help ในโปรแกรม คุณคงจะเข้าใจครับ

      เวลาขณะนี้ 28/03/24, 09:26 pm