2

How do I read input from the user in Smalltalk squeak? Just want to make new variable and initialize it with a number got from the keyboard.

adius
  • 13,685
  • 7
  • 45
  • 46
Yuval Levy
  • 2,397
  • 10
  • 44
  • 73
  • Can you be more specific what smalltalk you are using? – Tobias Apr 08 '14 at 10:52
  • smalltalk in squeak! windows – Yuval Levy Apr 08 '14 at 11:27
  • 1
    It heavily depends on the way you want to do that. Usually, you would do that from within the Squeak environment (the "image"). But of course, it is, in principle, possible to read from `stdin` (although I don't recommend that) or from an `http` request (or similar). So we really need to know, what it is **exactly** that you are trying to accomplish (give us a precise use case). – Max Leske Apr 08 '14 at 15:00

1 Answers1

1

The traditional way is to pop-up a small dialog for entering the input.

FillInTheBlank request: 'enter initial value'.

That did work in st-80 and still works in latest Squeak (4.5). That will answer a String that you can later interpret as you like. Though a modernized way is to request a UIManager:

| answer initialValue |
answer := UIManager default request: 'enter initial value'.
initialValue := Number readFrom: answer ifFail: [self error: 'Sorry, this was not a well formed number'].
^initialValue
aka.nice
  • 9,100
  • 1
  • 28
  • 40