Sign in to follow this  
Followers 0
Ibike2

Variable number of Radio Buttons

4 posts in this topic

Newbie question after hours spent in help and the forums without finding a solution.

I'm attempting to take the entries from a listbox in someone else's GUI (no command line) and create a radio button for each entry in my own GUI. When the user selects a radio button and selects OK, I would like the value related to that radio to be stored in an output variable to be input the next time this listbox appears.

I have no problems sending the stored value to the listbox when it appears again, my issue is that the output variable is inconsistently stored. Sometimes it stores perfectly, sometimes (when i start with a different list in the same listbox) nothing is stored, and it seems consistent which lists do store and which don't, but I haven't identified anything different about the ones that work and ones that don't.

The code is

#include <GuiConstantsEx.au3>
#include <Guicombobox.au3>
#include <array.au3>
#include <GuiListBox.au3>

Global $Runfiles[50]
Global $Runfile=""
Global $Openhandle
Global $OKButton
Global $NumberProjects
Global $msg

dim $i=1
dim $n=0

WinActivate("Open Project", "")

sleep(200)

$Openhandle=ControlGetHandle("Open Project", "", "[ID: 3]")

$NumberProjects=_GUICtrlListBox_GetCount($Openhandle)
For $n=0 to $NumberProjects
    $Runfiles[$n+1]=_GUICtrlListBox_GetText($Openhandle, $n)
Next
$Runfiles[0]=$NumberProjects

GUICreate("Available Project Files", 600, $Runfiles[0]*20+100)
GUISetState()
GUISetFont(10)
GUICtrlCreateLabel("Please select one of the Project Files to optimize", 10, 10)
GUICtrlCreateGroup("Available Project Files", 10, 40)
For $i = 1 To $Runfiles[0]
    Dim $Radio[50]
    $Radio[$i]=GUICtrlCreateRadio($Runfiles[$i], 10, ($i * 20)+20)
    
Next
GUICtrlCreateGroup("", -99, -99)
$OKButton=GUICtrlCreateButton("OK", 260, $Runfiles[0]*20+70, 90, 20)


While 1
    $msg=GUIGetMsg()
    
    If $msg=$GUI_Event_Close Then 
        $Runfile=""
        ExitLoop
    EndIf
    
    For $i = 1 To $Runfiles[0]
        if GUICtrlRead($Radio[$i])= $GUI_Checked Then
            $Runfile=$Runfiles[$i]
            EndIf
        Next
    
    if $msg=$OKButton Then
            ExitLoop
        EndIf
        
    sleep(10)
Wend

MsgBox(0, "", $NumberProjects)
MsgBox(0, "", $Runfile)

but I think my issue lies within the portion

While 1
    $msg=GUIGetMsg()
    
    If $msg=$GUI_Event_Close Then 
        $Runfile=""
        ExitLoop
    EndIf
    
    For $i = 1 To $Runfiles[0]
        if GUICtrlRead($Radio[$i])= $GUI_Checked Then
            $Runfile=$Runfiles[$i]
            EndIf
        Next
    
    if $msg=$OKButton Then
            ExitLoop
        EndIf
        
    sleep(10)
Wend

Any thoughts on making this more consistent, or an easier way to change from external listbox to radio's in my GUI?

Thanks all for any help.

Share this post


Link to post
Share on other sites



Found in help that I should be using BitAND(GUICtrlRead($Radio[$i]),$GUI_CHECKED)= $GUI_Checked Then in place of GUICtrlRead($Radio[$i])=$GUI_Checked, but this still didn't solve the problem. Also of note, the gui displays well with all of the buttons needed, it's just the matter of storing the selection. And I found that it is possible for one radio to store correctly and others not even when reading from the same table.

Thanks so much for any suggestions.

Share this post


Link to post
Share on other sites

Look closely at this loop:

For $i = 1 To $Runfiles[0]
    Dim $Radio[50]
    $Radio[$i]=GUICtrlCreateRadio($Runfiles[$i], 10, ($i * 20)+20)
Next

You are re-declaring the $Radio array over-and-over, wiping out the data each time. Move that outside the loop.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks PsaltyDS for overlooking my newness and helping with the code. Your suggestion fixed all of the issues with my script and I will be a more careful programmer because of it.

Thanks does not begin to convey my gratitude for the number of hours of frustration you just saved me.

Have a great weekend!

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