Jump to content

Txt value read to inputbox write


mucitbey
 Share

Recommended Posts

1 hour ago, pixelsearch said:

Hi mucitbey,
1 line of code could do that, but it will color the whole line (which shouldn't be a big problem ?)
Coloring only the time column seems a bit harder, though doable (I've been told)

colored.png.7a3cdfb44bf7340b410e9a82f9f6f447.png

Depending on the script you will choose, add one of these lines, just after the GUICtrlCreateListViewItem() line : 

If $aInFile[$i][4] > "08:10:00" And $aInFile[$i][4] < "16:50:00" Then _
    GUICtrlSetBkColor(-1, 0xDDFFE0) ; light green

; or

If $aTemp[4] > "08:10:00" And $aTemp[4] < "16:50:00" Then _
    GUICtrlSetBkColor(-1, 0xC0FFFF) ; light blue is great too !

Good luck :)

 

Endless thanks for your help and support.

Link to comment
Share on other sites

Glad we could help, mucitbey :)
With the help of mikell's script, I was able to color only the Time column.

Here is the resulting script, in case it's important for you.
Also this script could be helpful for other Forum readers who would like to color only 1 column in listview

#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

Global $aInFile
_FileReadToArray("20191015.txt", $aInFile, $FRTA_NOCOUNT, ", ")
Global $iLines = UBound($aInFile)
; _ArrayDisplay($aInFile, "$aInFile")

Global $bFile
_FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=")
; _ArrayDisplay($bFile, "$bFile")

$hGUI = GUICreate("_mucitbey_", 430, 500)
$lv = GUICtrlCreateListView("#|Card ID|[]|Date|Clock|User", 10, 60, 400, 400)
Global $hListView = GuiCtrlGetHandle($lv)

$nBegin = TimerInit()
For $i = 0 To $iLines - 1

    ; $iIndex = _ArraySearch($bFile, $aInFile[$i][1], 0, 0, 0, 0, 1, 0) ; search only col. 0
    $iIndex = _ArrayBinarySearch($bFile, $aInFile[$i][1], 0, 0, 0) ; use only if "Users.txt" is sorted

    $user = (($iIndex <> -1) ? ($bFile[$iIndex][1]) : ("Unknown ID"))

    GUICtrlCreateListViewItem($aInFile[$i][0] & "|" & $aInFile[$i][1] & "|" & _
        $aInFile[$i][2] & "|" & $aInFile[$i][3] & "|" & $aInFile[$i][4] & "|" & $user, $lv)
        
;   If you want the whole row colored, comment line GUIRegisterMsg($WM_NOTIFY...)
;   If $aInFile[$i][4] > "08:10:00" And $aInFile[$i][4] < "16:50:00" Then _
;       GUICtrlSetBkColor(-1, 0xDDFFDD) ; light green for 1 complete row

Next
ConsoleWrite(TimerDiff($nBegin) & @CRLF)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
GUIDelete($hGUI)

;============================================
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
                    Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                    Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                    Local $iColor = 0xFF000000 ; $CLR_DEFAULT                   
                    If $iSubItem = 4 Then ; Time column
                        If $aInFile[$iItem][4] > "08:10:00" And $aInFile[$iItem][4] < "16:50:00" Then
                            $iColor = 0xDDFFDD ; light green for 1 subitem... RGB = BGR :)
                            ; $iColor = RGB2BGR(0xC0FFFF) ; light blue
                        EndIf
                    EndIf
                    DllStructSetData($tCustDraw, "clrTextBk", $iColor) ; background color
                    Return $CDRF_NEWFONT
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

;============================================
Func RGB2BGR($iColor)
     Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR()

1062861597_coloredsubitem.png.756b5356a9521481f45a12ca2814329f.png

I also upload the 2 text files "20191015.txt" (1000 rows) and "Users.txt" (500 users, sorted on ID, which allows the use of _ArrayBinarySearch() in the precedent script) so anyone can easily try the script.

20191015.txt

Users.txt

Edited by pixelsearch
moved GUIRegisterMsg() just before GUISetState(), much faster display, thx Mikell !
Link to comment
Share on other sites

@Zedna : It sure is, 2s for opening both text files of 5.000 and 10.000 rows with _FileReadToArray() on my antique PC, compared to 200ms to open and read the same text files with your script. I tested it placing 3 timers in both scripts.

But as in the end, _ArrayBinarySearch() will always beat StringInStr() by several seconds when the files are big, so this is going nowhere. Imho, the more bigger the files will be, the more _ArrayBinarySearch() will rule, compared to StringInStr()

Anyway, no big deal. Each one is free to choose his own path, it's always great to have several points of view :)

@Mikell : many thanks for your advice, indicating me how to display the ListView faster, by moving GUIRegisterMsg() just before GUISetState(), I amended the script above to reflect the change and it sure displays much faster now :)

Edited by pixelsearch
Link to comment
Share on other sites

  • 2 weeks later...

Hello friends,
once again I need your help. I added a report selection feature to the program. My question is to list the ID and names in the User.txt file and to list those ID and names that are not in the 20191015.txt ID data (no card data record). User list can also be. I share my codes. Thank you.

#include <Array.au3>
#include <File.au3>
#include <Date.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("_mucitbey_ PDKS v1.0", 690, 520, -1, -1);  $WS_CAPTION, $WS_EX_TOPMOST
$fi = GUICtrlCreateMenu("&File")
$fi1 = GUICtrlCreateMenuItem("Raport Open", $fi)
$fi2 = GUICtrlCreateMenuItem("List Of Person", $fi)
$fi3 = GUICtrlCreateMenuItem("Empty", $fi)
$ext = GUICtrlCreateMenuItem("Exit", $fi)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $fi1
            $lv = GUICtrlCreateListView("Card ID|Date|Clock|Name and Surname|", 10, 10, 400, 480)
            _GUICtrlListView_DeleteAllItems($lv)
            $ArrFile = FileOpenDialog("Chose Raport Date ",@ScriptDir, "Raport (*.txt)")
            Global $bFile, $aInFile, $ArrFile
            _FileReadToArray($ArrFile, $aInFile, $FRTA_NOCOUNT)
            Global $iLines = UBound($aInFile)
            _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=")
                For $i = 0 To $iLines - 1
                    $aTemp = StringSplit($aInFile[$i], ", ", $STR_NOCOUNT)
                    $user = GetUser($aTemp[1])
                    GUICtrlCreateListViewItem($aTemp[1] &"|"& $aTemp[3] &"|"& $aTemp[4] &"|"& $user, $lv)
            If $aTemp[4] > "08:10:00" And $aTemp[4] < "16:50:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF)
                Next

        $Uv = GUICtrlCreateListView("Card ID|User", 420, 10, 260, 480)
        Global $uFile
        _FileReadToArray("Users.txt", $uFile, $FRTA_NOCOUNT)
        Global $iLine = UBound($uFile)
            For $i = 0 To $iLine - 1
                $uTemp = StringSplit($uFile[$i], "=", $STR_NOCOUNT)
        If  $uTemp[0] <> $aTemp[1] Then GUICtrlCreateListViewItem($uTemp[0] &"|"& $uTemp[1], $Uv)
            Next

        Case $fi2
            Global $bFile
            _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=")
            _ArrayDisplay($bFile, "USER LİST", "|", Default, Default, "CARD ID|NAME AND SURNAME|")

        Case $fi3


        Case $ext
            Exit
    EndSwitch
WEnd

Func GetUser($ID)
    Local $iIndex = _ArraySearch($bFile, $ID)
    If $iIndex <> -1 Then
        Return $bFile[$iIndex][1]
    Else
        Return "Undefined ID"
    EndIf
EndFunc

 

Edited by mucitbey
Link to comment
Share on other sites

Hi mucitbey,

#include <Array.au3>
#include <File.au3>
#include <Date.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $hGui = GUICreate("_mucitbey_ PDKS v1.0", 690, 520, -1, -1);  $WS_CAPTION, $WS_EX_TOPMOST
$fi = GUICtrlCreateMenu("&File")
$fi1 = GUICtrlCreateMenuItem("Raport Open", $fi)
$fi2 = GUICtrlCreateMenuItem("List Of Person", $fi)
$fi3 = GUICtrlCreateMenuItem("Empty", $fi)
$ext = GUICtrlCreateMenuItem("Exit", $fi)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $fi1
            $lv = GUICtrlCreateListView("Card ID|Date|Clock|Name and Surname|", 10, 10, 400, 480)
            _GUICtrlListView_DeleteAllItems($lv)

            Global $bFile, $aInFile, $ArrFile
            $ArrFile = FileOpenDialog("Chose Raport Date ",@ScriptDir, "Raport (*.txt)")

            _FileReadToArray($ArrFile, $aInFile, $FRTA_NOCOUNT)
            Global $iLines = UBound($aInFile)

            _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=")
            Global $iLines_Users = UBound($bFile)
            Global $iCols_Users = UBound($bFile, 2)
            Redim $bFile[$iLines_Users][$iCols_Users+1] ; add empty column

            ; GUISetState(@SW_LOCK, $hGui) ; "Lock the window to avoid repainting"
            For $i = 0 To $iLines - 1
                $aTemp = StringSplit($aInFile[$i], ", ", $STR_NOCOUNT)
                $user = GetUser($aTemp[1])
                GUICtrlCreateListViewItem($aTemp[1] &"|"& $aTemp[3] &"|"& $aTemp[4] &"|"& $user, $lv)
                If $aTemp[4] > "08:10:00" And $aTemp[4] < "16:50:00" Then GUICtrlSetBkColor(-1, 0xC0FFFF)
            Next
            ; GUISetState(@SW_UNLOCK, $hGui) ; "Unlock the window to allow repainting"

            $Uv = GUICtrlCreateListView("Card ID|User", 420, 10, 260, 480)
            Local $aAbsent = _ArrayFindAll($bFile, 0, Default, Default, Default, Default, 2)
            For $i = 0 To Ubound($aAbsent) - 1
                GUICtrlCreateListViewItem($bFile[$aAbsent[$i]][0] &"|"& _
                    $bFile[$aAbsent[$i]][1], $Uv)
            Next

        Case $fi2
            Global $bFile
            _FileReadToArray("Users.txt", $bFile, $FRTA_NOCOUNT, "=")
            _ArrayDisplay($bFile, "USER LIST", "|", Default, Default, "CARD ID|NAME AND SURNAME|")

        Case $fi3

        Case $ext
            Exit
    EndSwitch
WEnd

Func GetUser($ID)
    Local $iIndex = _ArraySearch($bFile, $ID)
    If $iIndex <> -1 Then
        $bFile[$iIndex][2] = 1 ; 1 = User checked in/out
        Return $bFile[$iIndex][1]
    Else
        Return "Undefined ID"
    EndIf
EndFunc

165d.png.6b6fa71956c74cfdf034e5f80ee45418.png

I added a last empty column in $bFile (Users.txt array), so when a user checks in/out, his cell in this column becomes = 1. At the end of the day, all empty cells in the last column mean these users didn't check in/out

Does the image above reflect the result you expect, if Users 89 & 317 didn't check in/out that day ?

Edited by pixelsearch
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...