Author Topic: User Input from Windows  (Read 423 times)

0 Members and 1 Guest are viewing this topic.

Offline tbohon

  • Paid Subscriber
  • Sr. Member
  • *****
  • Posts: 282
  • Wandering aimlessly in the Forest of Confusion ...
User Input from Windows
« on: November 08, 2017, 10:15:17 AM »
Is there any way (and I'm sure there is, I'm just not looking for the correct terms) to pop up a window, get a value from the user, close the popup and return said value to the main program?  Sort of like INPUTBOX in other languages maybe ... ???

Tnx.
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 912
    • LA2PJ
Re: User Input from Windows
« Reply #1 on: November 08, 2017, 12:06:39 PM »
Hi Tom,

The same challenge came up in another CB project: http://www.ionicwind.com/forums/index.php?topic=6004.0

After the main window is created, a dialog was also created solely for exepting user input by the help of an Edit Control:
Code: [Select]
DIALOG d1,0,0,180,25,@CAPTION,win,"",d1handler
CONTROL d1,"E,,1,1,180,22,0,2"

The same dialog is used for input twice, but here showing just one of them. In the window main loop:
Code: [Select]
case 15 :' New project button clicked
answer = ""
d1text = " ENTER Projectname:"
domodal d1
selectedproject = answer
do: until getkeystate(0x0D) = 0 :' clear keyboard buffer after use of ENTER Key
if selectedproject <> ""
AddProject(win,selectedproject,11)
SendMessage(win,LB_RESETCONTENT,0,0,12)
oldproject = selectedproject
ListItems(win,selectedproject,12)
buffer = ""
setcontroltext win,13,buffer
pcount = GETSTRINGCOUNT(win,11)
SETSELECTED win,11,pcount-1
endif



And finally, here is the dialog handler:
Code: [Select]
'
SUB d1handler
'------------------------------------------------------------------------------------- 
' Handler for the text input dialog
'------------------------------------------------------------------------------------- 
SELECT @CLASS

CASE @IDINITDIALOG
CENTERWINDOW d1
setcaption d1,d1text
setfocus(d1,2)

CASE @IDCONTROL
CASE @IDOK
if GETKEYSTATE(0x0D) :' Enter is pressed
  answer = GETCONTROLTEXT(d1,2)
do: until getkeystate(0x0D) = 0 :' clear keyboard buffer after use of ENTER Key
closedialog d1,0
endif

ENDSELECT
RETURN answer


Both full source for the mentioned project plus a working is posted on the page in the above link. There this code example is used for inputting Project Name and Item Name.
Pleased to see you posting in the CB section.


Good luck!

Egil


« Last Edit: November 08, 2017, 12:10:48 PM by Egil »
Support Amateur Radio  -  Have a ham  for dinner!

Offline GWS

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1492
Re: User Input from Windows
« Reply #2 on: November 08, 2017, 02:10:26 PM »
Hi Tom,

Here's another way, using a dedicated window to accept the data ..
Sorry it's a bit rough - I wrote it quickly ..  ::)

Code: [Select]
' Input Value using a small window

def w,w2:window
def sW,sH,winLeft,winTop,wW,wH:int
def Lat,Long:int
def fm:float
def a$:string

getscreensize sW,sH

' create main display window ...
window w,-sW,0,sW,sH,@sysmenu,0,"Input Test",messages
'set background colour to dark blue ...
setwindowcolor w,rgb(0,20,40)
control w,"B,Exit,(sW-70)/2,0.8*sH,70,30,0,1"

centerwindow w


' create input window and set up home location information screen ...
window w2,-sW,0,0.45*sW,0.36*sH,@MINBOX,0,"Home Latitude and Longitude",InputMessages
setwindowcolor w2,rgb(0,60,190)

control w2,"B,Exit,(600-70)/2,310,70,30,0,100"
getsize w2,winLeft,winTop,wW,wH

HomeSet :' set up the controls of the input window


run = 1

WAITUNTIL run = 0
CLOSEWINDOW w
END

SUB messages
select @class
case @idclosewindow
if w2 then closewindow w2
run = 0
case @idcontrol
select @controlID
case 1
if w2 then closewindow w2
run = 0
endselect
endselect
return

sub InputMessages
select @class
case @idclosewindow
closewindow w2
case @idcontrol
select @controlID
case 100
closewindow w2
case 8 :' Input window Enter Button Pressed
a$ = ltrim$(getcontroltext(w2,4))
Lat = val(a$)
a$ = ltrim$(getcontroltext(w2,5))
Long = val(a$)

FRONTPEN w, 0xffffff

move w,50,100
print w,"Latitude is:   ",Lat

move w,50,150
print w,"Longitude is:   ",Long

closewindow w2

endselect
endselect


return

sub HomeSet
def flag1:int
' set up home location information screen ...

control w2,"T,Please enter your Location,(wW-0.9*wW)/2,0.05*wH,0.9*wW,0.08*wH,@CTEDITCENTER|0x200,1"
setcontrolcolor w2, 1, 0xffffff, rgb(0,10,100)

flag1 = @cteditnumber|@cteditcenter|0x200
control w2,"T,Latitude,80,50,80,30,flag1,2"
control w2,"T,Longitude,300,50,80,30,flag1,3"

setcontrolcolor w2, 2, rgb(0,180,255), rgb(0,10,100)
setcontrolcolor w2, 3, rgb(0,180,255), rgb(0,10,100)

control w2,"E,Edit1,100,100,50,30,flag1,4"
control w2,"E,Edit2,315,100,50,30,flag1,5"

for i = 4 to 5
setcontrolcolor w2, i, rgb(0,0,0), rgb(0,180,250)
next i

control w2,"B,Enter,(wW-70)/2,0.75*wH,70,30,@ctlbtnflat,8"
setcontrolcolor w2, 8, rgb(0,180,255), rgb(0,50,140)

control w2,"T,Degrees,160,100,60,30,flag1,10"
control w2,"T,Degrees,375,100,60,30,flag1,12"

setcontrolcolor w2, 10, rgb(100,200,100), rgb(0,60,190)
setcontrolcolor w2, 12, rgb(100,200,100), rgb(0,60,190)

centerwindow w2

return


Notice that the input Edit boxes have been limited in this example to only accept numbers ..

Best wishes, :)

Graham
« Last Edit: November 08, 2017, 02:13:00 PM by GWS »
Tomorrow may be too late ..

Offline tbohon

  • Paid Subscriber
  • Sr. Member
  • *****
  • Posts: 282
  • Wandering aimlessly in the Forest of Confusion ...
Re: User Input from Windows
« Reply #3 on: November 09, 2017, 09:56:15 AM »
Graham and Egil:  Thanks guys, appreciate the hints.  I've started doing more 'hobby' programming now that my 51 year IS career is winding down (when your boss' boss asks why they're paying you it's just a matter of time before the severance package offer is made ... and I'm going to accept anything reasonable).

So back to the fun of programming with a fun language - Creative Basic!

Again appreciate the help - later!

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)