Sign in to follow this  
Followers 0
johnmcloud

Add Checkbox(s) in a GUI List

18 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I have this script:

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

$Form1 = GUICreate("Form1", 248, 180)
$Edit = GUICtrlCreateEdit("", 8, 8, 233, 121)
$Button = GUICtrlCreateButton("Save", 8, 136, 233, 33)
GUISetState(@SW_SHOW)

$TestFile = @WorkingDir & "Test.txt"
FileOpen($TestFile, 2)
FileWrite($TestFile, "Word_1" & @CRLF & "Word_2" & @CRLF & "Word_3" & @CRLF & "Word_4")
GUICtrlSetData($Edit, FileRead($TestFile))

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
     FileDelete(@WorkingDir & "Result.txt")
     FileWrite(@WorkingDir & "Result.txt", GUICtrlRead($Edit))
     ShellExecute(@WorkingDir & "Result.txt") EndSwitch
WEnd

I don't know how, i'd like to add a checkbox on every line of this list, so if i unchecked some and click on the button it save only the element with the checkbox enabled. I don't know how hany line has .txt, but i think we can read by array[0]

Hope I was clear, if not just ask and I'll try to post more information.

Thanks ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites



Not possible in an Edit control, you can do it in a ListView control though.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Can you provide a simple script example like mine? It's better for me to understand. I think i can integrate a listview control in a GUI, right?

Thanks for your time.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Below is a ruff script of what you could do. It gets buggy when you start scrolling, but there is a probably a workaround.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include<array.au3>
$Form1 = GUICreate("Form1", 248, 180)
$Edit = GUICtrlCreateEdit("", 20, 8, 233, 121)
$Button = GUICtrlCreateButton("Save", 8, 136, 233, 33)

Local $iBoxes,$aBoxes[1], $sMSG, $iLines=1

GUISetState(@SW_SHOW)




GUICtrlSetData($Edit,"a"&@crlf&"b"&@crlf&"c"&@crlf)



While 1
$nMsg = GUIGetMsg()

$aLines=StringRegExp(GUICtrlRead($Edit),"(.*)?(?:v)?",3)

$iLines=UBound($aLines)

$iBoxes= UBound($aBoxes)
If $iBoxes>$iLines Then
For $x=$iLines To UBound($aBoxes)-1
GUICtrlDelete($aBoxes[$x])
Next
EndIf

ReDim $aBoxes[$iLines]
If $iBoxes<$iLines Then
For $x=$iBoxes To UBound($aBoxes)-1
$aBoxes[$x-1]=GUICtrlCreateCheckbox("",2,($x-1)*14+8,14)
GUICtrlSetState(-1,$GUI_CHECKED)
Next

EndIf


Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Edit

Case $Button
$sMSG=""
$aEdit=StringRegExp(GUICtrlRead($Edit),"(.*)?(?:v)?",3)


For $x=0 To UBound($aBoxes)-1

If BitAnd(GUICtrlRead ($aBoxes[$x]),$GUI_CHECKED) Then

$sMSG&=$aEdit[$x]
EndIf
Next
MsgBox (0,"",$sMSG)
EndSwitch

WEnd
Edited by DicatoroftheUSA

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok guys, for now i have make this:

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

Dim $item[6] = [5]

GUICreate("Example", 216, 201, -1, -1, -1, $WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("Name1", 10, 10, 192, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 185)
$item[1] = GUICtrlCreateListViewItem("Select/Unselect All", $listview)
$item[2] = GUICtrlCreateListViewItem("Word1", $listview)
$item[3] = GUICtrlCreateListViewItem("Word2", $listview)
$item[4] = GUICtrlCreateListViewItem("Word3", $listview)
$item[5] = GUICtrlCreateListViewItem("Word4", $listview)
$button = GUICtrlCreateButton("Save", 11, 162, 186, 20)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button
For $i = 1 To $item[0]
    If BitAND(GUICtrlRead($item[$i], 1), $GUI_CHECKED) Then
     FileDelete(@WorkingDir & "Test.txt")
     FileWrite(@WorkingDir & "Test.txt", StringTrimRight(GUICtrlRead($item[$i]),1))
     ShellExecute(@WorkingDir & "Test.txt")
;~   MsgBox(0, 0, GUICtrlRead($item[$i]), 2)
    EndIf EndIf
Next
EndSwitch
WEnd

There are a couple of problems:

1) This script not read the information from a file, the problem is not how to do, but i don't know how many item has the file. In the example are 4, but may be even 500

2) Click on checkbox "Select/Unselect All" and make it working, so if is selected, all are selected and viceversa

Thanks to all ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have resolved for the Select/Unselect all

Case $item[1]
For $i = 2 To $item[0]
If BitAND(GUICtrlRead($item[1], 1), $GUI_CHECKED) Then
     GUICtrlSetState($item[$i], $GUI_CHECKED)
Else
     GUICtrlSetState($item[$i], $GUI_UNCHECKED)
EndIf
Next

But sometime seems not work...if you click fast.

And this part not work:

If BitAND(GUICtrlRead($item[$i], 1), $GUI_CHECKED) Then
     FileDelete(@WorkingDir & "Test.txt")
     FileWrite(@WorkingDir & "Test.txt", StringTrimRight(GUICtrlRead($item[$i]), 1))
     ShellExecute(@WorkingDir & "Test.txt")
;~   MsgBox(0, 0, GUICtrlRead($item[$i]), 2)
EndIf

And i need also only to know how read an unknow number of line from a txt...

Please some advice/example

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Not work:

Case $button
For $i = 1 To $item[0]
     If _GUICtrlListView_GetItemChecked($listview, $i-1) Then
         FileDelete(@WorkingDir & "Test.txt")
         FileWrite(@WorkingDir & "Test.txt", StringTrimRight(GUICtrlRead($item[$i]), 1))
     EndIf
Next
ShellExecute(@WorkingDir & "Test.txt")

The .txt has only one element also if if select more, so if i select one work, but two or more not...

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

This works for me...

Also for me, but when i write on a file i have only one value. I need to use FileWrite?

For $i = 1 To $item[0]
     If _GUICtrlListView_GetItemChecked($listview, $i - 1) Then
         FileDelete(@WorkingDir & "Test.txt")
         FileWrite(@WorkingDir & "Test.txt", _GUICtrlListView_GetItemText($listview, $i - 1) & @CRLF)
     EndIf
Next
ShellExecute(@WorkingDir & "Test.txt")
Edited by johnmcloud

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Thanks Zedna, update:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $item[6] = [5]

GUICreate("Example", 216, 201, -1, -1, -1, $WS_EX_ACCEPTFILES)
$iListView = GUICtrlCreateListView("Name1", 10, 10, 192, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 185)
$hListView = GUICtrlGetHandle($iListView)
$item[1] = GUICtrlCreateListViewItem("Select/Unselect All", $iListView)
$item[2] = GUICtrlCreateListViewItem("Word1", $iListView)
$item[3] = GUICtrlCreateListViewItem("Word2", $iListView)
$item[4] = GUICtrlCreateListViewItem("Word3", $iListView)
$item[5] = GUICtrlCreateListViewItem("Word4", $iListView)
$button = GUICtrlCreateButton("Save", 11, 162, 186, 20)
GUISetState(@SW_SHOW)

For $i = 1 To $item[0]
GUICtrlSetState($item[$i], $GUI_CHECKED)
Next

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button
FileOpen(@WorkingDir & "Test.txt", 2)
For $i = 2 To $item[0]
    If _GUICtrlListView_GetItemChecked($iListView, $i - 1) Then
     FileWrite(@WorkingDir & "Test.txt", _GUICtrlListView_GetItemText($iListView, $i - 1) & @CRLF)
    EndIf
Next
If _GUICtrlListView_AllUnChecked($hListView) = True Then
    MsgBox(0, 0, "No element(s) selected")
Else
    ShellExecute(@WorkingDir & "Test.txt")
EndIf
Case $item[1]
For $i = 2 To $item[0]
    If BitAND(GUICtrlRead($item[1], 1), $GUI_CHECKED) Then
     GUICtrlSetState($item[$i], $GUI_CHECKED)
    Else
     GUICtrlSetState($item[$i], $GUI_UNCHECKED)
    EndIf
Next
EndSwitch
WEnd

Func _GUICtrlListView_AllUnChecked($hListView)
Local $iChecked = 0, $iCount = _GUICtrlListView_GetItemCount($hListView)
For $i = 0 To $iCount - 1
If Not _GUICtrlListView_GetItemChecked($hListView, $i) Then
$iChecked += 1
EndIf
Next
Return $iChecked = $iCount ; Returns True - all items are unchecked or False - some are unchecked.
EndFunc ;==>_GUICtrlListView_AllUnChecked

Problems:

1) The Func _GUICtrlListView_AllUnChecked read also the first line ( select/unselect all ), how to remove from the _GUICtrlListView_GetItemCount ?

2) Read the ListView information from a txt, without know the number of the item

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

New update:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $SelectAll[1]

GUICreate("Example", 216, 201, -1, -1, -1, $WS_EX_ACCEPTFILES)
$iListView = GUICtrlCreateListView("Name1", 10, 10, 192, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 185)
$hListView = GUICtrlGetHandle($iListView)
$SelectAll[0] = GUICtrlCreateListViewItem("Select/Unselect All", $iListView)
$Button = GUICtrlCreateButton("Save", 11, 162, 186, 20)
GUISetState(@SW_SHOW)

File_Create()
Load_Value()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button
FileOpen(@WorkingDir & "Test.txt", 2)
For $i = 2 To $SelectAll[0]
    If _GUICtrlListView_GetItemChecked($iListView, $i - 1) Then
     FileWrite(@WorkingDir & "Test.txt", _GUICtrlListView_GetItemText($iListView, $i - 1) & @CRLF)
    EndIf
Next
If _GUICtrlListView_AllUnChecked($hListView) = True Then
    MsgBox(0, 0, "No element(s) selected")
Else
    ShellExecute(@WorkingDir & "Test.txt")
EndIf
EndSwitch
WEnd

Func File_Create()
$Test = FileOpen(@WorkingDir & "Test.txt", 2)
FileWrite($Test, "Value11" & @LF & "Value22" & @LF & "Value33" & @LF & "Value44")
EndFunc

Func _GUICtrlListView_AllUnChecked($hListView)
Local $iChecked = 1, $iCount = _GUICtrlListView_GetItemCount($hListView)
For $i = 0 To $iCount - 1
If Not _GUICtrlListView_GetItemChecked($hListView, $i) Then
$iChecked += 1
EndIf
Next
Return $iChecked = $iCount ; Returns True - all items are unchecked or False - some are unchecked.
EndFunc ;==>_GUICtrlListView_AllUnChecked

Func Load_Value()
$File = FileRead(@WorkingDir & "Test.txt")
$array = StringSplit($File, @LF)
For $i = 1 To $array[0] - 1
GUICtrlCreateListViewItem(StringTrimRight($array[$i], 1), $iListView)
Next
EndFunc ;==>Load_Value

Now the script load the information from a txt ( remove last line and last letter of every line, but i need it )

I need to add only a working checkbox "Select/Unselect All"

Please :D

Edited by johnmcloud

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I think i'm not understand :(

I have not figured out how to apply it to my situation. I have no variables, I have only one value ($SelectAll), the others are generated from the contents of the file

So i want to click on "Select/Unselect All" checkbox, if checked the other are checked and viceversa.

The script, with the new button for load the value and one for save:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $SelectAll[1]
 
$_1 = GUICreate("Example", 217, 202, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$iListView = GUICtrlCreateListView("Name1", 10, 10, 192, 150, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 180)
$hListView = GUICtrlGetHandle($iListView)
$ButtonSave = GUICtrlCreateButton("Save", 107, 164, 92, 20)
$ButtonLoad = GUICtrlCreateButton("Load", 19, 166, 84, 20)
GUISetState(@SW_SHOW)

File_Create()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ButtonLoad
   $SelectAll[0] = GUICtrlCreateListViewItem("Select/Unselect All", $iListView)
   Load_Value()
  Case $ButtonSave
   FileOpen(@WorkingDir & "Test.txt", 2)
   For $i = 2 To $SelectAll[0]
    If _GUICtrlListView_GetItemChecked($iListView, $i - 1) Then
     FileWrite(@WorkingDir & "Test.txt", _GUICtrlListView_GetItemText($iListView, $i - 1) & @CRLF)
    EndIf
   Next
   If _GUICtrlListView_AllUnChecked($hListView) = True Then
    MsgBox(0, 0, "No element(s) selected")
   Else
    ShellExecute(@WorkingDir & "Test.txt")
   EndIf
EndSwitch
WEnd

Func File_Create()
$Test = FileOpen(@WorkingDir & "Test.txt", 2)
FileWrite($Test, "Value11" & @LF & "Value22" & @LF & "Value33" & @LF & "Value44")
EndFunc   ;==>File_Create

Func _GUICtrlListView_AllUnChecked($hListView)
Local $iChecked = 1, $iCount = _GUICtrlListView_GetItemCount($hListView)
For $i = 0 To $iCount - 1
  If Not _GUICtrlListView_GetItemChecked($hListView, $i) Then
   $iChecked += 1
  EndIf
Next
Return $iChecked = $iCount ; Returns True - all items are unchecked or False - some are unchecked.
EndFunc   ;==>_GUICtrlListView_AllUnChecked

Func Load_Value()
$File = FileRead(@WorkingDir & "Test.txt")
$array = StringSplit($File, @LF)
For $i = 1 To $array[0] - 1
  GUICtrlCreateListViewItem(StringTrimRight($array[$i], 1), $iListView)
Next
EndFunc   ;==>Load_Value
Edited by johnmcloud

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I think i have a solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>
#include <GuiListView.au3>

Dim $SelectAll[1]

$_1 = GUICreate("Example", 217, 202, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$iListView = GUICtrlCreateListView("Name1", 10, 10, 192, 150, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 180)
$hListView = GUICtrlGetHandle($iListView)
$ButtonSave = GUICtrlCreateButton("Save", 107, 164, 92, 20)
$ButtonLoad = GUICtrlCreateButton("Load", 19, 166, 84, 20)
GUISetState(@SW_SHOW)

File_Create()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $ButtonLoad
$SelectAll[0] = GUICtrlCreateListViewItem("Select/Unselect All", $iListView)
Load_Value()
Case $ButtonSave
FileOpen(@WorkingDir & "Test.txt", 2)
For $i = 2 To $SelectAll[0]
    If _GUICtrlListView_GetItemChecked($iListView, $i - 1) Then
     FileWrite(@WorkingDir & "Test.txt", _GUICtrlListView_GetItemText($iListView, $i - 1) & @CRLF)
    EndIf
Next
If _GUICtrlListView_AllUnChecked($hListView) = True Then
    MsgBox(0, 0, "No element(s) selected")
Else
    ShellExecute(@WorkingDir & "Test.txt")
EndIf
Case $SelectAll[0]
If _GUICtrlListView_GetItemChecked($iListView, $SelectAll) Then
_GUICtrlListView_SetItemChecked($iListView, $SelectAll[0], 1)
_GUICtrlListView_SetCheckedStates($hListView, 1)
EndIf
If Not _GUICtrlListView_GetItemChecked($iListView, $SelectAll) Then
_GUICtrlListView_SetItemChecked($iListView, $SelectAll, 2)
_GUICtrlListView_SetCheckedStates($hListView, 2)
EndIf
EndSwitch
WEnd

Func File_Create()
$Test = FileOpen(@WorkingDir & "Test.txt", 2)
FileWrite($Test, "Value11" & @LF & "Value22" & @LF & "Value33" & @LF & "Value44")
EndFunc ;==>File_Create

Func _GUICtrlListView_AllUnChecked($hListView)
Local $iChecked = 1, $iCount = _GUICtrlListView_GetItemCount($hListView)
For $i = 0 To $iCount - 1
If Not _GUICtrlListView_GetItemChecked($hListView, $i) Then
$iChecked += 1
EndIf
Next
Return $iChecked = $iCount ; Returns True - all items are unchecked or False - some are unchecked.
EndFunc ;==>_GUICtrlListView_AllUnChecked

Func Load_Value()
$File = FileRead(@WorkingDir & "Test.txt")
$array = StringSplit($File, @LF)
For $i = 1 To $array[0] - 1
GUICtrlCreateListViewItem(StringTrimRight($array[$i], 1), $iListView)
Next
EndFunc ;==>Load_Value

Func _GUICtrlListView_SetCheckedStates($hListView, $iType) ; By Zedna, Modified by guinness.
Local $fState = False, $iCount = _GUICtrlListView_GetItemCount($hListView)
If $iType < 0 Or $iType > 2 Then
Return SetError(1, 0, 0)
EndIf
If $iType Then
$fState = True
EndIf
For $i = 0 To $iCount - 1
If $iType = 2 Then
$fState = Not _GUICtrlListView_GetItemChecked($hListView, $i) ; Invert checked state with $iType 2.
EndIf
_GUICtrlListView_SetItemChecked($hListView, $i, $fState)
Next
EndFunc ;==>_GUICtrlListView_SetCheckedStates

There is only a problem, if you click fast on checkbox "select/unselect all" sometimes lose the function. Someone what to test for search a workaround?

Thanks

Edited by johnmcloud

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Jcreator
      this script keeps having contradicting loop
      By Jcreator
      i used this code to take names for a text file called data and put the info of the image and it location from the data file into the gui interface but it only detect the lines with the info and it do not show the images . here is the code 
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> #include <GuiComboBox.au3> #include <GuiTab.au3> #include <file.au3> #include <array.au3> _Main() Func _Main() Local $idTab1 $Form1 = GUICreate("Form1", 500, 334, 240, 182) $Group1 = GUICtrlCreateGroup("Group1", 20, 12, 249, 314) $idButton6 = GUICtrlCreateButton("Info", 50, 270, 185, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Global $fileMPA = "C:\T-in\MPA\data.txt" FileOpen($fileMPA, 0)    Global $line1 = FileReadLine($fileMPA , 1) $imp = 0 $idTab1 = GUICtrlCreateTab(300, -3, 180, 330) GUICtrlCreateTabItem("imglist1") GUICtrlSetTip(-1, '#Region TAB1') GUICtrlSetTip(-1, '#Region LIST') Local $imglist1 = GUICtrlCreateList("", 307, 26, 164, 304) $cline =_FileCountLines($fileMPA)  While  $imp < $cline $line2 = FileReadLine($fileMPA , $imp + 2)  $imp = $imp + 7 if $line2 = ""  then     ExitLoop    else  GUICtrlSetData(-1, ""& $line2 &"", "")  endif WEnd GUICtrlCreateTabItem("imagelist2") GUICtrlSetTip(-1, '#Region TAB2') GUICtrlCreateTabItem("imagelist3") GUICtrlSetTip(-1, '#Region TAB3') While 1     $Msg = GUIGetMsg()     Select         Case $Msg = $GUI_EVENT_CLOSE             Exit             Global $whatnow = GUICtrlRead($imglist1) Case $Msg = $idButton6             $imp2 = 0              While  $imp2 < 30 $line2 = FileReadLine($fileMPA ,$imp2 + 2) $line3 = FileReadLine($fileMPA , $imp2 + 3) $line7 = FileReadLine($fileMPA , 7)  $imp2 = $imp2 + 7 if $line2 = ""  then  ExitLoop             If GUICtrlRead($imglist1) = ""& $line2 &""  Then MsgBox($MB_SYSTEMMODAL, "img info" , $line3)                WEnd             EndSelect $imp2 = 0              While  $imp2 < 30 $line2 = FileReadLine($fileMPA ,$imp2 + 2) $line3 = FileReadLine($fileMPA , $imp2 + 3) $line7 = FileReadLine($fileMPA , 7)  $imp2 = $imp2 + 7     Select Case GUICtrlRead($imglist1) = ""& $line2 &"" if $line2 = "" then ExitLoop     $Pic1 = GUICtrlCreatePic(""& $line7 &"", 185, 28, 233, 230) If GUICtrlRead($imglist1) then  ExitLoop EndSelect WEnd     WEnd  EndFunc   ;==>_Main the data.txt file content is 
      Hibiscus Hibiscus is a hardy perennial which grows in variety of colors, sizes and fragrances. Actually they are tropical flowers which require ample sunlight and moisture to grow well. These flowers start blooming in late spring and continuously bloom through July and August. C:\T-in\IMG\2.jpg Lilies There are different types of lily flowers which bloom in August including water lilies, tiger lilies and gold band lilies. Tiger lilies generate orange flowers having black spots. This lily blooms in delayed July and beginning of August. Gold band lily produce exotic white blooms. All varieties of lilies need enough space to grow and protection from summer sun. C:\T-in\IMG\1.jpg Turtlehead Growing in humid areas, turtleheads are small flowers which bloom from July to September. They mostly produce flowers of white and pink color. C:\T-in\IMG\3.jpg Hydrangea These are ever green bushes which produce flowers in different colors including white, purple, blue and pink. They are easy to grow bushes and can grow 3 to 10 feet tall. They require morning sun to grow but they should be protected from noon and afternoon sun. C:\T-in\IMG\4.jpg Dahlias August proves to be the peak blooming season for dahlias. Dahlias come in colors like white, orange, yellow, red and purple. They can tolerate all types of soil and require full sun to grow.
    • Jcreator
      i used while to display images but it went wrong
      By Jcreator
      i used this code to take names for a text file called data and put the info of the image and it location from the data file into the gui interface but it only detect the lines with the info and it do not show the images . here is the code 
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <AVIConstants.au3> #include <TreeViewConstants.au3> #include <GuiComboBox.au3> #include <GuiTab.au3> #include <file.au3> #include <array.au3> _Main() Func _Main() Local $idTab1 $Form1 = GUICreate("Form1", 500, 334, 240, 182) $Group1 = GUICtrlCreateGroup("Group1", 20, 12, 249, 314) $idButton6 = GUICtrlCreateButton("Info", 50, 270, 185, 49) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Global $fileMPA = "C:\T-in\MPA\data.txt" FileOpen($fileMPA, 0) Global $line1 = FileReadLine($fileMPA , 1) $imp = 0 $idTab1 = GUICtrlCreateTab(300, -3, 180, 330) GUICtrlCreateTabItem("imglist1") GUICtrlSetTip(-1, '#Region TAB1') GUICtrlSetTip(-1, '#Region LIST') Local $imglist1 = GUICtrlCreateList("", 307, 26, 164, 304) $cline =_FileCountLines($fileMPA) While $imp < $cline $line2 = FileReadLine($fileMPA , $imp + 2) $imp = $imp + 7 if $line2 = "" then ExitLoop else GUICtrlSetData(-1, ""& $line2 &"", "") endif WEnd GUICtrlCreateTabItem("imagelist2") GUICtrlSetTip(-1, '#Region TAB2') GUICtrlCreateTabItem("imagelist3") GUICtrlSetTip(-1, '#Region TAB3') While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Global $whatnow = GUICtrlRead($imglist1) Case $Msg = $idButton6 $imp2 = 0 While $imp2 < 30 $line2 = FileReadLine($fileMPA ,$imp2 + 2) $line3 = FileReadLine($fileMPA , $imp2 + 3) $line7 = FileReadLine($fileMPA , 7) $imp2 = $imp2 + 7 if $line2 = "" then ExitLoop If GUICtrlRead($imglist1) = ""& $line2 &"" Then MsgBox($MB_SYSTEMMODAL, "img info" , $line3) WEnd EndSelect $imp2 = 0 While $imp2 < 30 $line2 = FileReadLine($fileMPA ,$imp2 + 2) $line3 = FileReadLine($fileMPA , $imp2 + 3) $line7 = FileReadLine($fileMPA , 7) $imp2 = $imp2 + 7 Select Case GUICtrlRead($imglist1) = ""& $line2 &"" if $line2 = "" then ExitLoop $Pic1 = GUICtrlCreatePic(""& $line7 &"", 185, 28, 233, 230) If GUICtrlRead($imglist1) then ExitLoop EndSelect WEnd WEnd EndFunc ;==>_Main i wish some one can help me fix this without having to choose the images manually and i know that the script is messy but am still new in the world of autoit some bear with me . thanks for your time
    • Jefrey
      Buffer/stack with Arrays (limiting array size) UDF
      By Jefrey
      At my work I was creating a music player (truly the project is bigger than it but it doesn't come to the case right now) and, given some conditions, it should start playing songs randomly. I've used Random() function to sort any song from the list, but the "random wasn't so random" sometimes, and some songs used to repeat multiple times, although the song list wasn't so small. So I needed to keep a list of all the played songs. However, I couldn't feed up an array forever as this system I'm working on is meant to work 24/7 with no pause and the array could really reach huge values, while just the latest X values would really be used (to check if a random song was played recently before playing it).
      So I managed to create this simple stack/buffer/heap script. It works just like Assembly stacks (although the target is totally different). You'll have an array, you can define its max size and start adding items into it. Once the array limit is reached, the first added item is automatically removed, all the other items are reindexed and your new item will then be added.
      You can also change the array (stack) limit at any time, reset it as well as pull/remove or read the last added item. In the best Assembly stack way, you shouldn't be able to read all the items, except the last added item. But, well, we are talking about AutoIt arrays. It's just a list, where the 0 index brings the actual items count. This means you can easily create loops and read the array as you want (just be very careful if you want to modify the array without _Buffer* functions).
      It's also useful if you want to generate random values with Random() with repeating values, but they're repeating more than you want (instead of "1-2-2-2-3-1-2-3-4" you would have "1-3-2-4-3-1-2-4" - the values would only start repeating after it's too long since they were generated in last).
      Here's an example:
      #inclcude 'buffer.au3' ; the lib #include <Array.au3> ; needed only to do _ArrayDisplay ; Example 1 $aBuffer = _BufferCreate(3) _BufferPush($aBuffer, 12) _BufferPush($aBuffer, 23) _BufferPush($aBuffer, 34) _BufferPush($aBuffer, 45) MsgBox(0, '', _BufferPull($aBuffer)) ; 45 (and remove it) _BufferPush($aBuffer, 56) _BufferPush($aBuffer, 67) _ArrayDisplay($aBuffer) ; Example 2 $aBuffer = _BufferCreate(3) _BufferPush($aBuffer, 12) _BufferPush($aBuffer, 23) _BufferPush($aBuffer, 34) _BufferPush($aBuffer, 45) _BufferChangeLimit($aBuffer, 6) _BufferPush($aBuffer, 56) _BufferPush($aBuffer, 67) _ArrayDisplay($aBuffer) MsgBox(0, "", "Buffer items count: " & _BufferItemsCount($aBuffer) & @CRLF & "Buffer max size: " & _BufferLimit($aBuffer) & @CRLF & "Last item (without pulling/removing it): " & _BufferGetLastItem($aBuffer)) ; Example 3 $aBuffer = _BufferCreate(3) _BufferPush($aBuffer, 'ab') _BufferPush($aBuffer, 'cd') _BufferPush($aBuffer, 'ef') _BufferPush($aBuffer, 'gh') _ArrayDisplay($aBuffer) _BufferReset($aBuffer) _ArrayDisplay($aBuffer) ; Example 4 $aBuffer = _BufferCreate(2) _BufferPush($aBuffer, 'Song 1') _BufferPush($aBuffer, 'Music 2') _BufferPush($aBuffer, 'Hit 3') If _BufferCheckValue($aBuffer, 'Song 1') Then ; False MsgBox(0, "", "Song 1 was played too recently.") EndIf If _BufferCheckValue($aBuffer, 'Music 2') Then ; True MsgBox(0, "", "Music 2 was played too recently.") EndIf The lib source code:
      #include-once #cs Buffer/stack/heap UDF made by Jefrey <jefrey[at]jefrey.ml> Licensed under WTFPL: http://www.wtfpl.net/txt/copying/ #ce ; Creates a new buffer ; Arguments: $iSize - size of the buffer (limit) Func _BufferCreate($iSize) Local $aBuffer[$iSize+1] $aBuffer[0] = 0 Return $aBuffer EndFunc ; Adds an item to the buffer ; If the buffer limit was reached, then the first item will be removed. ; Arguments: $aBuffer - buffer to change (reference) / $mItem - item to add Func _BufferPush(ByRef $aBuffer, $mItem) If $aBuffer[0]+1 > UBound($aBuffer)-1 Then ; remove first item and reindex $aBuffer[1] = Null For $i = 2 To $aBuffer[0] $aBuffer[$i - 1] = $aBuffer[$i] Next Else $aBuffer[0] += 1 EndIf $aBuffer[$aBuffer[0]] = $mItem Return $aBuffer EndFunc ; Removes the last added item of the buffer and returns its value ; Arguments: $aBuffer - buffer to change (reference) Func _BufferPull(ByRef $aBuffer) If $aBuffer[0] = 0 Then Return $mReturn = $aBuffer[$aBuffer[0]] $aBuffer[$aBuffer[0]] = Null $aBuffer[0] -= 1 Return $mReturn EndFunc ; Returns the actual items count (how many items were added to the buffer, and not its limit) ; Arguments: $aBuffer - the buffer Func _BufferItemsCount($aBuffer) Return $aBuffer[0] EndFunc ; Returns the actual items count (how many items were added to the buffer, and not its limit) ; Arguments: $aBuffer - the buffer Func _BufferGetLastItem($aBuffer) Return $aBuffer[$aBuffer[0]] EndFunc ; Returns the buffer limits (that were set by you) ; Arguments: $aBuffer - the buffer Func _BufferLimit($aBuffer) Return UBound($aBuffer)-1 EndFunc ; Changes a buffer limit ; Arguments: $aBuffer - the buffer to change / $iSize - new buffer size Func _BufferChangeLimit(ByRef $aBuffer, $iSize) ReDim $aBuffer[$iSize + 1] Return $aBuffer EndFunc ; Resets a buffer (removes all items) ; Arguments: $aBuffer - the buffer to change Func _BufferReset(ByRef $aBuffer) Local $j = UBound($aBuffer)-1 For $i = 1 To $j $aBuffer[$i] = Null Next $aBuffer[0] = 0 EndFunc ; Checks if a value exists in a buffer ; Returns: 0 if not found or index (>0) of where it was found Func _BufferCheckValue($aBuffer, $mValue) If Not $aBuffer[0] Then Return 0 For $i = 1 To $aBuffer[0] If $aBuffer[$i] = $mValue Then Return $i Next Return 0 EndFunc  
    • Cirusnb
      Set Checked / un-checked value according to Registry value
      By Cirusnb
      Hi all, first post here ever, I'm working on a project, Helpdesk type tool.   I'm trying to set the State (Checked, Unchecked) of check boxes, and Or button, (a Toggle). this would be set by determining the Value of Certain Reg keys,    here is my phone below. $PC_select_data is the Computer Name so you could replace it with "@Computer".  
      I looked and looked and couldn't find whats wrong. 
      I'm new to Autoit somewhat. 
      I may be complicating things by assigning Arrays for my controls, but I think this will work. 
      the first part is fine, I get a Computer from a list (that I got from AD with Water's Awesome UDF)
      please not I'm using onevent also, well. the UDF OnEventA that allows upto 4 ByVal or Ref's 
      I get the Value $PC_selected_data
      return the value to the Function
       I send a test Key with Regread, if I can't read it I launch sc.exe to run Remote Reg.
      Then I read 5 values from the Remote Reg.   I assigned a Array of those Values and Also Assigned a Array of my CheckBoxes also.
      Now my logic, if the Value of the REG key is "" (blank)   then UnCheck all the check boxes, else, Check them. Now, to make this more efficient, I put the Controls in an Array, of the Same Lenth. now here is the think, I run my script, it runs fine, finds the value, and Un-checks all of the check boxes, now if I go change one of the REG values, it does not Check them. because of the Logic for the For Loop.   I would have figured that If the first value of the Array $Run_as_MSIscheck =  somevalue that it would see that as a "ELSE" and Check the box. Since the For loop contains the If - then- Else, but I Understand that it only runs the first Block, IF the condition is True.  So I guess Am I totally off track? 
       
      Func Check_PC_status($PC_select_Data) local $pingPC local $regtemp = "" local $x = "" local $Run_as_MSIcheck,$Run_as_CMDcheck,$Run_as_BATCheck,$Run_as_REGcheck local $RUNas_chks[4] = [$MSI_runAs_chk,$CMD_runAs_chk,$BAT_runAs_chk,$REG_runAs_chk] local $runAS_function_check[4] = [$Run_as_MSIcheck,$Run_as_CMDcheck,$Run_as_BATCheck,$Run_as_REGcheck] ;~ @error: ;~ 1 = Host is offline ;~ 2 = Host is unreachable ;~ 3 = Bad destination ;~ 4 = Other errors ;Sends Ping to pc to see if its live or not. $pingPC = ping($PC_select_Data,2000) ;if Ping has returned a good value, NOT 0. check current status of the following lines in registry. checkes for RunAS for CMD/MSI/BAT and Remote REG keys. checks for SMS prompt control. if $pingPC Then ;tries to read a key from the registry, and returns its value, if its blank, $regtemp = RegRead("\\" & $PC_select_Data & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required") ConsoleWrite("Sending test Key, is set to: " & $regtemp & @CRLF) ;~error: 3 = Bad destination if @error = 3 or $regtemp = "" Then ConsoleWrite("Unable to determine status of remote registry!!!" & @CRLF & "Trying to start Remote Registry.... via Service Control Manager" & @CRLF ) RunWait(@SystemDir & '\sc.exe \\' & $PC_select_Data & ' start RemoteRegistry',"","") if Not @error then ConsoleWrite("Remote Registry loaded" & @CRLF & @CRLF) EndIf EndIf TCPStartup() $IPadd = TCPNameToIP ($PC_select_Data) ConsoleWrite($IPadd & @CRLF) TCPShutdown() ConsoleWrite("ping Success: " & $pingPC & "ms" & @CRLF) $Sccm_PROMPTcheck = RegRead("\\" & $PC_select_Data & "\HKLM\SOFTWARE\Microsoft\SMS\Client\Client Components\Remote Control", "Permission Required") $Run_as_MSIcheck = RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\Msi.Package\shell\runas\command", "") ; MSI access Check $Run_as_CMDcheck = RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\cmdfile\shell\runas\command", "") ; CMS access Check $Run_as_BATCheck = RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\batfile\shell\runas\command", "") ; BAT access Check $Run_as_REGcheck = RegRead("\\" & $PC_select_Data & "\HKEY_CLASSES_ROOT\regfile\shell\runas\command", "") ; REG access Check ConsoleWrite("SMS Client status: " & $Sccm_Promptcheck & @CRLF & "MSI RunAS Status: " & $Run_as_MSIcheck & @CRLF & "CMD RunAs Status: " & $Run_as_CMDcheck & @CRLF & "BAT RunAs Status: " & $Run_as_BATCheck & @CRLF & "REG RunAs Status: " & $Run_as_REGcheck & @CRLF & @CRLF) for $x = 0 to UBound($runAS_function_check) -1 ConsoleWrite("Count: " & $x & @CRLF) if $runAS_function_check[$x] = "" Then $test1 = guictrlread($RUNas_chks[$x]) ConsoleWrite("B4 " & $test1 & @CRLF) GUICtrlSetState($RUNas_chks[$x],$GUI_UNCHECKED) $test2 = guictrlread($RUNas_chks[$x]) ConsoleWrite("After " & $test2 & @CRLF) Else GUICtrlSetState($RUNas_chks[$x],$GUI_CHECKED) EndIf Next Else ConsoleWrite($PC_select_Data & " is Not reachable" & @CRLF & @CRLF) EndIf Endfunc any help is appreciated. 
    • Simpel
      [Workaround] List of HotKeySets
      By Simpel
      Hi,
       
      I have written a programm offering me a lot of hotkeys to work with windows. All in all there are 40 hotkeys defined now.
      Now I made a portable version of it. But in this there are a lot of hotkeys useless. So I had to change some things. But that's not my point.
      Because of all these many hotkeys I sometimes know I made a hotkey but what were the keys I have to press.
      So I want to make a little help GUI or html or whatever. Now I'm interested to automate my own list of hotkeys.
      How can I collect all my hotkeys and necessary keys for this in a list?
       
      Regard, Conrad