Jump to content

GUI opens new GUI with search results, can't re use original GUI


Recommended Posts

Hey guys,

I've been trying to figure out what I'm doing wrong here... perhaps someone can shed some light on it for me? :)

The program works, and does exactly what I want it to, but when the initial program performs the search, and opens the second GUI, the first window is not usable, and I can't close it / run a new search with it.

I'd like to be able to close the second GUI that opens, without affecting the first GUI.

I'd also like to be able to run another search, and have multiple windows open.

Not sure If I'm doing this right, or if I'm completely off the right track!

Here's my code so far.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#include <array.au3>   
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

   ; read in the Excel file
   Global $sFilePath1 = @ScriptDir & "\Test.xls" ; directory of file
   Global $datasheet = _ExcelBookOpen($sFilePath1)

   ; Confirm if file exists
      Dim $test1
   
      $test1 = @error
      If @error = 1 Then
          MsgBox(0, "Error!", "Can't open excel object")
          _ExcelBookClose($datasheet)
          Exit
          
      ElseIf @error = 2 Then
          MsgBox(0, "Error!", "File not found")
          Exit
       EndIf
       ; End check

_Main()
Func _Main()

   Global $Input_partnumber, $Input_Description, $Stock_Quantity
   Global $Input_ReOrder, $Input_Location, $Input_Buy
   Global $Input_Sell, $Input_Orderfrom
   Global $sColumn = 1

   $aArray = _ExcelReadSheetToArray($datasheet) ;Reads excel data into the array

   ; input GUI
      $Form1 = GUICreate("Search window", 615, 438, 192, 124)
      $Button1 = GUICtrlCreateButton("Check", 8, 88, 75, 25)
      $Button2 = GUICtrlCreateButton("Exit", 88, 88, 75, 25)
      $Label1 = GUICtrlCreateLabel("Enter part number to search", 8, 8, 148, 33)
      $Input1 = GUICtrlCreateInput("", 8, 56, 153, 21)
      GUISetState(@SW_SHOW)

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

                 ;
              Case $Button1
                        $input = GUICtrlRead($Input1)
                        $iIndex = _ArraySearch($aArray, $input, "", "", "", "", 0, $sColumn)
                        
                        If @error Then
                            MsgBox(0, "Not Found", $input & " was not found")
                            _ExcelBookClose($datasheet)
                            Exit

                        Else
                           Local $partnumber = _ExcelReadCell($datasheet, $iIndex, 1)
                           Local $Description = _ExcelReadCell($datasheet, $iIndex, 2)
                           Local $Quantity = _ExcelReadCell($datasheet, $iIndex, 3)
                           Local $ReOrder = _ExcelReadCell($datasheet, $iIndex, 4)
                           Local $Location = _ExcelReadCell($datasheet, $iIndex, 5)
                           Local $Buy = _ExcelReadCell($datasheet, $iIndex, 6)
                           Local $Sell = _ExcelReadCell($datasheet, $iIndex, 7)
                           Local $Orderfrom = _ExcelReadCell($datasheet, $iIndex, 8)

                           ; GUI
                            GUICreate("Results", 400, 400, (@DesktopWidth - 300) / 2, (@DesktopHeight - 400) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS)
                            GUICtrlCreateLabel("Part Number", 10, 10, 150, 20)
                            GUICtrlCreateLabel("Description", 10, 40, 150, 20)
                            GUICtrlCreateLabel("Quantity", 10, 70, 150, 20)
                            GUICtrlCreateLabel("Re Order Level", 10, 100, 150, 20)
                            GUICtrlCreateLabel("Location", 10, 130, 150, 20)
                            GUICtrlCreateLabel("Buy Price", 10, 160, 150, 20)
                            GUICtrlCreateLabel("Sell Price", 10, 190, 150, 20)
                            GUICtrlCreateLabel("Order from", 10, 220, 150, 20)

                            $Input_partnumber = GUICtrlCreateLabel("" & $partnumber, 180, 10, 280, 20)
                            $Input_Description = GUICtrlCreateLabel("" & $Description, 180, 40, 280, 20)
                            $Stock_Quantity = GUICtrlCreateLabel("" & $Quantity, 180, 70, 280, 20)
                            $Input_ReOrder = GUICtrlCreateLabel("" & $ReOrder, 180, 100, 280, 20)
                            $Input_Location = GUICtrlCreateLabel("" & $Location, 180, 130, 280, 20)
                            $Input_Buy = GUICtrlCreateLabel("" & $Buy, 180, 160, 280, 20)
                            $Input_Sell = GUICtrlCreateLabel("" & $Sell, 180, 190, 280, 20)
                            $Input_Orderfrom = GUICtrlCreateLabel("" & $Orderfrom, 180, 220, 280, 20)
                            EndIf

                            GUISetState()
                               While 1
                                   $msg = GUIGetMsg()
                                   Select
                                       Case $msg = $GUI_EVENT_CLOSE
                                           ExitLoop
                                        Case Else
                                           _ExcelBookClose($datasheet)
                                   EndSelect
                               WEnd
                         Exit
              Case $Button2
                 _ExcelBookClose($datasheet)
                 Exit
          EndSwitch
      WEnd

EndFunc   ;==>_Main
Link to comment
Share on other sites

The wiki has a great tutorial about how to write multi GUI scripts.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If you're going to use 2 GUI's I'd suggest losing the second While loop because it's going to block everything in the first GUI until you close the 2nd GUI. Then you should be using GUIGetMsg(1) to return an array with more information, which is important because it will tell you which GUI it is getting the messages from and you can act on that information to make it so both GUIs are still able to be controlled.

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

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...