Jump to content

String to controlID problem


vcent
 Share

Recommended Posts

I wanted to use a loop or switch case to loop thr a number of radios

Switch $value

Case 1

GUICtrlSetState("$radio" & $value, $GUI_CHECKED)

Case 2

GUICtrlSetState("$radio" & $value, $GUI_CHECKED)

and so on....

The above will now work because I can't pass a string into the GUICtrlSetState. Is there other ways other than IF Else statements ?

Thanks.

Link to comment
Share on other sites

I wanted to use a loop or switch case to loop thr a number of radios

Switch $value

Case 1

GUICtrlSetState("$radio" & $value, $GUI_CHECKED)

Case 2

GUICtrlSetState("$radio" & $value, $GUI_CHECKED)

and so on....

The above will now work because I can't pass a string into the GUICtrlSetState. Is there other ways other than IF Else statements ?

Thanks.

Use an array, something like this:

Dim $RADIO[3]
$RADIO[0] = GUICtrlCreateRadio()
$RADIO[1] = GUICtrlCreateRadio()
$RADIO[2] = GUICtrlCreateRadio()

Switch $value
Case 0
GUICtrlSetState($RADIO[0], $GUI_CHECKED)
Case 1
GUICtrlSetState($RADIO[1], $GUI_CHECKED)
Case 2
GUICtrlSetState($RADIO[2], $GUI_CHECKED)

When the words fail... music speaks.

Link to comment
Share on other sites

  • Moderators

vcent,

As the ControlIDs are just numbers you could also do something like this:

$Radio_start = GUICtrlCreateRadio()
GUICtrlCreateRadio()
...
...
$Radio_end = GUICtrlCreateRadio()

For $i = $Radio_start To $Radio_end
    GUICtrlSetState($i, $GUI_CHECKED)
Next

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for your suggestions.

My codes have about 20 radios something like a survey

Don't Like Average Good Excellent

1. Rate how best you like apple

2. Rate how best you like orange

Basically I'm trying to load data hence I wanted to set GUICtrlSetstate based on a text file.

Other than a switch case, I can't think of other ways to set data other than if else :) But I have quite a number of such questions hecne I thought the codes will be more efficient.

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...