Sign in to follow this  
Followers 0
jakub

value of GUI item in variable

8 posts in this topic

ive got 3 inputs, and i want to set data in depends of condition $c

Switch $c

Case 1

$v=$input1

Case 2

$v=$input2

Case 3

$v=$input3

Endswitch

GUICtrlSetdata($v,$m)

but it doesnt work like that :/

Expected a "=" operator in assignment statement.:

$v=$input1

and i wont do it this way:

Case 1

GUICtrlSetdata($input1,$m)

casue my script is a lot more complicated

so if there is better option i would be gratefull for help

Share this post


Link to post
Share on other sites

ive got 3 inputs, and i want to set data in depends of condition $c

Switch $c

Case 1

$v=$input1

Case 2

$v=$input2

Case 3

$v=$input3

Endswitch

GUICtrlSetdata($v,$m)

but it doesnt work like that :/

Expected a "=" operator in assignment statement.:

$v=$input1

and i wont do it this way:

Case 1

GUICtrlSetdata($input1,$m)

casue my script is a lot more complicated

so if there is better option i would be gratefull for help

A simple look would be work, but we don't know the types of values in the ID's. Maybe you need some tests for encounter the problem.

A suggestion: Adding an Else statement to Switch and checking the result in $v and $c vars.

Share this post


Link to post
Share on other sites

variable $input1 is created as a

$input1=GUICtrlCreateInput("",...)

so i can set data in this input by

GUICtrlSetData($input,"")

but cause i dont know in wich input data should be set i use

GUICtrlSetData($v,"")

and function data chose input

func choseinput()

$v=$input1

endfunc

[its example to show in simple way what the problem is]

Share this post


Link to post
Share on other sites

Correction...

func choseinput()
$v=GUICtrlRead($input1)
endfunc

Share this post


Link to post
Share on other sites

NO. Totaly wrong. Why?

Share this post


Link to post
Share on other sites

As Josbe says

A simple look would be work, but we don't know the types of values in the ID's

In your case if $c is not numeric then your switch statement will not work

Share this post


Link to post
Share on other sites

It works for me.

$gui = GUICreate('', 200, 200)
$input1 = GUICtrlCreateInput('', 0, 0, 100, 20)
$input2 = GUICtrlCreateInput('', 0, 20, 100, 20)
$input3 = GUICtrlCreateInput('', 0, 40, 100, 20)
GUISetState()

$c = 1
Switch $c
    Case 1
        $v = $input1
    Case 2
        $v = $input2
    Case 3
        $v = $input3
EndSwitch

$m = 'Text'
GUICtrlSetData($v, $m)

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case -3 ; $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

As long as $v is between 1-3, no problems otherwise the guictrlsetdata will crash the program. Just put a case else in the switch statement and force a valid input-id for guictrlsetdata.

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