Hello Guest it is March 29, 2024, 04:03:46 AM

Author Topic: Dialog box - which button pressed  (Read 3572 times)

0 Members and 1 Guest are viewing this topic.

Offline tmead

*
  •  62 62
    • View Profile
Dialog box - which button pressed
« on: February 25, 2011, 12:11:14 PM »
I'm struggling a bit to try to get some code to update a userlabel. Seems there are a few ways of doing this. So far I've found:

Method 1
      Qty = GetUserLabel(61)
      Qty = Question("Enter Quantity of Line " & ThisPriority)
      SetUserLabel(61,Qty)

But there is no way to pick up the current value of the label to use as a default - means the user has to type new every time

Method 2
      Begin Dialog TextBoxSample 16,30,180,96,"Enter Required Quantity"
         OKButton 132,20,40,14
         CancelButton 132,44,40,14
         Text 8,8,32,8,"Text Box:"
         TextBox 8,20,100,12,.TextBox1
      End Dialog

           Dim Dlg1 As TextBoxSample
      Button = Dialog ( Dlg1 )
           
      SetUserLabel ( 61,Dlg1.TextBox1 )

Same problem - I can't figure a way to show the current value, and the user has to click into the field before entering data

Method 3
      Default = GetUserlabel(61)
      Answer = InputBox$("Enter data", "Title", Default, 200, 200)
      SetUserLabel(61,Answer)

Now this one I like - but i can't crack the last bit - how to not update anything when cancel is pressed ! At the moment the contents of the label are wiped if cancel is pressed, and I'd liek them to be left alone !

The Cypress Enable manual is full of detail about how to construct dialogs, but there is a level of assumed knowledge about what to do with the output that I simply don't have !

Tim

Offline tmead

*
  •  62 62
    • View Profile
Re: VB Script Dialog box - determine which button pressed
« Reply #1 on: February 27, 2011, 04:47:35 AM »
Blatant bump for the post !

Does anyone know how to determine which button was pressed in a dialog box ?

Tim

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Dialog box - which button pressed
« Reply #2 on: February 27, 2011, 08:35:39 AM »
Nt sure why the first one doesn't work, but what about this?

      Default = GetUserlabel(61)
      Answer = InputBox$("Enter data", "Title", Default, 200, 200)
      If Answer <> "" then SetUserLabel(61,Answer)
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline tmead

*
  •  62 62
    • View Profile
Re: Dialog box - which button pressed
« Reply #3 on: February 27, 2011, 05:43:21 PM »
Thanks for that, I've just got to a similar result by discriminating between entered data and cancel by using len(answer)>0.

I can't helpfeeling there must be a way of checking which button was pressed, which may be more elegant. However, these ways work !

Help much appreciated.

Tim

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Dialog box - which button pressed
« Reply #4 on: February 28, 2011, 04:33:08 AM »
Tim

Code: [Select]
     Begin Dialog TextBoxSample 16,30,180,96,"Enter Required Quantity"
         OKButton 132,20,40,14
         CancelButton 132,44,40,14
         Text 8,8,32,8,"Text Box:"
         TextBox 8,20,100,12,.TextBox1
      End Dialog

      Dim Dlg1 As TextBoxSample
      Dlg1.TextBox1="Hello world" 'default value
      Button = Dialog ( Dlg1 ) '-1 = ok, 0 = cancel

Ian

Offline tmead

*
  •  62 62
    • View Profile
Re: Dialog box - which button pressed
« Reply #5 on: February 28, 2011, 05:10:40 AM »
Ahh... thanks for that, I'd had a play with something similar, but did not get the syntax right.

I'm still in favour of the inputbox method, as I cannot get the DlgFocus command to allow direct entry into the box without having to click into it. The inputbox command does it for me !

Tim