kulltsb Posted February 4, 2019 Share Posted February 4, 2019 I tried my best to help myself using the forums, but I am at a loss now. I have data in an array. I want to copy a specific cell's data to my clipboard. That's it! The array is created dynamically. I first made the array in GUI listview... and then I found out you can't do anything with that info... so I made a new array in the GUI using labels. I made lots of buttoms to press to copy a specific cell, but I can't pass a variable with onevent mode. I found this and it got me quite close... I edited it slightly. Basically, I need to take COPYBUTTON[$VARIABLE] and have it give me $MAINARRAY[$VARIABLE][1] so I can then copy to clipboard $MAINARRAY[$VARIABLE][1] Local $iMsg = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $COPYBUTTON[0] To $COPYBUTTON[($directoryArray[0]-3)] $split = StringSplit($MAINARRAY[$i][1],"|") $name=$split[1] $email=$split[2] ClipPut($email) EndSwitch sleep(20) WEnd Link to comment Share on other sites More sharing options...
kulltsb Posted February 4, 2019 Author Share Posted February 4, 2019 The best I can do is this: Local $iMsg = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $COPYBUTTON[0] To $COPYBUTTON[($directoryArray[0]-3)] $string=GUICtrlRead($iMsg) ClipPut($string) EndSwitch sleep(20) WEnd But now the Buttons have email addresses from an array instead of the word COPY... which looks quite ugly and unprofessional. Any ideas? Link to comment Share on other sites More sharing options...
Subz Posted February 4, 2019 Share Posted February 4, 2019 Can you post your full script or a working example, its difficult to understand what you're trying to accomplish with just one half of the script. Link to comment Share on other sites More sharing options...
kulltsb Posted February 4, 2019 Author Share Posted February 4, 2019 #include <Process.au3> #include <WindowsConstants.au3> #include <String.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <FontConstants.au3> #include <ColorConstants.au3> global $txtname = "New Text Document.txt" Dim $MAINARRAY[0][2] Local $hMainGUI = GUICreate("Contacts", 800, 900) GUISetState(@SW_SHOW, $hMainGUI) $directoryArray = _FileListToArray(@Workingdir) For $i = 1 to $directoryArray[0]-2 $filename = $directoryArray[$i] & "\" & $txtname OpenFileAndArray() next _ArraySort($MAINARRAY, 0, 0, 0, 0) ;Local $idListview = GUICtrlCreateListView("STATE|NAME|EMAIL", 100, 10, 500, 300) ;,$LVS_SORTDESCENDING) ;_ArrayDisplay($MAINARRAY, "$avArray AFTER _ArraySort() ascending column 0") #cs For $i = 0 To ($directoryArray[0]-3) GUICtrlCreateListViewItem($MAINARRAY[$i][0] & "|" & $MAINARRAY[$i][1], $idListview) Next _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($idListview, 1, $LVSCW_AUTOSIZE) _GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE) #ce $hLbl = GUICtrlCreateLabel("STATE", 60 , 400, 70, 20, 0x1000) GUICtrlSetFont($hLbl, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLbl, $COLOR_BLACK) GUICtrlSetBkColor($hLbl, 0xffffff) $hLbl2 = GUICtrlCreateLabel("NAME", 130 , 400, 70, 20, 0x1000) GUICtrlSetFont($hLbl2, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLbl2, $COLOR_BLACK) GUICtrlSetBkColor($hLbl2, 0xffffff) $hLbl3 = GUICtrlCreateLabel("EMAIL", 200 , 400, 70, 20, 0x1000) GUICtrlSetFont($hLbl3, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLbl3, $COLOR_BLACK) GUICtrlSetBkColor($hLbl3, 0xffffff) For $i = 0 To ($directoryArray[0]-3) $hLblx = GUICtrlCreateLabel($MAINARRAY[$i][0], 60 , 420+($i*20), 70, 20, 0x1000) GUICtrlSetFont($hLblx, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLblx, $COLOR_BLACK) GUICtrlSetBkColor($hLblx, 0xffffff) Next Dim $COPYBUTTON[($directoryArray[0]-2)] For $i = 0 To ($directoryArray[0]-3) $split = StringSplit($MAINARRAY[$i][1],"|") $name=$split[1] $email=$split[2] $hLblx = GUICtrlCreateLabel($name, 130 , 420+($i*20), 70, 20, 0x1000) GUICtrlSetFont($hLblx, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLblx, $COLOR_BLACK) GUICtrlSetBkColor($hLblx, 0xffffff) $hLblx = GUICtrlCreateLabel($email, 200 , 420+($i*20), 70, 20, 0x1000) GUICtrlSetFont($hLblx, 12, $FW_BOLD, $GUI_FONTNORMAL, "Arial") GUICtrlSetColor($hLblx, $COLOR_BLACK) GUICtrlSetBkColor($hLblx, 0xffffff) $COPYBUTTON[$i] = GUICtrlCreateButton("COPY", 10, 420+($i*20), 50,20) GUICtrlSetData ( $COPYBUTTON[$i], $email ) Next GUISetState() Local $iMsg = 0 While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $COPYBUTTON[0] To $COPYBUTTON[($directoryArray[0]-3)] $string=GUICtrlRead($iMsg) ClipPut($string) EndSwitch sleep(20) WEnd Func OKButton($i) ; Note: At this point @GUI_CtrlId would equal $iOKButton, ; and @GUI_WinHandle would equal $hMainGUI MsgBox($MB_OK, "GUI Event", "You selected OK!") EndFunc ;==>OKButton Func CLOSEButton() ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ; and @GUI_WinHandle would equal $hMainGUI Exit EndFunc ;==>CLOSEButton Func OpenFileAndArray() $file = FileOpen($filename, 0) Dim $array _FileReadToArray($filename,$array) FileClose($file) For $i = 1 To $array[0] ; MsgBox(0,"",$string[$x]) ; ConsoleWrite("HERE"& @CRLF) ; ConsoleWrite($string[0]& @CRLF) ; ConsoleWrite("HERE2"& @CRLF) ; ConsoleWrite($string[1]& @CRLF) ; ConsoleWrite($array[$i]& @CRLF) Next local $arrayaddtemp[1][2] $name1 = StringSplit($array[7],":") $name2 = StringSplit($name1[2]," ") $arrayaddtemp[0][0] = $name2[2] $name1 = StringSplit($array[1],":") $name2 = StringSplit($name1[2]," ") ;_ArrayAdd($MAINARRAY, $name2[2]) $email1 = StringSplit($array[2],":") $email2 = StringSplit($email1[2]," ") $nameemail = $name2[2] & "|" & $email2[2] $arrayaddtemp[0][1] = $nameemail _ArrayAdd($MAINARRAY, $arrayaddtemp) Endfunc Link to comment Share on other sites More sharing options...
Subz Posted February 4, 2019 Share Posted February 4, 2019 Can you also post an example of the text file? Link to comment Share on other sites More sharing options...
kulltsb Posted February 4, 2019 Author Share Posted February 4, 2019 The text files have employee Name, Email, and Address. Basically I am making a program to make sending e-mails to the right employee faster. Link to comment Share on other sites More sharing options...
Subz Posted February 4, 2019 Share Posted February 4, 2019 (edited) I understand that, however would like to see the format of the text, it appears you have more than 3 delimiters, as I mentioned just require an example i.e does it look like: John Doe:John.Doe@example.com:Arizona:Jane Doe:Jane.Doe@example.com:Washington DC Edited February 4, 2019 by Subz Link to comment Share on other sites More sharing options...
dmob Posted February 5, 2019 Share Posted February 5, 2019 Wouldn't a listview serve you better? Link to comment Share on other sites More sharing options...
kulltsb Posted February 5, 2019 Author Share Posted February 5, 2019 Name: X Email: X Phone: X Age: X Street Address: X City: X State: X Zip Code: X i did listview, but i searched and you cannot copy to clipboard individual cells Link to comment Share on other sites More sharing options...
Subz Posted February 5, 2019 Share Posted February 5, 2019 (edited) Here is a basic example using listview: expandcollapse popup#include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $g_idAddress, $g_idListView _Example() Func _Example() Local $aDocument, $aDocuments = _FileListToArrayRec(@ScriptDir, "New Text Document.txt", 1, 1, 0, 2) GUICreate("Contacts", 800, 900) $g_idListView = GUICtrlCreateListView("Name|Email|Phone|Age|Street Address|City|State|Zip Code", 10, 10, 780, 500) For $i = 1 To $aDocuments[0] _FileReadToArray($aDocuments[$i], $aDocument, 0, ":") _ArrayTranspose($aDocument) _ArrayDelete($aDocument, 0) _GUICtrlListView_AddArray($g_idListView, $aDocument) Next $g_idAddress = GUICtrlCreateEdit("", 10, 515, 780, 200) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $iIndex, $sText Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $g_idListView If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked Case $LVN_KEYDOWN ; A key has been pressed $iIndex = _GUICtrlListView_GetSelectionMark($g_idListView) + 1 $sText = _GUICtrlListView_GetItemText($g_idListView, $iIndex, 0) & @CRLF $sText &= _GUICtrlListView_GetItemText($g_idListView, $iIndex, 1) & @CRLF $sText &= _GUICtrlListView_GetItemText($g_idListView, $iIndex, 2) & @CRLF GUICtrlSetData($g_idAddress, $sText) ClipPut($sText) MsgBox(4096, "Clipboard", "Added to ClipBoard", 1) Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $sText = _GUICtrlListView_GetItemText($g_idListView, DllStructGetData($tInfo, "Index"), 0) & @CRLF $sText &= _GUICtrlListView_GetItemText($g_idListView, DllStructGetData($tInfo, "Index"), 1) & @CRLF $sText &= _GUICtrlListView_GetItemText($g_idListView, DllStructGetData($tInfo, "Index"), 2) & @CRLF GUICtrlSetData($g_idAddress, $sText) ClipPut($sText) MsgBox(4096, "Clipboard", "Added to ClipBoard", 1) Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY If you want more advanced features recommend Melba23 ListviewEx.au3 udf found here: Edited February 5, 2019 by Subz Skysnake 1 Link to comment Share on other sites More sharing options...
Skysnake Posted March 8, 2019 Share Posted March 8, 2019 (edited) I don't have my scripts with me, but... You can make Listviews with checkboxes, tick the box corresponding to the row item you want, click on a button and do something with any value in a selected cell. I'll try to find an example Found it @kulltsb Here we go. SQLite db for data persistence, Listview for pretty display. And a nice GUI to make your CRUD easy You don't need to copy cell data to the clipboard, you can select to a $var and then do with it as you please... Zip file includes the SQLite 3.12.1 DLL. getLVcelldata.zip This uses a very different approach to managing the Listview compared to what @Subz put above. I only think my code is easier to follow and perhaps easier to maintain. Edited March 9, 2019 by Skysnake Subz 1 Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now