This looks like the resurrection of this topic
https://forums.mirc.com/ubbthreads.php/topics/209623/dialog-question

As I mentioned earlier in this thread, while it is true that using 2 variables for filename vs index works for the icon dialog-control that's controlled later by /did -g, the icon command in a table for controlling the dialog window's titlebar icon does not seem to support using anything to define the index except using literal text numbers. But the method C earlier doesn't recognize using an identifier or variable to define the titlebar icon's index. I tried using things including

[ 21 ]
$calc(21)
$eval(21,0)
$+(21)
placing 21 inside %iconindex
having $iconindex return 21
etc

and none of them worked. The old thread said that getting this to work is a feature request, and that appears to never been added, and the OP from 11 years ago ended up creating 2 dialog tables in order to call 1 of 2 alternatives. That's not an easy universal situation, if the table is large, or if there are a lot more than 2 icons to be used. I don't find an old reference where someone wanted to be able to use a /did command to change the titlebar icon, but it appears that's not possible either, barring my earlier suggestion to have /did -g refer to the titlebar icon by index 0 - which could also be a substitute for fixing the parsing of the dialog table.

I haven't checked to see which other contexts of the dialog table doesn't support $identifier/%variable either. Depending on this OP's use case, I don't know if there's a simple way to extract icons out of icon libraries like shell32.dll, then saving the icon to a separate filename by itself. But trying that might only be available on a few of the icon formats. I know of ICL, DLL, EXE, but i suspect there's others, even .ICO files containing multiple sizes of the same thing.