Что нового

[Элементы GUI] проблема с radio

andreitrane

Новичок
Сообщения
141
Репутация
3
почему условие на radio не срабатывает и при нажатии на button выводится самое первое значение radio, не смотря на то, какое выбрано
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117, 418, 309)
$kontaktradio = GUICtrlCreateRadio("kontaktradio", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mailradio", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
$Button2 = GUICtrlCreateButton("Button2", 8, 80, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
global $server

			if GUICtrlRead($kontaktradio) = $GUI_CHECKED Then
				$server = "109.234.155.196"
				elseif GUICtrlRead($mailradio) = $GUI_CHECKED Then
				$server = "109.234.156.254"
			EndIf
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
case $button1
msgbox(0, "", $server)
case $button2
msgbox(0, "", $server)

	EndSwitch
WEnd
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
andreitrane
а где ты проводишь опрос состояния радио в цикле?
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
все, разобрался, много вариантов пробовал, кроме этого, и все не подходили
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117, 418, 309)
$kontaktradio = GUICtrlCreateRadio("kontaktradio", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mailradio", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
$Button2 = GUICtrlCreateButton("Button2", 8, 80, 65, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
            if GUICtrlRead($kontaktradio) = $GUI_CHECKED Then
               global  $server = "109.234.155.196"
                elseif GUICtrlRead($mailradio) = $GUI_CHECKED Then
              global  $server = "109.234.156.254"
            EndIf

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
case $button1
msgbox(0, "", $server)
case $button2
msgbox(0, "", $server)

    EndSwitch
WEnd
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
andreitrane
А зачем все время проверять?
Код:
#include <GUIConstantsEx.au3>

#region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117)
$kontaktradio = GUICtrlCreateRadio("kontakt", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mail", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
GUISetState()
#endregion ### END Koda GUI section ###
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			If GUICtrlRead($kontaktradio) = $GUI_CHECKED Then
				Global $server = "109.234.155.196"
			Else
				Global $server = "109.234.156.254"
			EndIf
			MsgBox(0, "", $server)
	EndSwitch
WEnd
 
Автор
A

andreitrane

Новичок
Сообщения
141
Репутация
3
madmasles, у меня будет несколько кнопок, поэтому если использовать ваш скрипт, придется вписывать проверку на каждую кнопку, а это увеличит скрипт....
 

dwerf

Использует ArchLinux
Сообщения
478
Репутация
219
Код:
#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117)
$kontaktradio = GUICtrlCreateRadio("kontakt", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mail", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
GUISetState()
#EndRegion ### END Koda GUI section ###

Global $server = "109.234.155.196"

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $kontaktradio
			$server = "109.234.155.196"
		Case $mailradio
			$server = "109.234.156.254"
		Case $Button1
			MsgBox(0, "", $server)
	EndSwitch
WEnd
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
andreitrane [?]
у меня будет несколько кнопок, поэтому если использовать ваш скрипт, придется вписывать проверку на каждую кнопку, а это увеличит скрипт
Насколько оно там увеличит...
Код:
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1, $Buuton2, ...
            If GUICtrlRead($kontaktradio) = $GUI_CHECKED Then
                Global $server = "109.234.155.196"
            Else
                Global $server = "109.234.156.254"
            EndIf
            MsgBox(0, "", $server)
    EndSwitch
WEnd


а вообще, правильнее делать так:

Код:
#include <GUIConstantsEx.au3>

Global $server = "109.234.155.196"

#region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117)
$kontaktradio = GUICtrlCreateRadio("kontakt", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mail", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
$Button2 = GUICtrlCreateButton("Button2", 8, 80, 65, 25)
GUISetState()
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1, $Button2
            MsgBox(0, "", $server)
		Case $kontaktradio
			If GUICtrlRead($kontaktradio) = $GUI_CHECKED Then
				$server = "109.234.155.196"
			EndIf
		Case $mailradio
			If GUICtrlRead($mailradio) = $GUI_CHECKED Then
				$server = "109.234.156.254"
			EndIf
    EndSwitch
WEnd
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Или так:
Код:
#include <GUIConstantsEx.au3>

Global $server = "109.234.155.196"

#region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 117, 117)
$kontaktradio = GUICtrlCreateRadio("kontakt", 8, 8, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$mailradio = GUICtrlCreateRadio("mail", 8, 24, 65, 17)
$Button1 = GUICtrlCreateButton("Button1", 8, 48, 65, 25)
$Button2 = GUICtrlCreateButton("Button2", 8, 80, 65, 25)
GUISetState()
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1, $Button2
			Switch $GUI_CHECKED
				Case GUICtrlRead($kontaktradio)
					$server = "109.234.155.196"
				Case GUICtrlRead($mailradio)
					$server = "109.234.156.254"
			EndSwitch
			
            MsgBox(0, "", $server)
    EndSwitch
WEnd
 
Верх