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$
1
  • $\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, 2017 at 12:29

1 Answer 1

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$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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