Показать полную графическую версию : [решено] ComboBox не передаёт переменную в функцию.
Alkogolik
26-05-2020, 13:18
Добрый день.
сильно не пинайте, только учусь. Переменная внутри функции работает. если несколько функций то код слишком большой получается.
пересмотрел несколько примеров, везде внутри функции, а надо снаружи. подскажите что не так?
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 302, 111, 192, 114)
Global $Combo1 = GUICtrlCreateCombo("", 24, 24, 145, 25)
GUICtrlSetData(-1, "яблоко|шарик|вода|трава|изолента", "яблоко")
$Button1 = GUICtrlCreateButton("Button1", 192, 24, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
; это не работает
;#cs
$msg = GUICtrlRead($Combo1)
if $msg = "яблоко" Then $msg = ("красное")
if $msg = "шарик" Then $msg = ("круглый")
if $msg = "вода" Then $msg = ("мокрая")
if $msg = "трава" Then $msg = ("зеленая")
if $msg = "изолента" Then $msg = ("синяя")
;#ce
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
start()
EndSwitch
WEnd
Func start()
; это работает
;#cs
; $msg = GUICtrlRead($Combo1)
; if $msg = "яблоко" Then $msg = ("красное")
; if $msg = "шарик" Then $msg = ("круглый")
; if $msg = "вода" Then $msg = ("мокрая")
; if $msg = "трава" Then $msg = ("зеленая")
; if $msg = "изолента" Then $msg = ("синяя")
;#ce
MsgBox (0,"info", $msg )
endFunc
Ну вообще то в первом варианте (то что не работает), в любом случае $msg будет "красное", т.к изначально выбор стоит на яблоке.
Скорее всего нужно так:
#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $sCombo_Data = 'яблоко|шарик|вода|трава|изолента'
Global (http://www.autoitscript.com/autoit3/docs/keywords.htm#Global) $sType_Data = 'красное|круглый|мокрая|зеленая|синяя'
$hGUI = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)('Form1', 300, 100)
$Combo1 = GUICtrlCreateCombo (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateCombo.htm)('', 24, 24, 145, 25)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)(-1, $sCombo_Data, 'яблоко')
$Button1 = GUICtrlCreateButton (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateButton.htm)('Button1', 192, 24, 75, 25)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@SW_SHOW))
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $Button1
start()
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) start()
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $sRead = GUICtrlRead (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlRead.htm)($Combo1)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aCombo = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($sCombo_Data, '|')
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $aType = StringSplit (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm)($sType_Data, '|')
For (http://www.autoitscript.com/autoit3/docs/keywords.htm#For) $i = 1 To (http://www.autoitscript.com/autoit3/docs/keywords.htm#To) $aCombo[0]
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $aCombo[$i] = $sRead Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(64, 'info', $aType[$i], 0, $hGUI)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
Next (http://www.autoitscript.com/autoit3/docs/keywords.htm#Next)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)
Alkogolik
26-05-2020, 15:11
Creat0R, спасибо. пойду разбираться.
P.S. если не сложно укажи ссылку на теги для Autoit. А то нашел тему а ей более 10 лет и ошибок много.
http://forum.oszone.net/thread-148733.html
укажи ссылку на теги для Autoit »
Не совсем понял, про какие теги идёт речь?
Если речь про подсветку, тогда сюда (https://creator-lab.ucoz.ru/load/3-1-0-18).
Alkogolik
26-05-2020, 17:08
Скорее всего нужно так: »
не совсем то что хотелось.
немного переделал (мне новичку читается легче).
но всё равно спасибо. помог.
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 302, 111, 192, 114)
$Combo1 = GUICtrlCreateCombo("яблоко", 8, 8, 139, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "шарик|вода|трава|изолента")
$Button1 = GUICtrlCreateButton("Button1", 192, 24, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
If _GUICtrlComboBox_GetCurSel($Combo1) = 0 Then
$msg = ("красное")
ElseIf _GUICtrlComboBox_GetCurSel($Combo1) = 1 Then
$msg = ("круглый")
ElseIf _GUICtrlComboBox_GetCurSel($Combo1) = 2 Then
$msg = ("мокрая")
ElseIf _GUICtrlComboBox_GetCurSel($Combo1) = 3 Then
$msg = ("зелёная")
Else
$msg = ("синяя")
EndIf
start1()
start2()
EndSwitch
WEnd
Func start1()
MsgBox (0,"info1", $msg )
endFunc
Func start2()
MsgBox (0,"info2", $msg )
endFunc
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.