Jump to content

Recommended Posts

Hello, I have a big problem, the code is looping and I don't know why?
and $ desc don't want to display the description, if someone can help me

$iniFile = "Config.ini"
    $array = IniReadSectionNames($iniFile)

    For $i = 1 To $array[0]
    $desc = IniRead($iniFile, $array[$i], "Desc", "")



            _GUICtrlListView_DeleteAllItems($ListView1)
            ; Is there anything in the input?
            $sText = GUICtrlRead($Input1)           ; search
            If StringLen($sText) <> 0 Then
                ; Create a list of matches
                Local $aMatch_List[1] = [0]
                $iStart = 1
                For $i = 0 To UBound($array) - 1
                    ; Look for the match
                    If StringInStr($array[$i], $sText) Then
                        ; Add to list
                        $aMatch_List[0] += 1
                        ReDim $aMatch_List[$aMatch_List[0] + 1]
                        $aMatch_List[$aMatch_List[0]] = $array[$i]&"|"&$desc[$i]     ;$ desc[$ i] don't want to work
                    EndIf
                Next
                ; Add matches to ListView
                For $i = 1 To $aMatch_List[0]
                    GUICtrlCreateListViewItem($aMatch_List[$i], $ListView1)
                Next
            Else
                ; Reload everything
                ContinueCase
            EndIf

    Next

 

Share this post


Link to post
Share on other sites

this is a piece of code that i get, i want to search in an ini is display the result listview1 $ desc but i can't do it? can someone help me? thank you

 

ini

[.NET Core Preview]
Switch=
Desc=Version d’aperçu du SDK .NET Core. 
Category=6

[0 A.D.]
Switch=
Desc=0 A.D. est un jeu gratuit, open-source, historique real time strategy (RTS) actuellement en cours de developpement par Wildfire Games, un groupe mondial de developpeurs de jeux benevoles. En tant que chef d une civilisation ancienne, vous devez rassembler les ressources dont vous avez besoin pour elever une force militaire et dominer vos ennemis. 
Category=1

 

Share this post


Link to post
Share on other sites

Just noticed you have multiple $i, each would have to be different because they're in the same loop, for example use $i, $j etc..., will put an example together for you shortly.

Share this post


Link to post
Share on other sites

Basic example:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
Global $g_idListView, $g_idSearch
Example()

Func Example()
    GUICreate("listview items", 220, 250)
    $g_idListView = GUICtrlCreateListView("Section Name|Description", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
    Local $idButton = GUICtrlCreateButton("Search", 75, 170, 70, 20)
    Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $g_idListView)
    Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $g_idListView)
    Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $g_idListView)
    $g_idSearch = GUICtrlCreateInput("", 20, 200, 150)
    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton
                _Search()
        EndSwitch
    WEnd
EndFunc

Func _Search()
    Local $sSearch = GUICtrlRead($g_idSearch)
    ;~ No Search text added, so return to Gui
    If StringStripWS($sSearch, 8) = "" Then Return
    Local $sConfig = @ScriptDir & "\Config.ini"
    Local $sDesc, $aSectionNames = IniReadSectionNames($sConfig)
        If @error Then Return
    ;~ Delete all items from the list view
    _GUICtrlListView_DeleteAllItems($g_idListView)
    For $i = 1 To $aSectionNames[0]
        If StringInStr($aSectionNames[$i], $sSearch) Then
            $sDesc = IniRead($sConfig, $aSectionNames[$i], "Desc", "")
            If StringStripWS($sDesc, 8) = "" Then ContinueLoop
            GUICtrlCreateListViewItem($aSectionNames[$i] & "|" & $sDesc, $g_idListView)
        EndIf
    Next
EndFunc

 

Share this post


Link to post
Share on other sites

Hi, i had a bit of free time, so i could fix your code to work:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 548, 437, 192, 124)
$ListView1 = GUICtrlCreateListView("Name   | Description", 15, 10, 255, 377)
$Input1 = GUICtrlCreateInput("net", 305, 12, 224, 21)
$Button1 = GUICtrlCreateButton("Button1", 309, 72, 55, 27)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


$iniFile = "Config.ini"

While 1
    $nMSG = GUIGetMsg()
    If $nMSG = $Button1 Then
        _GUICtrlListView_DeleteAllItems($ListView1)

        $array = IniReadSectionNames($iniFile)

            ; Is there anything in the input?
            $sText = GUICtrlRead($Input1)           ; search
            If StringLen($sText) <> 0 Then
                ; Create a list of matches
                Local $aMatch_List[1] = [0]
                $iStart = 1
                For $i = 1 To UBound($array) - 1
                    $desc = IniRead($iniFile, $array[$i], "Desc", "")
                    ; Look for the match
                    If StringInStr($array[$i], $sText) Then
                        ; Add to list
                        $aMatch_List[0] += 1
                        ReDim $aMatch_List[$aMatch_List[0] + 1]
                        $aMatch_List[$aMatch_List[0]] = $array[$i] & "|" & $desc ;$ desc[$ i] don't want to work because desc is not an array
                    EndIf
                Next
                ; Add matches to ListView
                _GUICtrlListView_BeginUpdate($ListView1)
                For $i = 1 To $aMatch_List[0]
                    GUICtrlCreateListViewItem($aMatch_List[$i], $ListView1)
                Next
                _GUICtrlListView_EndUpdate($ListView1)
            Else
                ; Reload everything
                ;ContinueCase
            EndIf
    EndIf
    If $nMSG = $GUI_EVENT_CLOSE Then Exit
WEnd

 


~Dan~ :Emu.Zone now with Desktop Pets / DeskMates - (Bugfixed UniScrMate 4.1)

Share this post


Link to post
Share on other sites

Thank you very much you help me greatly

Tell me, how to write in an input and send the request without button ok? it's possible ?

Share this post


Link to post
Share on other sites
2 hours ago, mickdu59 said:

Thank you very much you help me greatly

Tell me, how to write in an input and send the request without button ok? it's possible ?

 

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

$Form1 = GUICreate("Test", 349, 184, 192, 124)
$Input1 = GUICtrlCreateInput("", 40, 24, 161, 21)
$Label1 = GUICtrlCreateLabel("", 40, 70, 161, 21)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func WM_COMMAND($hWinHandle, $iMsg, $wParam, $lParam)
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $Input1 Then
        GUICtrlSetData($Label1, GUICtrlRead($Input1))
    EndIf
EndFunc

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...