InnerHTML at beginning of vbscript function does not take effect immediately - dom

I'm using vbscript within a hta. file to write data to a .docx file. I want some kind of "status monitor" to tell the user when the process has started, when the file has been saved and so on...
Writing to the file works fine, but whatever I do, innerHTML or any DOM change is taking effect way after the file has been saved. After clicking the button it's kind of frozen. I would have supposed the code is executed line by line, but apparently it's not- the question is why and what to do?
VBScript:
Function TextToWord
Document.getElementById("status").innerHTML = "Start writing to doc..."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
Set objDoc = objWord.Documents.Open("file.docx")
Set objRange = objDoc.Bookmarks("Name").Range
objRange.Text = "Some Text..."
objDoc.SaveAs("newfile.docx")
objDoc.Close
End Function
HTML/HTA:
<button class="myButton" onClick="TextToWord()">Word Dokument erstellen</button>
<div id="status"></div>

Related

Setting value for title of NSOpenPanel does not work

I want to set title for my NSOpenPanel, but it does not work! Apple says:
Gets and sets the title for the panel shown at the top of the window.
But I can not make codes works, not sure what is wrong?
let nsOpenPanel = NSOpenPanel()
nsOpenPanel.canChooseFiles = true
nsOpenPanel.title = "Hello, Choose Files"
if (nsOpenPanel.runModal() == .OK) ... // rest of codes ...
The title is something from the past when windows in macOS had title bars. To show text or an instruction on top of the NSOpenPanel object, use the message property:
nsOpenPanel.message = "Hello, Choose Files"

In MS Access VBA determine the next control to have focus

Understanding the order of operations, is there a way for an OnExit or OnLostFocus script to know what control was clicked to take that focus?
I have a form that has a list box from which you have to select an item for the the rest of the data entered into the form to be saved, so that control has the focus when you open the form. If you click on any other control without selecting an item from the list, an OnExit gives you a warning that you haven't made a selection.
The problem that creates is, should you open the form and then decide you don't want it, you get that message when you close the form (either with the close button on the form or the built-in closer).
I would like to be able to tell the OnExit that either the close button has been clicked or the form itself is closing, so don't show the no entries message.
Any thoughts would be appreciated.
Not that I know of.
If your form is rather simple(not to many controls.) Move the warning out of the onExit to a sub. Call it from the other controls when they get focus. But not from the Close button.
Dim bDidUserSelectSomething As Boolean
'In the list box
Private sub ListBox1_Click()
'Do some code here
'Set the flag that they did something
bDidUserSelectSomething = True
End sub
'When you enter the other controls, check if they have done what they should have.
Private Sub TextBox1_Enter()
If bDidUserSelectSomething = False Then
'Warning
End If
End Sub
Consider altering your warning check.
Instead of an OnExit() Event of the listbox, add a validation in all other pertinent controls' BeforeUpdate() events. Usually this event is where validation checks are made.
First, build a general function behind the form that calls your warning:
Public Function WarningMessage() As Boolean
If IsNull(Me.Listbox) Then
Msgbox "Please first select an option in listbox.", vbExclamation, _
"MISSING LISTBOX SELECTION"
WarningMessage = True
Else
WarningMessage = False
End If
End Function
Then call the function to each control:
Private Sub cntr1_BeforeUpdate(Cancel As Integer)
Cancel = WarningMessage
End Sub
Private Sub cntr2_BeforeUpdate(Cancel As Integer)
Cancel = WarningMessage
End Sub
...
As you can see from above, if the listbox is null then the message appears and returns True which is passed back to the control's BeforeUpdate() subroutine to cancel the update.
Now, if there are too many controls to make this doable. Consider hiding all relevant controls in Form's OnCurrent() event except the listbox. When listbox is updated, render the other controls visible. Many softwares and web applications run dynamically like this to prevent users from missing important fields.
Private Sub Form_Current()
If IsNull(Me.listbox) Then
Me.ctnrl1.Visible = False
Me.ctnrl2.Visible = False
Me.ctnrl3.Visible = False
...
Else
Me.ctnrl1.Visible = True
Me.ctnrl2.Visible = True
Me.ctnrl3.Visible = True
...
End if
End Sub
Private Sub listbox_AfterUpdate()
Me.ctnrl1.Visible = True
Me.ctnrl2.Visible = True
Me.ctnrl3.Visible = True
...
End Sub

Easy way to add 'copy to clipboard' to GitHub markdown?

Specifically, I have blocks of code for install that I want the user to be able to quickly copy and paste into a terminal. I'd like a button to 'copy to clipboard' for the code block. Since there's a 'copy to clipboard' button for the git clone URLs, I was wondering if I could piggy back off that or if not whether there was some relatively simple I could add to the MD to make this happen. Or is this simply not possible with the processing and 'safication' the MD text goes through?
The copy button is now a reality (May 2021), as tweeted by Nat Friedman
We just added a "Copy" button to all code blocks on GitHub.
Once copied, you can paste it in a markdown document using Fenced code blocks, to create your code block of your own.
```
function test() {
console.log("notice the blank line before this function?");
}
```
I think that it is not what you want, but if you want to copy, you can do it by running the bookmarklet and adding a copy button.
var copy = function(target) {
var textArea = document.createElement('textarea')
textArea.setAttribute('style','width:1px;border:0;opacity:0;')
document.body.appendChild(textArea)
textArea.value = target.innerHTML
textArea.select()
document.execCommand('copy')
document.body.removeChild(textArea)
}
var pres = document.querySelectorAll(".comment-body > pre")
pres.forEach(function(pre){
var button = document.createElement("button")
button.className = "btn btn-sm"
button.innerHTML = "copy"
pre.parentNode.insertBefore(button, pre)
button.addEventListener('click', function(e){
e.preventDefault()
copy(pre.childNodes[0])
})
})

Problems handling a text_field as clicking on it opens a popup

I have problem entering text in a text_field as when the script tries to enter anything in the field, it throws a popup. When manually entering, it does not throw a popup. The html of the text field is as below.
<input name="txtperc" type="text" value="0" maxlength="3" id="txtperc" tabindex="1" class="textBox valid" data-setfocus="true" onchange="return OnChangePercentAssignment('1','1');" onkeypress="return restrictKeyPress(event);" onpaste="cleanText.Wait(this)" style="width:30px;">
My code =
text_field(:percentage ,:id=>'txtperc')
self.percentage = 100
My guess is that the script tries to clear the text field and that is triggering the pop up to fire.
I also tried
text_field(:percentage ,:id=>'txtperc')
self.percentage = 10
browser.alert.ok
self.percentage = 100
Is there an alternate way to set/type into the text_field?
The application behaviour seems a bit strange. You might have to bypass the input element's event by executing javascript to set the field. This assumes that the event's being fired can be ignored.
You could define the page object as:
class MyPage
include PageObject
text_field(:percentage ,:id=>'txtperc')
def percentage=(value)
execute_script("document.getElementById('txtperc').value = '#{value}';")
end
end
And then input the field as normal:
self.percentage = 100

How do I make PDF the default export option for a Crystal Report?

I am working with CrystalDecisions.CrystalReports.Engine.ReportDocument in WinForms in Visual Studio 2008. Right now when the users click the export button the dialog defaults to saving the report as a CrystalReports formatted file. It's possible to change the selector to PDF, but the specific request that I've been given -- and I've searched for too many hours trying to find -- is to make the 'export report' dialog default to PDF format option.
Does anyone know how to do this?
As of CR XI, the only way I know is to replace the export dialog with your own. You can add your own button to the CrystalReportViewer control and hide their export button.
Here's vb.net code to replace the export button with your own button/eventhandler...
Public Shared Sub SetCustomExportHandler(ByVal crv As CrystalDecisions.Windows.Forms.CrystalReportViewer, ByVal export_click_handler As EventHandler)
For Each ctrl As Control In crv.Controls
'find the toolstrip
If TypeOf ctrl Is ToolStrip Then
Dim ts As ToolStrip = DirectCast(ctrl, ToolStrip)
For Each tsi As ToolStripItem In ts.Items
'find the export button by it's image index
If TypeOf tsi Is ToolStripButton AndAlso tsi.ImageIndex = 8 Then
'CRV export button
Dim crXb As ToolStripButton = DirectCast(tsi, ToolStripButton)
'clone the looks of the export button
Dim tsb As New ToolStripButton
With tsb
.Size = crXb.Size
.Padding = crXb.Padding
.Margin = crXb.Margin
.TextImageRelation = crXb.TextImageRelation
.Text = crXb.Text
.ToolTipText = crXb.ToolTipText
.ImageScaling = crXb.ImageScaling
.ImageAlign = crXb.ImageAlign
.ImageIndex = crXb.ImageIndex
End With
'insert custom button in it's place
ts.Items.Insert(0, tsb)
AddHandler tsb.Click, export_click_handler
Exit For
End If
Next
Exit For
End If
Next
'hide the default export button
crv.ShowExportButton = False
End Sub
Then in the click handler you'd show a customized SaveFileDialog and eventually call the ReportDocument.ExportToDisk method. This way you can set the dialog's title and filename to something useful and of course set the default export type.