Jump to content

Case Not - Do That (In GUI)


Omga4000
 Share

Recommended Posts

Hey there :graduated:

So I've created a script that simply puts few files into folders.

In order to do that I needed to change the names of the folder, so I've created another little script.

Now in the GUI I'm going to have 2 buttons:

1) Change Folders Names

2) Move Files To Folders

I want to create a script that basicly means:

Case button 2 was pressed, and If button 1 wasn't pressed before, do *something I choose*

Now I know it is possible to create just 1 button and include "Change Folder Names" in it,

but I really want to learn how to create this sort of stuff.

Thank you ;)

Edited by Omga4000
Link to comment
Share on other sites

You should use a variable, then when the button1 is pressed, change the value of that variable, and when you press the button2 you should check the variable.

example

Global $Check = False

GUICreate("Test",120,90)
$Button1 = GUICtrlCreateButton("Button1", 10, 10, 100, 30)
$Button2 = GUICtrlCreateButton("Button2", 10, 50, 100, 30)
GUISetState()

While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case -3
            Exit
        Case $Button1
            $Check = True
            MsgBox(0, "Button1", "You have Pressed Button1." & @CRLF & "Now you can press Button2")
        Case $Button2
            If $Check Then MsgBox(0, "Button2", "You have pressed Button2")
    EndSwitch
WEnd

Another method will be disabling the second button.

example

#include <GuiConstantsEx.au3>

GUICreate("Test",120,90)
$Button1 = GUICtrlCreateButton("Button1", 10, 10, 100, 30)
$Button2 = GUICtrlCreateButton("Button2", 10, 50, 100, 30)
GuiCtrlSetState($Button2, $GUI_DISABLE)
GUISetState()

While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case -3
            Exit
        Case $Button1
            GuiCtrlSetState($Button2, $GUI_ENABLE)
            MsgBox(0, "Button1", "You have Pressed Button1." & @CRLF & "Now you can press Button2")
        Case $Button2
            MsgBox(0, "Button2", "You have pressed Button2")
    EndSwitch
WEnd
Link to comment
Share on other sites

Hi omga4000,

Case button 2 was pressed, and If button 1 wasn't pressed before, do *something I choose*

i got confused on the above line. could you clear me? you mean the Button 2 pressed and button 1 not pressed is the scenarion or Button 2 pressed and Button 1 have never pressed. which is the scenario you are looking for?

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Oh very nice... Thank you!

So this is my current code (It pretty much does nothing.. This is just the GUI right now..):

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 295, 161, 568, 145)
$Par_Files_Location_Input = GUICtrlCreateInput("", 8, 24, 185, 21)
$Par_Files_Location = GUICtrlCreateLabel("Par Files Location", 8, 8, 94, 17)
$Browse_Par_Files_Button = GUICtrlCreateButton("Browse..", 200, 22, 75, 25)
$Destination_Folder_Input = GUICtrlCreateInput("", 8, 80, 185, 21)
$Destination_Folder = GUICtrlCreateLabel("Destination Folder", 8, 64, 92, 17)
$Browse_Des_Folder_Button = GUICtrlCreateButton("Browse..", 200, 78, 75, 25)
$Start = GUICtrlCreateButton("Start!", 104, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
   Exit 0
  Case $nMsg = $Browse_Par_Files_Button
   $Par_Files_Open = FileSelectFolder("Open", "My Computer")
   GUICtrlSetData($Par_Files_Location_Input,$Par_Files_Open)
   $Par_Files_Text = GUICtrlRead($Par_Files_Location_Input, 1)
  Case $nMsg = $Browse_Des_Folder_Button
   $Des_Folder_Open = FileSelectFolder("Open", "My Computer")
   GUICtrlSetData($Destination_Folder_Input,$Des_Folder_Open)
   $Des_Folders_Text = GUICtrlRead($Destination_Folder_Input, 1)
  
  Case $nMsg = $Start
   $Par_Files_Text = GUICtrlRead($Par_Files_Location_Input, 1)
   If $Par_Files_Text = "" Then
    MsgBox(0, "Error!", "Please Select Par Files Location!")
   EndIf
   $Des_Folders_Text = GUICtrlRead($Destination_Folder_Input, 1)
   If $Des_Folders_Text = "" Then
    MsgBox(0, "Error!", "Please Select Destination Folder Location!")
   EndIf
EndSelect
WEnd

Please notice the "Case $nMsg = $Start" section.

As you can see, you are suppose to insert a fil folder location.

I told the program to see if the box is empty. If it is - throw an error.

Now I want to also add a script that checks if the location is correct.

Mistakes can be:

1) No such folder (If folder doesn't exist)

2) Wrong location code, such as:

C:\\\Program Filesfggsdfsdfs\

How do I check for that?

Thank you :graduated:

Hi omga4000,

i got confused on the above line. could you clear me? you mean the Button 2 pressed and button 1 not pressed is the scenarion or Button 2 pressed and Button 1 have never pressed. which is the scenario you are looking for?

Yha sorry about that ;)

To be more clear, I'll try to write this as a "code":

If button 2 was pressed Then

Check if button 1 was pressed before.

If button 1 was pressed Then

Continue Normally.

If button 1 wasn't pressed Then

Throw error message

Edited by Omga4000
Link to comment
Share on other sites

Here is the modified code of yours :graduated:

IS this what you are looking?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $But1 = False
$Form1 = GUICreate("Form1", 295, 161, 568, 145)
$Par_Files_Location_Input = GUICtrlCreateInput("", 8, 24, 185, 21)
$Par_Files_Location = GUICtrlCreateLabel("Par Files Location", 8, 8, 94, 17)
$Browse_Par_Files_Button = GUICtrlCreateButton("Browse..", 200, 22, 75, 25)
$Destination_Folder_Input = GUICtrlCreateInput("", 8, 80, 185, 21)
$Destination_Folder = GUICtrlCreateLabel("Destination Folder", 8, 64, 92, 17)
$Browse_Des_Folder_Button = GUICtrlCreateButton("Browse..", 200, 78, 75, 25)
$Start = GUICtrlCreateButton("Start!", 104, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
   Exit 0
  Case $nMsg = $Browse_Par_Files_Button
   $Par_Files_Open = FileSelectFolder("Open", "My Computer")
   GUICtrlSetData($Par_Files_Location_Input,$Par_Files_Open)
   $Par_Files_Text = GUICtrlRead($Par_Files_Location_Input, 1)
   $But1 = True
  Case $nMsg = $Browse_Des_Folder_Button
  If $But1 = True Then
  $Des_Folder_Open = FileSelectFolder("Open", "My Computer")
  GUICtrlSetData($Destination_Folder_Input,$Des_Folder_Open)
  $Des_Folders_Text = GUICtrlRead($Destination_Folder_Input, 1)
 Else
   MsgBox(16, "Error!", "Please Select Par Files Location!")
  EndIf

  Case $nMsg = $Start
   $Par_Files_Text = GUICtrlRead($Par_Files_Location_Input, 1)
   $Des_Folders_Text = GUICtrlRead($Destination_Folder_Input, 1)
   If $Des_Folders_Text = "" And $Par_Files_Text = "" Then
    MsgBox(16, "Error!", "Please Select Par and Destination Folder Location!")
ElseIf $Des_Folders_Text = "" Then
  MsgBox(16, "Error!", "Please Select Destination Folder Location!")
 ElseIf $Par_Files_Text = "" Then
  MsgBox(16, "Error!", "Please Select Par Folder Location!")
 Else
  MsgBox(64, "Success!", "i will do my task here!")
   EndIf
EndSelect
WEnd
Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to comment
Share on other sites

Now I want to also add a script that checks if the location is correct.

Mistakes can be:

1) No such folder (If folder doesn't exist)

2) Wrong location code, such as:

C:\\\Program Filesfggsdfsdfs\

This is how i will do... :graduated:

$ret = FileSelectFolder("Open",@DesktopDir,4)
_Folder($ret)

Func _Folder($ret)
 Local $WrongLocation = "You have entered the wrong location"
 Local $NoFolder = "Folder does not exist"
 If $ret = "" Then
  MsgBox(0,"",$WrongLocation)
 ElseIf DriveStatus($ret) = "UNKNOWN" Then
  MsgBox(0,"",$NoFolder)
 Else
  MsgBox(0,"",$ret)
 EndIf
EndFunc

Note:

even if you close or canel you will endup with that message"you entered wrong location"...

any help ? ;)

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

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