3
$\begingroup$

I'm pretty new to mathematica and I'd like to create a little program that takes user input as variables which it then uses to do some calculations. I have the following code:

Clear[numcols, nullbitmap]

    DynamicModule[{numcols, nullbitmap},
 Column[{
   InputField[Dynamic[numcols], Number, 
    FieldSize -> {15, {1, Infinity}}], 
   Button[Style["Process"], 
    nullbitmap[numcols_] = 2 + ((7 + numcols)/8)]
   }]]

Print[nullbitmap]

But this doesn't print the result I and it seems that it doesn't take the 'numcols' as a variable in the calculation.

$\endgroup$
  • $\begingroup$ There are several problems with your code, Print is immediate instead of triggered from Button, also nullbitmap[numcols_] = 2 + ((7 + numcols)/8)] looks at least confusing replaced by Print[2 + ((7 + numcols)/8)] should do what you need. I'm encouraging you to go through documentation of DynamicModule, InputField, Button, especially basic examples and applications sections. $\endgroup$ – Kuba Jun 8 '17 at 12:29
1
$\begingroup$

Try this:

Clear[numcols, nullbitmap]

DynamicModule[{numcols, nullbitmap}, 
 Column[{InputField[Dynamic[numcols], Number, 
    FieldSize -> {15, {1, Infinity}}], 
   Button[Style["Process"], nullbitmap = 2 + ((7 + numcols)/8); 
    Print[nullbitmap]]
   }]
 ]

enter image description here

Have fun!

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