Sign in to follow this  
Followers 0
Delai

radio buttons in a Loop

3 posts in this topic

Hi, I have a trouble with a script. First i will explain what i do and what i want:

  • I search for all the files with the extension .txt
  • I split the file with the delimiter "."
  • I create button radio for any word of the file splitted. and a button "continue".
When i press the button "Continue" without checking any radio button, it passes to the following search file, that i don´t want. What I want, is to put a message that tells me that first i must check one radio button and not pass to the follolwing search until i have checked one radio button.

Here is my script:

#include <GUIConstants.au3>
#include <File.au3>
$search = FileFindFirstFile("*.txt")
If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
  Exit
EndIf

While 1
   $File = FileFindNextFile($search)
    If @error Then ExitLoop
    $Nombre = StringSplit( $file , "." )

    GUICreate("My Guide"); will create a dialog box that when displayed is centered
    $Button = GUICtrlCreateButton ("Continue",  310, 360, 70)
    GUISetState ()  ; will display an  dialog box with 1 checkbox

    $Height=10
    For $i=1 to $Nombre[0]
      $Nombre[$i] = GUICtrlCreateRadio ($Nombre[$i], 10, $Height, 120, 20)
      $Height = $Height + 20
    Next
    
    While 1
       $msg = GUIGetMsg()
       Select
         Case $msg = $GUI_EVENT_CLOSE
             Exit
          Case $msg = $Button
            For $i=1 to $Nombre[0]
                $Radio_State = BitAND(GUICtrlRead($Nombre[$i]), $GUI_CHECKED)
;             IF GUICtrlRead($Nombre[$i]) = $GUI_CHECKED THen 
               IF $Radio_State = $GUI_CHECKED THen 
               $Extract = "Plantilla.txt"
               $Text = FileRead($Extract,FileGetSize($Extract))
               $Text = StringReplace($Text,"Titulo",$File)
               $Text = StringReplace($Text,"Plantilla",GUICtrlRead($Nombre[$i], 1))
               FileWrite("ScriptFile.txt", $Text)
               MsgBox(1, '', 'Has Seleccionado El Titulo: '  & GUICtrlRead($Nombre[$i], 1))
         !!!!!! here i want to code, not to pass to the follwing search file untile i have checked one radio button!!!!!!
           ENDIF
          Next         
     ExitLoop
     EndSelect
     
     Wend
WEnd
FileClose($search)

Share this post


Link to post
Share on other sites



I think this will do what you need.

#include <GUIConstants.au3>
#include <File.au3>

$search = FileFindFirstFile("*.txt")
If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
  Exit
EndIf

; While loop removed.  From here ---->>
$File = FileFindNextFile($search)
$Nombre = StringSplit( $file , "." )

GUICreate("My Guide"); will create a dialog box that when displayed is centered
$Button = GUICtrlCreateButton ("Continue",  310, 360, 70)
GUISetState ()    ; will display an  dialog box with 1 checkbox

$Height=10
For $i=1 to $Nombre[0]
    $Nombre[$i] = GUICtrlCreateRadio ($Nombre[$i], 10, $Height, 120, 20)
    $Height += 20
Next
; <<---- to here should only need to be done one time.

While 1
    $msg = GUIGetMsg()

    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button
            ; This checks to to see which radio button is selected.
            ; If nothing is selected checked = 0, if something is
            ; selected then checked = the array element of the control.
            $checked = 0
            For $i = 1 To $Nombre[0]
                If GUICtrlRead($Nombre[$i]) = $GUI_CHECKED Then
                    $checked = $i
                    ExitLoop
                EndIf
            Next

            If $checked > 0 Then
               $Extract = "Plantilla.txt"
               $Text = FileRead($Extract,FileGetSize($Extract))
               $Text = StringReplace($Text,"Titulo",$File)
               $Text = StringReplace($Text,"Plantilla",GUICtrlRead($Nombre[$checked], 1))
               FileWrite("ScriptFile.txt", $Text)
               MsgBox(1, '', 'Has Seleccionado El Titulo: '  & GUICtrlRead($Nombre[$checked], 1))
           Else
               MsgBox(64, 'Nothing Selected', 'Please make a selection first.')
           EndIf

    EndSwitch
WEnd
FileClose($search)

Share this post


Link to post
Share on other sites

Thank you very much @cjconstantine, it works fine. That is exactly what I need.

Thanks again.

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