Jump to content

Switch button


TuMiM
 Share

Recommended Posts

I have a script that runs with one button to find the file you want to process and one that processes the file. The script basically just renames the file. Anyhow, I need to create a switch type of button that depending on which switch is set will name the file one way and if the button is switched the other way it names the file differently. Is there a way to create such a switch type of GUI button? I know I could probably do it with a check box but I'd rather a switch

Link to comment
Share on other sites

  • Moderators

TuMiM,

Use the $BS_PUSHLIKE style on a checkbox - it then looks like a button which up (unchecked) and down (checked). ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ok thanks I got that to work but that broke the rest of my script because now when i push the button it doesn't do anything. I assume it's because i am now using oneventmode but not sure how to fix this

#include <GUIConstants.au3>
#include<file.au3>
#include<array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
;OPT("GuiOnEventMode",1)
$Form1 = GUICreate("LST File Copy", 456, 290, 241, 160)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$FileIn = GUICtrlCreateInput("", 128, 88, 177, 21, -1)
$Button1 = GUICtrlCreateButton("Browse", 320, 88, 97, 25)
GUICtrlCreateLabel("LST File Copy", 150, 16, 342, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("Choose LST File:", 24, 88, 94, 17)
$Partial = GUICtrlCreateCheckbox("Partial OFF",  24, 140, 100, 20, $BS_PUSHLIKE)
GUICtrlSetOnEvent(-1, "UpdateGUI")
$Button2 = GUICtrlCreateButton("Copy LST File", 152, 256, 137, 25)
$Find_Loc = ""
GUISetState(@SW_SHOW)
While 1
$msg = GuiGetMsg()
Select
Case $msg = $Button1
            $find_loc = FileOpenDialog("Please Choose File.", "ServerShare","LST Files (*.lst)",1 + 2)
   If $find_loc = "" Then ContinueLoop
            GUICtrlSetData($FileIn, $find_loc)
   $split = StringSplit($Find_loc,"")
   $Dest = "172.28.206.7BservicesLST"
   $dir = $split[$split[0] -1]
   $file = $split[$split[0]]
   $chan1 = StringMid($file, 1, 4)
   $year = StringMid($file, 7, 2)
   $Month = StringMid($file, 9, 2)
   $Day = StringMid($file, 11, 2)
  If $chan1 = "APAR" Then $chan = "AA"
  If $chan1 = "APBR" Then $chan = "AB"
  If $chan1 = "APLA" Then $chan = "AP"
  If $chan1 = "DCAR" Then $chan = "AR"
  If $chan1 = "DHBR" Then $chan = "BH"
  If $chan1 = "DCBR" Then $chan = "BL"
  If $chan1 = "CVLA" Then $chan = "DC"
  If $chan1 = "DCES" Then $chan = "DE"
  If $chan1 = "DCEE" Then $chan = "DE"
  If $chan1 = "DCFA" Then $chan = "DF"
  If $chan1 = "DFUH" Then $chan = "DF"
  If $chan1 = "DKLA" Then $chan = "DK"
  If $chan1 = "DCME" Then $chan = "DM"
  If $chan1 = "DSLA" Then $chan = "DS"
  If $chan1 = "TULA" Then $chan = "DT"
  If $chan1 = "DCVE" Then $chan = "DV"
  If $chan1 = "DHAR" Then $chan = "HA"
  If $chan1 = "DLHD" Then $chan = "HD"
  If $chan1 = "HDLT" Then $chan = "HDLT"
  If $chan1 = "DHME" Then $chan = "HM"
  If $chan1 = "DHSP" Then $chan = "HS"
  If $chan1 = "DKAR" Then $chan = "KA"
  If $chan1 = "DKBR" Then $chan = "KB"
  If $chan1 = "DKMX" Then $chan = "KM"
  If $chan1 = "DCLA" Then $chan = "LA"
  If $chan1 = "DHLA" Then $chan = "LH"
  If $chan1 = "TLLA" Then $chan = "LT"
  If $chan1 = "PAAR" Then $chan = "PA"
  If $chan1 = "PABR" Then $chan = "PB"
  If $chan1 = "PAME" Then $chan = "PM"
  If $chan1 = "PALA" Then $chan = "PN"
  If $chan1 = "DCSP" Then $chan = "SP"
  If $chan1 = "TLAR" Then $chan = "TA"
  If $chan1 = "TLCA" Then $chan = "TA"
  If $chan1 = "TLCB" Then $chan = "TB"
  If $chan1 = "PAIB" Then $chan = "TI"
  If $chan1 = "TLCL" Then $chan = "TL"
  If $chan1 = "LVAR" Then $chan = "VA"
  If $chan1 = "LVBR" Then $chan = "VB"
  If $chan1 = "LVLA" Then $chan = "VL"
  If $chan1 = "LVME" Then $chan = "VM"
  
   If BitAND(GUICtrlRead($Partial), $GUI_CHECKED) == $GUI_CHECKED THEN
   $Note = '"The LST file above will be copied to '& $Dest &''& $dir &' as '& $chan & $Month & $Day & $year &'A.LST"'
   GUICtrlCreateLabel($note, 24, 136, 390, 108)
   GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
   GUICtrlSetColor(-1, 0xFF0000)
   Else
   $Note = '"The LST file above will be copied to '& $Dest &''& $dir &' as '& $chan & $Month & $Day & $year &'.LST"'
   GUICtrlCreateLabel($note, 24, 136, 390, 108)
   GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
   GUICtrlSetColor(-1, 0xFF0000)
    ENDIF
   
Case $msg = $Button2
   If $Find_loc = "" Then ContinueLoop
   $Lookup = '" '& $Dest &''& $chan &''& $chan & $Month & $Day & $year &'.LST"'
   ;MsgBox(1, "Test", $Lookup)
   ;MsgBox(1, "File Copied", ' /c copy "' & $Find_loc & '" "' & $Dest &''& $chan &''& $chan & $Month & $Day & $year &'.LST" /Y')
   ;Runwait(@ComSpec & ' /c copy "' & $Find_loc & '" "' & $Dest &''& $chan &''& $chan & $Month & $Day & $year &'.LST" /Y',"", @SW_Hide)
   Runwait(@ComSpec & ' /c copy "' & $Find_loc & '" "' & $Dest &''& $dir &''& $chan & $Month & $Day & $year &'.LST" /Y',"", @SW_Hide)
   ;If Fileexists($lookup) Then
   MsgBox(1, "File Copied", $Lookup & " has been copied")
   ;ENDIF
Case $msg = $GUI_EVENT_CLOSE
  ExitLoop
Case Else
  ;;;;;;;
EndSelect
WEnd
Exit
Func _Quit()
    Exit
EndFunc   ;==>_Quit
Func UpdateGUI();make GUI Refresh
   If BitAND(GUICtrlRead($Partial), $GUI_CHECKED) == $GUI_CHECKED Then
       GUICtrlSetData($Partial,"Partial ON") ; if checked
    Else
       GUICtrlSetData($Partial,"Partial OFF") ; if unchecked
    EndIf

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

  • Moderators

TuMiM,

You are mixing OnEvent and MessageLoop modes - which is not possible in the same script at the same time. :)

Try this version:

#include<file.au3>
#include<array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

$Form1 = GUICreate("LST File Copy", 456, 290, 241, 160)

$FileIn = GUICtrlCreateInput("", 128, 88, 177, 21, -1)
$Button1 = GUICtrlCreateButton("Browse", 320, 88, 97, 25)
GUICtrlCreateLabel("LST File Copy", 150, 16, 342, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("Choose LST File:", 24, 88, 94, 17)
$Partial = GUICtrlCreateCheckbox("Partial OFF", 24, 140, 100, 20, $BS_PUSHLIKE)
$Button2 = GUICtrlCreateButton("Copy LST File", 152, 256, 137, 25)
$Find_Loc = ""
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $Button1
            $Find_Loc = FileOpenDialog("Please Choose File.", "ServerShare", "LST Files (*.lst)", 1 + 2)
            If $Find_Loc = "" Then ContinueLoop
            GUICtrlSetData($FileIn, $Find_Loc)
            $split = StringSplit($Find_Loc, "")
            $Dest = "172.28.206.7BservicesLST"
            $dir = $split[$split[0] - 1]
            $file = $split[$split[0]]
            $chan1 = StringMid($file, 1, 4)
            $year = StringMid($file, 7, 2)
            $Month = StringMid($file, 9, 2)
            $Day = StringMid($file, 11, 2)
            If $chan1 = "APAR" Then $chan = "AA"
            If $chan1 = "APBR" Then $chan = "AB"
            If $chan1 = "APLA" Then $chan = "AP"
            If $chan1 = "DCAR" Then $chan = "AR"
            If $chan1 = "DHBR" Then $chan = "BH"
            If $chan1 = "DCBR" Then $chan = "BL"
            If $chan1 = "CVLA" Then $chan = "DC"
            If $chan1 = "DCES" Then $chan = "DE"
            If $chan1 = "DCEE" Then $chan = "DE"
            If $chan1 = "DCFA" Then $chan = "DF"
            If $chan1 = "DFUH" Then $chan = "DF"
            If $chan1 = "DKLA" Then $chan = "DK"
            If $chan1 = "DCME" Then $chan = "DM"
            If $chan1 = "DSLA" Then $chan = "DS"
            If $chan1 = "TULA" Then $chan = "DT"
            If $chan1 = "DCVE" Then $chan = "DV"
            If $chan1 = "DHAR" Then $chan = "HA"
            If $chan1 = "DLHD" Then $chan = "HD"
            If $chan1 = "HDLT" Then $chan = "HDLT"
            If $chan1 = "DHME" Then $chan = "HM"
            If $chan1 = "DHSP" Then $chan = "HS"
            If $chan1 = "DKAR" Then $chan = "KA"
            If $chan1 = "DKBR" Then $chan = "KB"
            If $chan1 = "DKMX" Then $chan = "KM"
            If $chan1 = "DCLA" Then $chan = "LA"
            If $chan1 = "DHLA" Then $chan = "LH"
            If $chan1 = "TLLA" Then $chan = "LT"
            If $chan1 = "PAAR" Then $chan = "PA"
            If $chan1 = "PABR" Then $chan = "PB"
            If $chan1 = "PAME" Then $chan = "PM"
            If $chan1 = "PALA" Then $chan = "PN"
            If $chan1 = "DCSP" Then $chan = "SP"
            If $chan1 = "TLAR" Then $chan = "TA"
            If $chan1 = "TLCA" Then $chan = "TA"
            If $chan1 = "TLCB" Then $chan = "TB"
            If $chan1 = "PAIB" Then $chan = "TI"
            If $chan1 = "TLCL" Then $chan = "TL"
            If $chan1 = "LVAR" Then $chan = "VA"
            If $chan1 = "LVBR" Then $chan = "VB"
            If $chan1 = "LVLA" Then $chan = "VL"
            If $chan1 = "LVME" Then $chan = "VM"

            If BitAND(GUICtrlRead($Partial), $GUI_CHECKED) == $GUI_CHECKED Then
                $Note = '"The LST file above will be copied to ' & $Dest & '' & $dir & ' as ' & $chan & $Month & $Day & $year & 'A.LST"'
                GUICtrlCreateLabel($Note, 24, 136, 390, 108)
                GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
                GUICtrlSetColor(-1, 0xFF0000)
            Else
                $Note = '"The LST file above will be copied to ' & $Dest & '' & $dir & ' as ' & $chan & $Month & $Day & $year & '.LST"'
                GUICtrlCreateLabel($Note, 24, 136, 390, 108)
                GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
                GUICtrlSetColor(-1, 0xFF0000)
            EndIf

        Case $msg = $Button2
            If $Find_Loc = "" Then ContinueLoop
            $Lookup = '" ' & $Dest & '' & $chan & '' & $chan & $Month & $Day & $year & '.LST"'
            ;MsgBox(1, "Test", $Lookup)
            ;MsgBox(1, "File Copied", ' /c copy "' & $Find_loc & '" "' & $Dest &''& $chan &''& $chan & $Month & $Day & $year &'.LST" /Y')
            ;Runwait(@ComSpec & ' /c copy "' & $Find_loc & '" "' & $Dest &''& $chan &''& $chan & $Month & $Day & $year &'.LST" /Y',"", @SW_Hide)
            RunWait(@ComSpec & ' /c copy "' & $Find_Loc & '" "' & $Dest & '' & $dir & '' & $chan & $Month & $Day & $year & '.LST" /Y', "", @SW_HIDE)
            ;If Fileexists($lookup) Then
            MsgBox(1, "File Copied", $Lookup & " has been copied")
            ;ENDIF
        Case $msg = $Partial
            UpdateGUI()
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
            ;;;;;;;
    EndSelect
WEnd
Exit
Func _Quit()
    Exit
EndFunc   ;==>_Quit
Func UpdateGUI();make GUI Refresh
    If BitAND(GUICtrlRead($Partial), $GUI_CHECKED) == $GUI_CHECKED Then
        GUICtrlSetData($Partial, "Partial ON") ; if checked
    Else
        GUICtrlSetData($Partial, "Partial OFF") ; if unchecked
    EndIf

EndFunc   ;==>UpdateGUI

Working now? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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