Sign in to follow this  
Followers 0
Jcreator

array vs loop is this possible

5 posts in this topic

i have a file flower.txt with the name of the flowers and there picture location and information about that kind of flower. i wana cerat a gui that will display the flower picture and it information 

here is the script 

#include <Misc.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#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>

Global $sfPath = 'flowers.txt'
Global $aFlowers
_FileReadToArray($sfPath,$aFlowers,$FRTA_NOCOUNT,'|')
_ArrayColDelete($aFlowers,0) ;row 0 has no data so deleting

$Form1 = GUICreate("Search Flower Name",320, 480)
$input = GUICtrlCreateInput("", 60, 360, 209, 25)
$idss = GUICtrlCreateButton("Search", 130, 400, 73, 65)

GUISetState(@SW_SHOW)




Func Searchf()



Global $Fname = GUICtrlRead($input)


        For $iNo = 0 To UBound($aFlowers[0][0]) - 1 ;

           if $Fname = $aFlowers[$iNo][0] then

MsgBox($MB_SYSTEMMODAL, "","Flower nfo", ""& $aFlowers[$iNo][1] &"")

pic()

EndIf
        Next

EndFunc

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

            Exit
         Case $nMsg = $idss

        Searchf()

    EndSwitch
 WEnd

func pic()
   For $iNo = 0 To UBound($aFlowers[0][0]) - 1
   GUICtrlCreatePic($aFlowers[$iNo][2], 20, 30, 280, 280)
    Next
   EndFunc

here is the flower.txt file

|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.|C:\T-in\IMG\5.jpg

am still trying to learn about how the ubound work and the _filereadtoarray

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Array.au3>

Local $sPath = 'flowers.txt'
Local $hPath = FileOpen($sPath)
If $hPath = -1 Then Exit

Local $aFlowers = StringSplit(StringTrimLeft(FileRead($hPath), 1), "|", 2)
FileClose($hPath)

_ArrayDisplay($aFlowers)

For $x = 0 To UBound($aFlowers) - 1 Step 3
    MsgBox(0, "NAME", $aFlowers[$x])
Next
For $x = 1 To UBound($aFlowers) - 1 Step 3
    MsgBox(0, "DESCRIPTION", $aFlowers[$x])
Next
For $x = 2 To UBound($aFlowers) - 1 Step 3
    MsgBox(0, "IMAGE", $aFlowers[$x])
Next
For $x = 0 To UBound($aFlowers) - 1
    If $aFlowers[$x] = "Hibiscus" Then
        MsgBox(0, "NAME", $aFlowers[$x])
        MsgBox(0, "DESCRIPTION", $aFlowers[$x + 1])
        MsgBox(0, "IMAGE", $aFlowers[$x + 2])
        ExitLoop
    EndIf
Next

Study it, isn't so hard.

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

You were really close, keep up the good work!

 

All problems I have comments on. This should work. Let me know!

 

#include <Misc.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#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>

Global $sfPath = 'flowers.txt'
Global $aFlowers, $FlowerFound = 0 ; Added in a global variable that you can assign if when searching the flower is in the Flower.txt so you can alert the user no data was found.
_FileReadToArray($sfPath, $aFlowers, $FRTA_NOCOUNT, '|')
_ArrayColDelete($aFlowers, 0) ;row 0 has no data so deleting

$Form1 = GUICreate("Search Flower Name", 320, 480)
$input = GUICtrlCreateInput("", 60, 360, 209, 25)
$idss = GUICtrlCreateButton("Search", 130, 400, 73, 65)

GUISetState(@SW_SHOW)




Func Searchf()


    Global $Fname = GUICtrlRead($input)



    For $iNo = 0 To UBound($aFlowers) - 1 ; You do not add [0][0] to a Ubound since its searching the entire Array already it just requires the Array Name.


        If $Fname = $aFlowers[$iNo][0] Then

            MsgBox(0, "Flower Info", $aFlowers[$iNo][1]) ; Shortened this up for cleaner look IMO.
            $FlowerFound = 1 ; Assigned a 1 to the FlowerFound so you can detect if the flower is in the Flowers.txt

            pic()

        Else

        EndIf
    Next

    If $FlowerFound = 0 Then ; Error handling to let the user know the flower is not located in the Flower.txt
        MsgBox(48, "Error", "No flower found in database!")
    EndIf

    $FlowerFound = 0 ; Reassign FlowerFound to 0 so next search it can detect if its not found or found again

EndFunc   ;==>Searchf

Func pic()
    For $iNo = 0 To UBound($aFlowers) - 1 ; Same principle as above, only the Array Name is needed. 
        GUICtrlCreatePic($aFlowers[$iNo][2], 20, 30, 280, 280)
    Next
EndFunc   ;==>pic

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

            Exit
        Case $idss ; You just need the ID of the Control, not the GuiGetMsg info. You were close!

            Searchf()

    EndSwitch
WEnd

 


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I made some changes to @Damein script:

#include <Misc.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#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>

Global $sfPath = 'flowers.txt'
Global $idPic=-99               ;<== placeholder PicControlID
Global $aFlowers
; $FlowerFound = 0 ; Added in a global variable that you can assign if when searching the flower is in the Flower.txt so you can alert the user no data was found.
;<== moved in local scope
_FileReadToArray($sfPath, $aFlowers, $FRTA_NOCOUNT, '|')
_ArrayColDelete($aFlowers, 0) ;row 0 has no data so deleting

$Form1 = GUICreate("Search Flower Name", 320, 480)
$input = GUICtrlCreateInput("", 60, 360, 209, 25)
$idss = GUICtrlCreateButton("Search", 130, 400, 73, 65)

GUISetState(@SW_SHOW)

Func Searchf()
    Local $Fname = GUICtrlRead($input)  ;<== use local scope
    Local $FlowerFound                  ;<== 
    For $iNo = 0 To UBound($aFlowers) - 1 ; You do not add [0][0] to a Ubound since its searching the entire Array already it just requires the Array Name.

        If $Fname = $aFlowers[$iNo][0] Then
            MsgBox(0, "Flower Info", $aFlowers[$iNo][1]) ; Shortened this up for cleaner look IMO.
            $FlowerFound = 1 ; Assigned a 1 to the FlowerFound so you can detect if the flower is in the Flowers.txt
            pic($aFlowers[$iNo][2]) ;<== calling func with path from pic
            ExitLoop ;<== allready found so search is ended
            ;Else                       ;<==
        EndIf
    Next

    If $FlowerFound = 0 Then ; Error handling to let the user know the flower is not located in the Flower.txt
        MsgBox(48, "Error", "No flower found in database!")
    EndIf

    ;$FlowerFound = 0 ; ;<== no need in local scope
EndFunc   ;==>Searchf

Func pic($sPicPath)
    If $idPic<>-99 Then GUICtrlDelete($idPic)
    $idPic=GUICtrlCreatePic($sPicPath, 20, 30, 280, 280)
EndFunc   ;==>pic

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

            Exit
        Case $idss ; You just need the ID of the Control, not the GuiGetMsg info. You were close!

            Searchf()

    EndSwitch
WEnd

my added comments begin with ;<== and my changes are based on my thinking each flowername is only once in the file.

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@Terenz you saved my life . your script was so easy to experiment with  so i could know what i needed to do Thank you

and for @damien your explanation helped me know what are the mistake i had in my script

@AutoBert i cant thank you enough every time am in trouble i found you there for me without you i would have spend moths postponing this project i owe you so much i hope you have a wonderful day 

thanks everyone and here is a happy cat face

happy cat.jpg

Edited by Jcreator

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

    • 0Ethan0
      By 0Ethan0
      Ahoy Autoit Community!
      After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution 
      The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
      The Setup: GUI with a ListView Control and a simple exit button.
      The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
      The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
      The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
      The Code (stripped and simplified as much as I could):
      #include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global $c=0 Global $ssGDI[3], $ssGraphic[2], $ssImage Global Const $bg_color = "000000" Global Const $ssW = 480, $ssH = 320 Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH ) $guiW = 1200 $guiH = 726 $mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP) $Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent($Button1, "_Exit") $Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent($Button1, "Test") Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth ($ListView, 0, 100) _GUICtrlListView_SetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) screenshotWidgetInit($ssW,$ssH, 690, 100) GUISetState(@SW_SHOW, $mainWindow) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For $k = 1 To UBound($aFiles) - 1 screenshotWidgetTransition($aFiles[$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000) Local $a, $d = $c, $iX, $iY $ssImage = _GDIPlus_ImageLoadFromFile($image) $iX = _GDIPlus_ImageGetWidth($ssImage) $iY = _GDIPlus_ImageGetHeight($ssImage) $FDesktop=$ssH/$ssW $Fact =1 If $iX > $ssW And $FDesktop > ($iY/$iX) Then $Fact=$ssW/$iX ElseIf $iY > $ssH Then $Fact=$ssH/$iY EndIf $H1 = Round(($Fact * $iY),0) $W1 = Round(($Fact * $iX),0) _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1) WinSetTrans($ssGDI[$d], "", 0) WinSetOnTop($ssGDI[$d], "", 1) For $a = 0 To 254 Step $speed WinSetTrans($ssGDI[$d], "", $a) Sleep($delay) Next WinSetTrans($ssGDI[$d], "", 254) WinSetOnTop($ssGDI[Not ($d)], "", 0) WinSetTrans($ssGDI[Not ($d)], "", 0) _GDIPlus_GraphicsClear($ssGraphic[Not ($d)]) $c = 1 - $d _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics Sleep($sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY) $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow) $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) ; GUISetBkColor("0x" & $bg_color, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[0]) GUISetState(@SW_SHOW, $ssGDI[1]) WinSetTrans($ssGDI[0], "", 0) WinSetTrans($ssGDI[1], "", 0) _GDIPlus_Startup() $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0]) $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1]) _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color) _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose($ssImage) _GDIPlus_GraphicsDispose($ssGraphic[0]) _GDIPlus_GraphicsDispose($ssGraphic[1]) GUIDelete($ssGDI[0]) GUIDelete($ssGDI[1]) GUIDelete($ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?
      Thank you in advance!
      P.S.
      The script is patched from different scripts of different users in the forum - thank you again users!
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • mati
      By mati
      Hi,
      I wonder if
      AutoIt3Wrapper_run_debug_mode = Y can include run information about functions which are called within the main code. So far I noticed in the console that the function itself is called but no specific run information from  inside the function is provided. Is there a chance to show the entire debug log including functions in the console?
      I furthermore noticed a stop of information when a loop is entered. What could be the reason for that?
       
      Thanks for help.
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx