Jump to content

Noob help


Recommended Posts

Hi

I have been reading the forums But cannot seem to find my answer

Its probably to noob, so please forgive me I am brand new not only to AutoIt but to programming

My first project is to collect data from input boxes and radio buttong whithin a gui, and writing results to an ini file.

My problems lie in the radio data collection, I am doing something totally wrong

Can someone help me out with the code ? it would be much appreciated

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 509, 281, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 48, 24, 417, 73)
$Radio1 = GUICtrlCreateRadio("Radio1", 80, 56, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 200, 56, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 336, 56, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 48, 120, 417, 73)
$Radio4 = GUICtrlCreateRadio("Radio4", 80, 152, 113, 17)
$Radio5 = GUICtrlCreateRadio("Radio5", 200, 152, 113, 17)
$Radio6 = GUICtrlCreateRadio("Radio6", 336, 152, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Cancel", 120, 224, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Next", 272, 224, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
        Case $Button2

            $sIni = @DesktopDir & "\radioinitest.ini"

            $nData1 = "group_1 = " & GUICtrlRead($Group1)
            $nData2 = "group_2 = " & GUICtrlRead($Group2)
            IniWriteSection($sIni, "Result1", $nData1)
            IniWriteSection($sIni, "Result2", $nData2)



            Exit

    EndSwitch
WEnd

I'm wanting the name of the radio button in any group to be written to the ini file, but at the moment it is writing the group name.

ie. heres the result from the script

[Result1]

group_1 = Group1

[Result2]

group_2 = Group2

I am after

[Result1]

group_1 = Radio1

[Result2]

group_2 = radio4

Or whatever button was selected

Any help

EDIT:

Also, I cant figure out how to create a space between the sections

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Here you go.. >_<

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $r1="Radio 1",$r2="Radio 2",$r3="Radio 3",$r4="Radio 4",$r5="Radio 5",$r6="Radio 6"
$Form1 = GUICreate("Form1", 509, 281, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 48, 24, 417, 73)
$Radio1 = GUICtrlCreateRadio($r1, 80, 56, 113, 17)
$Radio2 = GUICtrlCreateRadio($r2, 200, 56, 113, 17)
$Radio3 = GUICtrlCreateRadio($r3, 336, 56, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 48, 120, 417, 73)
$Radio4 = GUICtrlCreateRadio($r4, 80, 152, 113, 17)
$Radio5 = GUICtrlCreateRadio($r5, 200, 152, 113, 17)
$Radio6 = GUICtrlCreateRadio($r6, 336, 152, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Cancel", 120, 224, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Next", 272, 224, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
        Case $Button2
    
            $sIni = @DesktopDir & "\radioinitest.ini"
            Select
            Case GUICtrlRead($radio1)=1
                $var1=$r1
                
            Case GUICtrlRead($radio2)=1
                $var1=$r2
                
            Case GUICtrlRead($radio3)=1
                $var1=$r3
            EndSelect       
            
            Select
            Case GUICtrlRead($radio4)=1
                $var2=$r4
                
            Case GUICtrlRead($radio5)=1
                $var2=$r5
                
            Case GUICtrlRead($radio6)=1
                $var2=$r6
            EndSelect   
                
            $nData1 = "group_1 = " & $var1
            $nData2 = "group_2 = " & $var2
            IniWriteSection($sIni, "Result1", $nData1)
            IniWriteSection($sIni, "Result2", $nData2)



            Exit

    EndSwitch
WEnd
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

Hi

I have been reading the forums But cannot seem to find my answer

Its probably to noob, so please forgive me I am brand new not only to AutoIt but to programming

My first project is to collect data from input boxes and radio buttong whithin a gui, and writing results to an ini file.

My problems lie in the radio data collection, I am doing something totally wrong

Can someone help me out with the code ? it would be much appreciated

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 509, 281, 192, 124)
$Group1 = GUICtrlCreateGroup("Group1", 48, 24, 417, 73)
$Radio1 = GUICtrlCreateRadio("Radio1", 80, 56, 113, 17)
$Radio2 = GUICtrlCreateRadio("Radio2", 200, 56, 113, 17)
$Radio3 = GUICtrlCreateRadio("Radio3", 336, 56, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Group2", 48, 120, 417, 73)
$Radio4 = GUICtrlCreateRadio("Radio4", 80, 152, 113, 17)
$Radio5 = GUICtrlCreateRadio("Radio5", 200, 152, 113, 17)
$Radio6 = GUICtrlCreateRadio("Radio6", 336, 152, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Cancel", 120, 224, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Next", 272, 224, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
        Case $Button2

            $sIni = @DesktopDir & "\radioinitest.ini"

            $nData1 = "group_1 = " & GUICtrlRead($Group1)
            $nData2 = "group_2 = " & GUICtrlRead($Group2)
            IniWriteSection($sIni, "Result1", $nData1)
            IniWriteSection($sIni, "Result2", $nData2)



            Exit

    EndSwitch
WEnd

I'm wanting the name of the radio button in any group to be written to the ini file, but at the moment it is writing the group name.

ie. heres the result from the script

I am after

[Result1]

group_1 = Radio1

[Result2]

group_2 = radio4

Or whatever button was selected

Any help

EDIT:

Also, I cant figure out how to create a space between the sections

Hi,

change

$nData1 = "group_1 = " & GUICtrlRead($Group1)

$nData2 = "group_2 = " & GUICtrlRead($Group2)

IniWriteSection($sIni, "Result1", $nData1)

IniWriteSection($sIni, "Result2", $nData2)

to

If GUICtrlRead ($Radio1) = $GUI_CHECKED Then
                $nData1 = "group_1 = Radio1"
            ElseIf GUICtrlRead ($Radio2) = $GUI_CHECKED Then
                $nData1 = "group_1 = Radio2"
            ElseIf GUICtrlRead ($Radio3) = $GUI_CHECKED Then
                $nData1 = "group_1 = Radio3"
            EndIf
            If GUICtrlRead ($Radio4) = $GUI_CHECKED Then
                $nData1 = "group_2 = Radio4"
            ElseIf GUICtrlRead ($Radio5) = $GUI_CHECKED Then
                $nData1 = "group_2 = Radio5"
            ElseIf GUICtrlRead ($Radio6) = $GUI_CHECKED Then
                $nData1 = "group_2 = Radio6"
            EndIf
            IniWriteSection($sIni, "Result1", $nData1)
            IniWriteSection($sIni, "Result2", $nData2)

So, if you want to check radiobutton, you have to check it instead of checking the group. There is a more elegant way to check the buttons with a For loop, i think Melba did it. But this should also work.

For the space i would try a IniWriteSection($sIni, "", @CRLF) after the write for "Result1".

;-))

Stefan

[edit]Manjish beats me with another solution..........

Edited by 99ojo
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...