How can i write the code to do "When i click cancel in options windows , that field will hide." - field

I have a field in the Notes document , the field name is "reason".
if i click a button,will show a options windows , and the field will show out.
now i need to know how can i write the code to do "when i click cancel in options windows , that field will hide.".
the options windows is PROMPT_OKCANCELLIST.
the following codes is i write in the button:
If uipr.FieldGetText("TRACK_MARK") = "" Then
Call uipr.FieldSetText("TRACK_MARK" , "Y")
End If
askme = ws.prompt(PROMPT_OKCANCELLIST,"Track Reason","Please choose reason..." , data(0) , data())
If askme = "" Then
If uipr.FieldGetText("TRACK_MARK") = "Y" Then
Call uipr.FieldSetText("TRACK_MARK" ,"")
Exit Sub
End If
End If

In the Form with the Reason field, you will need to select the paragraph you wish to hide, then in the Properties box, select Hide paragraph if formula is true, and enter TRACK_MARK="Y" :
This will hide the paragraph once TRACK_MARK is set to "Y".

Related

Call the name of a Texbox with number changing in Visual Basic 6

I'm use Visual Basic 6 to create a table with many Textbox which named txtNo1, txtNo2, txtNo3,...
I want to use the "For...Next..." loop to assign a content to these Textbox.
How can I call all these Textbox in the simplest way?
For i = 1 to 100
txtNo (......) .txt = "ABC"
Next i
Instead of using unique textboxes, each with a unique name, you should use a (textbox) control array:
Place the 1st textbox on the form, name it 'txtNo'
Copy it and paste it onto the form
VB will ask you "There's already a control named 'txtNo'. Would you like to create a control array?". Answer "Yes"
Paste as the textbox as many times as you need it
Then your code looks like
' Control arrays typically start at index 0
For i = 0 to 100
txtNo(i) .txt = "ABC"
Next i
Jim Mack's solution works as well, code for it:
' Assuming your form is named 'Form1'
For each ctrl in Form1.Controls
If TypeOf ctrl Is Textbox
For i = 1 To 100
If ctrl.Name = "txtNo" & CStr(i) Then
ctrl.Text = "ABC"
End If
End If
End If
It's a bit more complex, but therefore more flexible as works with multiple control types (in one loop).
If you need an easiest way to create your textboxes as a table, you can Load the controls at runtime. You have to add only the first TextBox control to your form, set the name to "txtNo", and Index to 0 in the Properties window.
In your code, call Load() to create additional controls, and you can set the Top/Left and other properties
For i = 1 To 100
Load txtNo(i)
txtNo(i).Top = txtNo(i - 1).Top + txtNo(i - 1).Height + 150
txtNo(i).Left = txtNo(i - 1).Left
txtNo(i).Text = "Textbox " & i
txtNo(i).Visible = True
Next i
If you need again to change any control property, from your list of controls, you can iterate only over your control list, instead of all controls of your Form
For i = txtNo.LBound() To txtNo.UBound()
Form1.Controls("txtNo")(i).Text = "New text " & i
Next i

Disable/Enable button based on which control has focus

What I'm trying to do here is loop through the different controls and if any of the controls got focus to disable a button. This is a loop that I used for another task, so I'm kinda basing it off of this...
Dim cControl As Control
For Each cControl In Me.controls
If Not cControl.Container Is framClient Then
If Mid(cControl.Name, 1, 3) = "txt" Or Mid(cControl.Name, 1, 3) = "msk" Or Mid(cControl.Name, 1, 3) = "cbo" Then
'WHAT I'm trying to do here is
'if cControl.gotfocus then
'cmdExit.enabled=false
'end if ' but it barks at me
'cControl.Enabled = False
End If
End If
Next
I didn't make these text boxes in an array and I do not want to go through each text box to see if got focus and do whatever. Please take a look.
In vb6 only one control can have focus: the ActiveControl, so there's no point in looping and asking if the control has focus.
If you need to do something based on whether a certain control with a particular name has focus you could do this:
cmdExit.Enabled = (Me.ActiveControl.Name = "MyTextBox")
If you need to do it based on whether any TextBox has focus:
If TypeOf Me.ActiveControl Is TextBox Then
cmdExit.Enabled = false
Else
cmdExit.Enabled = true
End If
You can go ahead with Subclassing of text boxes as suggested in this SO Post.
As the post suggests, you have to do this exercise for every form where you have this requirement. I think, from your post that you have to do it only for one form.

Setting returned text to open an app in applescript

I have a apple script program that I am programming and I want the text the user sends to open an application, But I keep getting error messages saying "Can't get application {"name_of_app"} of <>. The code I very simple and I cant figure out the problem
set deReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set xpp to text returned of deReturnedItems
set theReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set amt to the text returned of theReturnedItems
set daReturnedItems to (display dialog "Last thing, what should the spam message say?" default answer "" buttons {"Quit", "OK"} default button 2)
set msg to the text returned of daReturnedItems
repeat [amt] times
tell application [xpp]
activate
tell application "System Events"
keystroke [msg]
keystroke return
end tell
end tell
end repeat
Get rid of those square brackets. Don't use them for variables. Use underscores before and after if you must, like:
repeat _amt_ times
…
end
Also, you need to check to make sure your variable is an integer before you use it in the repeat block.
Incidentally, when you set a variable and then include it in brackets, that's applescript syntax for set the string to a list. For example:
set [x, y, z] to "123"
return x
-- returns "1", and y is set to "2", and z is set to "3"

.NET Multiline Textbox Make Shift+Enter working instead of Enter key

I have a Windows Form Multiline Textbox.
I want to use Shift+Enter Instead of using Enter key to make a new line in textbox, and the traditional Enter key will be used to focus on the next control.
I mean Shift+Enter will work exactly like Enter key on normal multiline textbox (Regard to textbox maxlength --> So you cant enter newline, or current selected text will be delete when you insert newline,...)
I've tried to override OnKeyDown, to insert newline on Shift+Enter, but it doesn't work as I expected.
you'll need to override OnKeyDown and check for enter key using the KeyDownEvent's KeyCode property.
If enter was pressed and the keydownevent's modifiers property does not equal Keys.Shift you'll need to suppress the key press. Here's the documentation on how to do that:
http://msdn.microsoft.com/en-us/library/system.windows.forms.keyeventargs.suppresskeypress(v=vs.110).aspx
If shift+enter was pressed you'll need to insert Environment.NewLine at the cursor position, then move the cursor after the inserted Environment.NewLine. Here's how to do that:
How to paste text in textbox current cursor?
Here is my implementation in VB .NET.
Regard to Maxlength of the textbox and current selected text
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If (Me.Multiline AndAlso e.KeyData = (Keys.Shift Or Keys.Enter)) Then
Dim intRemainCharCount As Integer = Me.MaxLength - Me.Text.Length + Me.SelectedText.Length
'' Check if have enough space to place NewLine
If (Environment.NewLine.Length > intRemainCharCount) Then
MyBase.OnKeyDown(e)
Return
End If
Dim intPos = Me.SelectionStart
Me.Paste(Environment.NewLine)
'' Reset selection start (Reset cusor position)
Me.SelectionStart = intPos + Environment.NewLine.Length
e.Handled = True
e.SuppressKeyPress = True
Return
End If
MyBase.OnKeyDown(e)
End Sub
Change the property for Accept Return for the Multiline doesn't even require coding anything, unless you have an event listening to the KeyDown, in which case you can put a condition to check if the Textbox is focussed.

Triggering OK from the call back on GetParm

I am using the IUP.GetParm dialog to do a search and replace prompt.
The dialog supports 3 buttons, the first two OK and Cancel close the prompt and return to the main program flow.
The third button can be tracked in the parm_action function, what I want to do is use the third button to skip the item and close the dialog, but I can't work out if this is possible.
I have asked this on the IUP mailing list but have not yet had a response.
function param_action(dialog,index)
if index == -4 then
bSkip = true
return 1
end
end
bSkip = false
bConfirm,strFromString,strToString,bSkip =
iup.GetParam("Search and Replace",
param_action,
fhGetTag(ptrRecord)..'-'..fhGetTag(ptr)..
' '..fhGetDisplayText(ptrRecord).." %t\n"..
"Replace: "..strBoxType.."\n"..
"With: "..strBoxType.."\n"..
"btn: %u[Ok,Cancel,Skip] \n"
, strFromString,strToString)
if bConfirm and not(bSkip) then
-- replace string
end
To make this function currently you have to press the Skip button and then the Ok button.
Just re-posting the answer from the IUP mailing list here:
Inside the call-back, when the 3rd button is pressed, set the dialog
attribute "status" to "1" and call the function iup.ExitLoop().

Resources