Jump to content

Recommended Posts

Posted

I'm wanting to create radio buttons from file input. Could be csv but, for now, just single column data. I have used FileReadLine to create an array of data and output this to a list. But I do not know how to implement this in radio buttons.

I am by no means a programmer, so I ask for your ideas (and hopefully some code example).

Thanks!

Posted (edited)

take a look at this:

only added a few lines to the help file example in the for...next loop. just displays it, I didn't do any more work than that, but you can finish it the way you wish.

GuiCreate ("My first AutoIt GUI"); start the definition 
   
GuiSetControl ("label", "Please Enter ?", 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30); add the input area 
$nOk    = GUISetControl ("button", "OK", 20,70); add the button that will close the GUI 
For $i=1 To 4
$var = IniRead("myfile.ini", "section1", $i, "Null") 
;IniWrite("myfile.ini", "section1", $i, "this is a new value"); used this to make the file
GuiSetControl("radio", $var,200,10+($i*20))
Next   

GuiWaitClose (); to display the dialog box 
    
if $nOK= GuiRead () then; to verify if OK was click 
  $input = GuiRead ($nInput); get the type value 
  msgbox(0,"Result", $input); will display the typed value 
endif

I would personally just put a delimited line for it, and use string split. You can then get the size of the array to fill in your radio buttons. ( make sure to know the limits of the gui size, or adjust it with your info.

edit...

ex:

GuiCreate ("My first AutoIt GUI"); start the definition
 
$nOk    = GUISetControl ("button", "OK", 10,10); add the button that will close the GUI
$x=StringSplit(FileReadLine("myfile.ini",1),",")
dim $out[$x[0]+1]

For $i=1 To $x[0]
$out[$i]=GuiSetControl("radio", $x[$i],10,20+($i*20),300)
Next  

GuiWaitClose (); to display the dialog box
   
if $nOK= GuiRead () then; to verify if OK was click
For $i=1 To $x[0]
 $input = GuiRead ($out[$i]); get the type value
If $input<>4 Then  msgbox(0,"Result"&$i, $x[$i]); will display the clicked value
Next
endif
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Posted

Apologies for not responding here sooner...

I tried your code, ScriptKitty, and only displays the first item in the file. Perhaps I'm doing something wrong?

Posted

oops, I guess I should have said what the first line was:

myfile.ini

bob,fred,joe,sam

I just made a comma delimited line to show one way to do it.

AutoIt3, the MACGYVER Pocket Knife for computers.

Posted

yea, any way you want, look into filereadline()

if the help file doesn't explain it well enough, I can post a solution.

AutoIt3, the MACGYVER Pocket Knife for computers.

Posted

Yes, I saw that. But how to I substitute the comma delimiter with a newline delimiter? I tried @LF and char(10), but that did not appear to have any effect.

Posted

GuiCreate ("My first AutoIt GUI"); start the definition

$nOk    = GUISetControl ("button", "OK", 10,10); add the button that will close the GUI
$x=StringSplit(StringReplace(FileRead("myfile.ini",FileGetSize("myfile.ini")),@LF,""),@CR)
dim $out[$x[0]+1]

For $i=1 To $x[0]
$out[$i]=GuiSetControl("radio", $x[$i],10,20+($i*20),300)
Next  

GuiWaitClose (); to display the dialog box
 
if $nOK= GuiRead () then; to verify if OK was click
For $i=1 To $x[0]
$input = GuiRead ($out[$i]); get the type value
If $input<>4 Then  msgbox(0,"Result"&$i, $x[$i]); will display the clicked value
Next
endif

or you can use the filereadline, and use the loop to make your controls that way. Use the @error to know when the end of the file is found.

not to be confusing so:

$x=StringSplit(StringReplace(FileRead("myfile.ini",FileGetSize("myfile.ini")),@LF,""),@CR)

this reads the entire file by finding the filesize and using the fileread

then I replace the LF in @CRLF so that each line ends with one character @CR

Then I split it all up into and array by the @CR.

AutoIt3, the MACGYVER Pocket Knife for computers.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...