code that will show a message box after inserting data on the last cell of a column in datagrid. my program runs like this, when i click a button, a value will be added to the first cell then will triggered rs.MoveNext, when i click again the button the same process takes place, the problem is that when i reach the last cell and click the button again, the data i put on the last cell just replace with the new one. please help me with a code that will stop rs.MoveNext if i reach the end of file.
Try using MsgBox "Finished" without using the brackets ("").
Related
Ok so here's what I want to know.
I am making a GUI for roblox and I want too know how to make this button
interact with this textbox so what ever value is in the text box thats what will change when you hit the button
Here's the code to change the values
v.leaderstats1.Level.RobloxLocked = true
v.leaderstats1.Level.Value = 98000
And heres the code for the mousebutton click
LevelButton.MouseButton1Click:connect(function()
end)
So how do I combine this into 1 code so I can type a " value " like (3799)
and hit the button and it works?
any my text box is LevelBox.Name
I'm using Excel 2016 on my Mac (v10.11) and currently working on a table for the accounting of my company. It contains two sheets: On the first sheet I list up some costs and give them a projectnr. These costs get copied and pasted on the second sheet. The projectnrs get copied in a protected column, where I need to delete all duplicates. I want to automate this process. if you click on a button on the first page, the rest of the game will be done by itself.
For this, I wrote a VBA function like this:
Option Explicit
Sub Copy()
ThisWorkbook.Worksheets("FirstTable").Range("R21:R84").Copy
ThisWorkbook.Worksheets("SecondTable").Cells(3, 26).PasteSpecial xlPasteValues
ThisWorkbook.Worksheets("SecondTable").Activate
ThisWorkbook.Worksheets("SecondTable").Range("Z:Z").RemoveDuplicates Columns:=1, Header:=xlYes
ThisWorkbook.Worksheets("FirstTable").Activate
ActiveWorkbook.Save
Call Print
End Sub
The problem is that the method RemoveDuplicates does not work on mac! I've tested it on windows and everything works well. Does anyone know what the reason for this could be?
If I mark the column on my own and click on remove duplicates in the data tab, it works, but not with this macro.
I found the reason why it doesn't work:
On mac it pops up a dialog, which you need to confirm. If you don't hit the confirm button, the duplicates won't be removed. After I call the RemoveDuplicates function, I switch to the FirstTable by calling ThisWorkbook.Worksheets("FirstTable").Activate. The dialog disappears and the duplicates are not deleted.
On windows there is no dialog, thats why it works.
UPDATE3 - SOLVED with reservations, please see my solution below; leaving it open since the cause of the problem is unclear, and I don't know how robust the solution is.
UPDATE1: here's the short short version.
Currently, after .setEditText on a QComboBox, I get this:
so the next thing you type will overwrite 'Team '.
But the desired effect is this (unhighlighted / unselected), so that the next thing you type will be appended to 'Team ' instead of overwriting it:
Thanks for any help. The rambling details are below, which is the original post:
(this is all PyQt 5.4)
UPDATE2:
Apparently python doesn't think anything is actually selected:
self.entryForm.ui.teamField.lineEdit().setText("Team ")
print("selected text:"+self.entryForm.ui.teamField.lineEdit().selectedText())
prints "selected text:" and nothing else. To make sure that's working:
self.entryForm.ui.teamField.lineEdit().setText("Team ")
self.entryForm.ui.teamField.lineEdit().setSelection(0,4)
print("selected text:"+self.entryForm.ui.teamField.lineEdit().selectedText())
prints "selected text:Team"
So that might be why many of the methods that affect selection are not working as expected (.deselect(), .setSelection(5,5), etc, and even some of the other methods give unexpected behavior, i.e. cursorForward(False,1) or cursorBackward(False,1) and such.
Original post:
This is for a radio log GUI, so keyboard interactions must be minimal and intuitive. openNewEntryForm (below) is called as a slot from a pushbutton on the main application GUI window:
self.ui.pushButton.clicked.connect(self.openNewEntryDialog)
It can also be called using a keyPressEvent in the same class:
def keyPressEvent(self,event):
if type(event)==QKeyEvent:
print("QKeyEvent:"+str(event.key()))
if event.key()==Qt.Key_T:
self.openNewEntryDialog('t')
event.accept()
else:
event.ignore()
Here's the method in question:
def openNewEntryDialog(self,key=None):
self.entryDialog=newEntryDialog()
if key=='t':
self.entryDialog.ui.to_fromField.setCurrentIndex(1)
self.entryDialog.ui.teamField.setFocus()
self.entryDialog.ui.teamField.setEditText("Team ")
if self.entryDialog.exec_():
self.newEntry(self.entryDialog.getValues()) # adds the log entry
so, the intended key press sequence is (from the main application GUI window):
a single keyboard press of 't' will open the entryForm, set the to_fromField to index 1 (which happens to be "TO"), give focus to teamField (also a QComboBox), set its text to "Team " and set itself up so that the very next keypress will appear as the text following "Team " in teamField.
So, starting from the main app GUI again, the plan is that typing 't3' should open the new entry window, set the to_fromField to "TO", and set the teamField to "Team 3", ready for a keypress of the tab key to move on to the next field in the entryForm.
The problem is that the teamField.setEditText("Team ") call leaves all of the text highlighted/selected, so that a subsequent key press of '3' would replace "Team " with "3"; I'm looking for a way to unhighlight/unselect "Team " but leave the cursor active at the right of that string, so that the subsequent key press of '3' would make the entire string "Team 3".
Ideas? Thanks in advance.
You can access the line-edit of the combo box, and then remove the selection:
self.entryDialog.ui.teamField.setEditText("Team ")
self.entryDialog.ui.teamField.lineEdit().deselect()
UPDATE:
The above code is correct, but it seems that the dialog will then clobber it when it initialises the focus handling for its child widgets after it is shown. If a dialog is opened with exec(), it will start its own event-loop, and some events (including focus events) will only be processed after it is fully shown. This is why it may appear that some changes made to child widgets before the dialog is shown are being ignored.
One way to work around this is to use a single-shot timer to ensure the changes are only attempted after the dialog is shown.
So add a method to the entry dialog class something like this:
def resetUI(self, key):
if key == 't':
self.ui.to_fromField.setCurrentIndex(1)
self.ui.teamField.setFocus()
self.ui.teamField.setEditText('Team ')
QtCore.QTimer.singleShot(0, self.ui.teamField.lineEdit().deselect)
and then use it like this:
def openNewEntryDialog(self, key=None):
self.entryDialog = newEntryDialog()
self.entryDialog.resetUI(key)
if self.entryDialog.exec_():
self.newEntry(self.entryDialog.getValues())
SOLVED with reservations, see UPDATE3 in the original post.
So, with the initial text all highlighted, tests show that it didn't actually think anything was selected. This solution was just stumbled upon by trial and error, fiddling with setting and clearing focus, selecting text and trying deselect:
def openNewEntryDialog(self,key=None):
self.entryForm=newEntryDialog()
if key=='t':
self.entryForm.ui.to_fromField.setCurrentIndex(1)
self.entryForm.ui.teamField.lineEdit().setFocus()
self.entryForm.ui.teamField.lineEdit().setText("Team ")
self.entryForm.ui.teamField.lineEdit().setSelection(5,1)
Notice there are two spaces after 'Team' and the second one is intentionally selected. Then the very next keypress will overwrite that second space; that is basically the desired behavior.
Anyway it looks like something bizarro with the selection scheme; one way to look at this is that the highlight isn't really a selection, but, if you set a valid real selection then it will override the original highlighted 'pseudo-selection'. The original highlighting behaves like a selection in that a keypress will replace everything that's highlighted, but, not like a selection in that the selection methods reveal that there is no 'selection', see UPDATE2 in the original post.
Can anyone help explain this behavior? I'd like to build some more confidence in it before accepting this coincidental answer.
Thanks
I'm trying to build a protected worksheet where one of the cells has the following qualities:
Double-clicking the cell populates it with "hello".
The cell can only be blank or contain the word "hello".
So I decided to put validation on the cell, and write a worksheet_beforeDoubleClick() event.
Let's say it's cell A1. Starting with a blank worksheet, in B1 I enter "hello", and I set A1's validation as a list with range B1:B2.
My double-click event code is as follows:
Private Sub worksheet_beforedoubleclick(ByVal Target As Range, Cancel As Boolean)
If Target.Row = 1 And Target.Column = 1 Then
Target.Value = "hello"
End If
End Sub
This code and validation works fine while the sheet is unprotected; the cell populates with "hello" when double-clicked.
However, once the sheet is protected, double-clicking on cell A1 turns the mouse pointer into an hourglass until I press Esc or click on another cell; the cell does not populate with the word "hello".
Any idea what's going on?
When you protect the sheet, check the "Edit Objects" checkbox and it will work. Don't know quite why, but it will.
Thanks Doug for a lead in the right direction. For future reference, a good VBA snippet for this is:
ActiveSheet.Protect UserInterfaceOnly:=True, DrawingObjects:=False
This will protect the sheet, but allow macros to edit the sheet, as well as clear up the conflict described here.
While the answers above with unprotecting the drawing objects works, the end solution with respect to the user being able to right click and edit drawing object shapes is not always acceptable.
My work around was to use a checkbox to the left of the cell and add a macro that did what my double click action originally was doing.
I have a need to run different code when a user clicks or double-clicks an item in a VB6 ListBox control. When I click on the control, the Click event handler executes. However, I am finding that when I double-click on the control, both the Click and DblClick event handlers execute.
Anyone have a good solution for getting just the DblClick event handler code to run without the Click code being executed first?
Thanks in advance for any suggestions.
A slight hack, but you could use a Timer control and a boolean variable:
Start the timer on the Click event, set the boolean variable to false
Set the boolean variable to true on the DoubleClick event
When the timer Tick event fires, check the boolean variable to see if the user did a Click or DoubleClick
I'd recommend setting the timer interval to the Windows double click time setting, plus a bit (There should be a Windows API call that will give you this value).
The behavior of the list control in Visual Basic 6 is as follows.
When you click on an item the click event is fired.
When you click on the SAME item the click event is still fired.
When you double click on the item both the click event and double click event are fired.
Note #2. What you need to do is have a current item in the form you working with. Every time the click event is checked you first see if the current item is the same item as what you clicked. If it is NOT the same item you process the click event normally.
If you double click on a NEW Item then the user is doing two things at the same time. Selecting a new item and performing the double click item. In this case the click is fired first then the double click.
This sequence is no different than if the control did what you wanted it to. It is the same as if you clicked on a new item wait X second then double click the same item.
If your click event involves handing off the task to a ActiveX EXE and immediately terminating or setting data to be processed later by a background timer. Then you need to have a semaphore or a flag to indicate when the process spawned by the click event is done. The Double Click event won't be processed until the semaphore is cleared.
If you have additional details my answer can be more specific. The following is some code you can run to see the List Box in actions. Create a Form and add three items to the list. Then add the below code.
Private Sub List1_Click()
Print "Clicked - " & Me.List1.List(Me.List1.ListIndex)
End Sub
Private Sub List1_DblClick()
Print "Double Clicked - " & Me.List1.List(Me.List1.ListIndex)
End Sub
Do the following steps
Click on Item #1
Click on Item #2
Click on Item #2 again
Double Click on Item #2
Double Click on Item #3
You will see the various combination of actions occurring.