ฟอรั่ม 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


4 posters

    รบกวนสคริปอ่านไฟล์หน่อยครับ

    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 04/02/14, 11:34 pm

    รบกวนสคริปอ่าน textfile (.txt) แล้วให้มันแสดงผลทั้งหมด แสดงผลใน editbox (มี 100 บรรทัดก็ต้องแสดงทั้งหมด) จากนั้น สามารถแก้ไขไฟล์ แล้วมีปุ่ม คลิกเพื่อ "บันทึก" แก้ไขและ save ลงในไฟล์เดิม

    ผมพยายามทำหลายๆ รอบ อ่านได้ที่ละแถว อีกทั้งไม่สามารถนำข้อมูลที่อ่านมาแสดงได้ มึนตึบครับ แฮ่ะๆ


    ขอบคุณครับ
     em228 em229 
    yoyokungzz
    yoyokungzz
    PSsix Member Class II
    PSsix Member Class II


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 49
    ความนิยม : 9
    เข้าร่วมเมื่อ : 18/10/2013

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by yoyokungzz 05/02/14, 04:20 pm

    [You must be registered and logged in to see this link.]

    FileWriteLine เก็บข้อมูลลง .txt

    อ่านไฟล์ text
    GUICtrlSetData($var, FileRead("Text.txt"))

    ลองดูครับ (via ท่านArm)
    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 05/02/14, 11:02 pm

    yoyokungzz พิมพ์ว่า:[You must be registered and logged in to see this link.]

    FileWriteLine เก็บข้อมูลลง .txt

    อ่านไฟล์ text
    GUICtrlSetData($var, FileRead("Text.txt"))

    ลองดูครับ  (via ท่านArm)

    ขอบคุณครับ จะลองทำดู
    tomakung
    tomakung
    PSsix Member Class II
    PSsix Member Class II


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 38
    ความนิยม : 11
    เข้าร่วมเมื่อ : 24/02/2012

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by tomakung 06/02/14, 07:18 am

    #include
    #include
    #include
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Button1", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
    $file = FileOpen("test.txt", 0)
    $show= FileRead($file)
    GUICtrlSetData(-1, $show)
    FileClose($file)
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button2
    $Edit1=GUICtrlSetData(-1, "")
    Case $Button3
    $hsave=FileSaveDialog("Choose...",@ScriptDir,"Text Files (*.txt)")
    If $hsave="" Then
    cancel()
    else
    FileWrite($hsave&".txt",GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    EndIf
    EndSwitch

    WEnd

    Func cancel()
    MsgBox(64,"Cancelled","Cancelled")

    EndFunc
    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 06/02/14, 09:28 am

    tomakung พิมพ์ว่า:#include
    #include
    #include
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Button1", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
    $file = FileOpen("test.txt", 0)
               $show= FileRead($file)
    GUICtrlSetData(-1, $show)
               FileClose($file)
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button2
    $Edit1=GUICtrlSetData(-1, "")
    Case $Button3
               $hsave=FileSaveDialog("Choose...",@ScriptDir,"Text Files (*.txt)")
               If $hsave="" Then
               cancel()
               else
               FileWrite($hsave&".txt",GUICtrlRead($Edit1))
               MsgBox(64,"Saved","Document was saved",5)

    EndIf
       EndSwitch

    WEnd

    Func cancel()
       MsgBox(64,"Cancelled","Cancelled")

       EndFunc

    ขอบคุณท่าน tomakung เกือบได้แล้วครับแต่ติดนิดหน่อย

    FileWrite($hsave&".txt",GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    ผมแก้เป็น

    FileWrite($hsave,GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    เอา .txt ออก เพราะมัน save เป็น .txt.txt ซ้ำๆ กันไปเรื่อย

    แต่ก็ยังไม่ตรงตามที่ต้องการ เพราะ
    1. ทุกครั้งที่แก้ไข มันจะบันทึกต่อท้าย ต้องการให้มันแทนที่ครับ
    2. เวลาคลิก save ต้องการให้บันทึกซ้ำไฟล์เดิมเลยครับไม่ต้องการให้เลือกไฟล์ save แต่ แจ้งเตือนก่อนทำการ save ด้วยก็ดี

    ขอบคุณครับ
    flapjack
    flapjack
    PSsix Member Super Class III
    PSsix Member Super Class III


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

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by flapjack 06/02/14, 02:50 pm

    MaxiMus พิมพ์ว่า:
    tomakung พิมพ์ว่า:#include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Button1", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
    $file = FileOpen("test.txt", 0)
               $show= FileRead($file)
    GUICtrlSetData(-1, $show)
               FileClose($file)
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button2
    $Edit1=GUICtrlSetData(-1, "")
    Case $Button3
               $hsave=FileSaveDialog("Choose...",@ScriptDir,"Text Files (*.txt)")
               If $hsave="" Then
               cancel()
               else
               FileWrite($hsave&".txt",GUICtrlRead($Edit1))
               MsgBox(64,"Saved","Document was saved",5)

    EndIf
       EndSwitch

    WEnd

    Func cancel()
       MsgBox(64,"Cancelled","Cancelled")

       EndFunc

    ขอบคุณท่าน tomakung เกือบได้แล้วครับแต่ติดนิดหน่อย

    FileWrite($hsave&".txt",GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    ผมแก้เป็น

    FileWrite($hsave,GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    เอา .txt ออก เพราะมัน save เป็น .txt.txt ซ้ำๆ กันไปเรื่อย

    แต่ก็ยังไม่ตรงตามที่ต้องการ เพราะ
    1. ทุกครั้งที่แก้ไข มันจะบันทึกต่อท้าย ต้องการให้มันแทนที่ครับ
    2. เวลาคลิก save ต้องการให้บันทึกซ้ำไฟล์เดิมเลยครับไม่ต้องการให้เลือกไฟล์ save แต่ แจ้งเตือนก่อนทำการ save ด้วยก็ดี

    ขอบคุณครับ

    ประมาณนี้เปล่าครับ (โค๊ดจาก คุณ tomakung)
    Code:

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Read", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    $file = FileOpen("test.txt", 9)

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
       FileClose($file)
    GUICtrlSetData($Edit1, readContents() )
    Case $GUI_EVENT_CLOSE
       FileClose($file)
    Exit
    case $Button2
     GUICtrlSetData($Edit1," ")
    Case $Button3
                FileClose($file)
               MsgBox(64,"Status","Document was "& saveContents(GUICtrlRead($Edit1)),5)
       EndSwitch

    WEnd

    Func saveContents($text)
    $file = FileOpen("test.txt", 2)
    If $file = -1 Then
     Return "File Not Save"
    Else
     FileWrite ("test.txt",$text)
    FileClose($file)
     Return "File Save"
     EndIf
    EndFunc

    Func readContents()
    $file = FileOpen("test.txt", 0)
        $text = FileRead($file)
        If @error = -1 Then
     Return "Error : Error : Cannot read file"
         EndIf
    FileClose($file)

    Return $text
     EndFunc
    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 06/02/14, 11:32 pm

    flapjack พิมพ์ว่า:
    MaxiMus พิมพ์ว่า:
    tomakung พิมพ์ว่า:#include
    #include
    #include
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Button1", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
    $file = FileOpen("test.txt", 0)
               $show= FileRead($file)
    GUICtrlSetData(-1, $show)
               FileClose($file)
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button2
    $Edit1=GUICtrlSetData(-1, "")
    Case $Button3
               $hsave=FileSaveDialog("Choose...",@ScriptDir,"Text Files (*.txt)")
               If $hsave="" Then
               cancel()
               else
               FileWrite($hsave&".txt",GUICtrlRead($Edit1))
               MsgBox(64,"Saved","Document was saved",5)

    EndIf
       EndSwitch

    WEnd

    Func cancel()
       MsgBox(64,"Cancelled","Cancelled")

       EndFunc

    ขอบคุณท่าน tomakung เกือบได้แล้วครับแต่ติดนิดหน่อย

    FileWrite($hsave&".txt",GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    ผมแก้เป็น

    FileWrite($hsave,GUICtrlRead($Edit1))
    MsgBox(64,"Saved","Document was saved",5)

    เอา .txt ออก เพราะมัน save เป็น .txt.txt ซ้ำๆ กันไปเรื่อย

    แต่ก็ยังไม่ตรงตามที่ต้องการ เพราะ
    1. ทุกครั้งที่แก้ไข มันจะบันทึกต่อท้าย ต้องการให้มันแทนที่ครับ
    2. เวลาคลิก save ต้องการให้บันทึกซ้ำไฟล์เดิมเลยครับไม่ต้องการให้เลือกไฟล์ save แต่ แจ้งเตือนก่อนทำการ save ด้วยก็ดี

    ขอบคุณครับ

    ประมาณนี้เปล่าครับ (โค๊ดจาก คุณ tomakung)
    Code:

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 615, 437, 192, 124)
    $Button1 = GUICtrlCreateButton("Read", 448, 24, 97, 33)
    $Button2 = GUICtrlCreateButton("Delete", 448, 80, 97, 33)
    $Button3 = GUICtrlCreateButton("Save", 448, 140, 97, 33)
    $Edit1 = GUICtrlCreateEdit("", 40, 24, 177, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    $file = FileOpen("test.txt", 9)

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    case $Button1
       FileClose($file)
    GUICtrlSetData($Edit1, readContents() )
    Case $GUI_EVENT_CLOSE
       FileClose($file)
    Exit
    case $Button2
     GUICtrlSetData($Edit1," ")
    Case $Button3
                FileClose($file)
               MsgBox(64,"Status","Document was "& saveContents(GUICtrlRead($Edit1)),5)
       EndSwitch

    WEnd

    Func saveContents($text)
    $file = FileOpen("test.txt", 2)
    If $file = -1 Then
     Return "File Not Save"
    Else
     FileWrite ("test.txt",$text)
    FileClose($file)
     Return "File Save"
     EndIf
    EndFunc

    Func readContents()
    $file = FileOpen("test.txt", 0)
        $text = FileRead($file)
        If @error = -1 Then
     Return "Error : Error : Cannot read file"
         EndIf
    FileClose($file)

    Return $text
     EndFunc

     em238 em238 em238 

    ถูกต้องเลยครับบบบ ขอบคุณมากๆ ครับ
    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 07/02/14, 12:07 am

    แต่สอบเพิ่มเติมหน่อยครับ

    $file = FileOpen("test.txt", 9)

    0 = Read mode (default)
    1 = Write mode (append to end of file)
    2 = Write mode (erase previous contents)
    8 = Create directory structure if it doesn't exist (See Remarks).
    16 = Force binary mode (See Remarks).
    ......

    เลข 9 มัน ให้ทำอะไรครับ ท่าน
    flapjack
    flapjack
    PSsix Member Super Class III
    PSsix Member Super Class III


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

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by flapjack 07/02/14, 02:40 am

    MaxiMus พิมพ์ว่า:แต่สอบเพิ่มเติมหน่อยครับ

    $file = FileOpen("test.txt", 9)

     0 = Read mode (default)
     1 = Write mode (append to end of file)
     2 = Write mode (erase previous contents)
     8 = Create directory structure if it doesn't exist (See Remarks).
     16 = Force binary mode (See Remarks).
     ......

    เลข 9 มัน ให้ทำอะไรครับ ท่าน

    เกิดจาก mode ของเลข 8 กับ เลข 1 มา + กันครับ
    มีความว่า ถ้าไฟล์ไม่มีให้สร้างไฟล์และเริ่มการเขียนแบบเนื้อหาสุดท้ายของไฟล์นั้น(เนื้อหาของไฟล์ จะเพิ่มต่อจากเนื้อหาที่มีอยู่)
    avatar
    MaxiMus
    สมาชิกทั่วไป
    สมาชิกทั่วไป


    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty รบกวนสคริปอ่านไฟล์หน่อยครับ Empty
    จำนวนข้อความ : 13
    ความนิยม : 0
    เข้าร่วมเมื่อ : 28/01/2014

    รบกวนสคริปอ่านไฟล์หน่อยครับ Empty Re: รบกวนสคริปอ่านไฟล์หน่อยครับ

    ตั้งหัวข้อ by MaxiMus 10/02/14, 02:05 pm

    flapjack พิมพ์ว่า:
    MaxiMus พิมพ์ว่า:แต่สอบเพิ่มเติมหน่อยครับ

    $file = FileOpen("test.txt", 9)

     0 = Read mode (default)
     1 = Write mode (append to end of file)
     2 = Write mode (erase previous contents)
     8 = Create directory structure if it doesn't exist (See Remarks).
     16 = Force binary mode (See Remarks).
     ......

    เลข 9 มัน ให้ทำอะไรครับ ท่าน

    เกิดจาก mode ของเลข 8 กับ เลข 1 มา + กันครับ
    มีความว่า ถ้าไฟล์ไม่มีให้สร้างไฟล์และเริ่มการเขียนแบบเนื้อหาสุดท้ายของไฟล์นั้น(เนื้อหาของไฟล์ จะเพิ่มต่อจากเนื้อหาที่มีอยู่)

    ขอบคุณมากๆ ครับ เป็นความรู้ใหม่ สำหรับผมจริงๆ

      เวลาขณะนี้ 07/05/24, 04:13 pm