1
$\begingroup$

I'm trying to make a simple app, which loads some data via TextFields and then does something with that, but ...

Needs["GUIKit`"]
okt1 == PropertyValue[{"O1", "text"}]
mask1 == PropertyValue[{"M1", "text"}]

Of course O1 and M1 are simply names of TextFields. Then I want to use BitAnd with those two numbers which user should enter.

SetPropertyValue[{"siec1", "text"}, BitAnd[okt1, mask1]]

All these actions are performed by an inside script which starts to work when an user clicks a button.

My problem is why in TextField named siec1 I see this:

BitAnd[GUIKit`Private`Script83`mask1, GUIKit`Private`Script83`okt1]

Instead of some value that I expect to see. Of course when I use

SetPropertyValue[{"siec1", "text"}, 2]

Number 2 appears in TextField siec1.

How should I approach this problem ?

Whole code:

Needs["GUIKit`"];
ref = GUIRun[
    Widget["Panel",
        {
            Widget["Label", {"text" -> "Wprowadź adres IP:"}],
            {
                Widget["TextField", {"columns" -> 3}, Name -> "O1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "O2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "O3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "O4"]
            },
            Widget["Label", {"text" -> "Wprowadź maskę"}],
            {
                Widget["TextField", {"columns" -> 3}, Name -> "M1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "M2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "M3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3}, Name -> "M4"]
            },
            Widget["Label", {"text" -> "                        "}],
            (***************************************************)
            (***************************************************)
            (***************************************************)
            Widget["Button", {"text" -> "Oblicz!",
                BindEvent["action",
                        Script[Przelicz[]] 
                     ],
                Script[
                        Przelicz[] := (
                        (*Pobranie wartosc z pol na formularzu*)
                            ref @okt1 == PropertyValue[{"O1", "text"}]
                            ref @okt2 == PropertyValue[{"O2", "text"}]
                            ref @okt3 == PropertyValue[{"O3", "text"}]
                            ref @okt4 == PropertyValue[{"O4", "text"}]

                            ref @mask1 == PropertyValue[{"M1", "text"}]
                            ref @mask2 == PropertyValue[{"M2", "text"}]
                            ref @mask3 == PropertyValue[{"M3", "text"}]
                            ref @mask4 == PropertyValue[{"M4", "text"}]



            SetPropertyValue[{"siec1", "text"}, BitAnd[okt1, mask1]]
                            SetPropertyValue[{"siec2", "text"}, 2]




                        )
                    ]
            }
            ],
            (***************************************************)
            (***************************************************)
            (***************************************************)
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "Adres sieci:"}],
            {
                Widget["TextField", {"columns" -> 3, "enabled" -> True}, 
       Name -> "siec1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "siec2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "siec3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "siec4"]
            },
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "Adres pierwszego hosta:"}],
            {
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "phost1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "phost2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "phost3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "phost4"]
            },
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "Adres ostatniego hosta:"}],
            {
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "lhost1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "lhost2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "lhost3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "lhost4"]
            },
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "Adres rozgłoszeniowy:"}],
            {
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "brd1"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "brd2"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "brd3"],
                Widget["Label", {"text" -> "."}],
                Widget["TextField", {"columns" -> 3, "enabled" -> False}, 
       Name -> "brd4"]
            },
            Widget["Label", {"text" -> "                        "}],
            Widget["Label", {"text" -> "                        "}],

            (***************************************************)
            (***************************************************)
            Widget["Button", {"text" -> "Zapisz do pliku!",
                BindEvent["action",
                        Script[ZapiszDoPliku[]] 
                     ],
                Script[
                        ZapiszDoPliku[] := (
                            lol123 = 1


                        )
                    ]
            }
            ],
            (***************************************************)
            (***************************************************)


        }, Name -> "Okno"]
   ];
$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Jan 19 '15 at 20:55
  • $\begingroup$ I receive error messages when I run your first two lines of code. PropertyValue needs more arguments: According to the documentation, PropertyValue[{obj,item},name]. Also, do you really mean == in those equations? $\endgroup$ – bbgodfrey Jan 19 '15 at 21:01
  • $\begingroup$ In fact PropertyValue[{"M1", "text"}] has red color, but I can't see any error. I'm using it like in this example . And if I use = I get error Set::write: Tag Times in 255 mask1 is Protected. $\endgroup$ – Kaziu Jan 19 '15 at 21:21
  • $\begingroup$ Your Question does not appear to show all your essential code, so it is difficult to suggest improvements. Also, once I add Needs["GUIKit`"], the error goes away. $\endgroup$ – bbgodfrey Jan 19 '15 at 21:36
  • $\begingroup$ I added whole code. I need to load these 8 values from O1, O2, O3, O4, M1, M2, M3, M4, do some work with them and paste result in other TextFields. Is there any way to do that? $\endgroup$ – Kaziu Jan 19 '15 at 21:46
1
$\begingroup$

Ok, I got it. I can't find simplier method, but this one actually works for me.

I don't create variables for every single TextField. While using BitAnd[] for example I'm doing it this way:

SetPropertyValue[{"siec1", "text"},
                    ToString[BitAnd[ToExpression[PropertyValue[{"O1", "text"}]],
                                ToExpression[PropertyValue[{"M1", "text"}]]]]]

Thanks everyone for help.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.