My AutoIt script opens an Excel file and moves it to desktop, but I found a problem if that Excel file was already open, so for that I need to add in my code a condition to pass if Excel file was opened.
My code :
#include<excel.au3>
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '')
If $aResult[1] <> '0000040C' Then
MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & #CRLF & '(0000040C->' & $aResult[1] & ')')
EndIf
EndFunc
HotKeySet("{F2}", "COMP")
Func COMP()
local $var = "C:\Users\Relkassah\Desktop\changment data.xlsx"
local $oExcel_1 = _Excel_Open()
_Excel_BookOpen($oExcel_1,$var)
Sleep(300)
_WinWaitActivate("changment data - Excel","")
Send("{ALTDOWN}{SPACE}m{ALTUP}")
MouseClick("left")
MouseDown("left")
MouseMove(150,444)
MouseUp("left")
Send("{ALTDOWN}{SPACE}{ALTUP}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
EndFunc
While 1
Sleep(1)
WEnd
Check out this function it may help you : https://www.autoitscript.com/autoit3/docs/functions/WinExists.htm
you have to add if statement inside the while loop, Example :
While 1
If WinExists($yourwindow) Then
;do whatever you want here..
EndIf
Sleep(1)
WEnd
this function will return true or false value and while the excel is opened it will keep sending true.
Related
I have a dynamic action doing the below ,
Submit page ,
Successful Alert message,
Log out and redirect to another website (www.google.com),
And I have two required item in page.
When pressed the button and the item is null ,the successful Alert message appears and after that the system shows the error (the item is required). How can I show the successful alert message only when the process and validation are done without errors ,and when ok is pressed in the alert message redirect to website and log out from the sessions
There are different ways you could approach this. You're currently using a mix of Dynamic Actions and page-level validations and processes that aren't going to play well together. I suggest you move all the logic to Dynamic Actions. Here are step by step instructions to do what I think you're trying to do. You can learn from this and then integrate what you want back to your solution.
Create a new blank page. Mine was page 17. You'll need to update references to "P17" with your page number if it's different. Disable the page level attribute Warn on Unsaved Changes to prevent prompts before the redirect to Google.
Add a new HTML region to the page.
Add a new item to the region. Set Name to P17_FIRST_NAME and leave the default Type of Text Field.
Add a new item to the region. Set Name to P17_LAST_NAME and leave the default Type of Text Field.
Add a new item to the region. Set Name to P17_RESULT, Type to Hidden, and Value Protected to No. This item will be used to transfer messages from the server to the client via Ajax.
Add a button to the region. Set Name to RUN_PROCESS and Action to Defined by Dynamic Action.
Create a new Dynamic Action that fires when the button is clicked. The easiest way to do this is to right-click the button and select Create Dynamic Action. Set the Name to RUN_PROCESS clicked.
Select the Show action that was created by default for the Dynamic Action. Set Action to Execute PL/SQL Code and copy-paste the following code into the PL/SQL Code attribute.
declare
l_result_obj json_object_t := json_object_t();
l_errors_arr json_array_t := json_array_t();
l_error_obj json_object_t;
begin
if :P17_FIRST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_FIRST_NAME');
l_error_obj.put('message', 'First Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if :P17_LAST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_LAST_NAME');
l_error_obj.put('message', 'Last Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if l_errors_arr.get_size() > 0
then
l_result_obj.put('status', 'error');
l_result_obj.put('errors', l_errors_arr);
:P17_RESULT := l_result_obj.to_string();
return;
end if;
null; -- do "success" processing here
l_result_obj.put('status', 'success');
l_result_obj.put('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
:P17_RESULT := l_result_obj.to_string();
end;
As you can see, the validations are now being done inside the process. The PL/SQL code is making use of the JSON types introduced with Oracle 12.2. If you're on an older version of the database, you can adapt the code to use APEX_JSON instead.
While still in the Execute PL/SQL Code action, set Items to Submit to P17_FIRST_NAME,P17_LAST_NAME and Items to Return to P17_RESULT. This is how you can transfer values from the page into session state before the process executes and then back to the page after the process finishes executing.
Create a new Dynamic Action that fires on the Change event of P17_RESULT. The easiest way to do this is to right-click the item and select Create Dynamic Action. Set the Name to P17_RESULT changed.
Select the Show action that was created by default for the Dynamic Action. Set Action to Execute JavaScript Code and copy-paste the following code into the Code attribute.
var result = JSON.parse($v('P17_RESULT'));
apex.message.clearErrors();
if (result.status === 'error') {
for (var idx = 0; idx < result.errors.length; idx++) {
result.errors[idx].type = 'error';
result.errors[idx].location = ['page', 'inline'];
result.errors[idx].unsafe = false;
}
apex.message.showErrors(result.errors);
} else if (result.status === 'success') {
apex.message.alert(result.message, function(){
apex.navigation.redirect('https://google.com');
});
}
The JavaScript code takes the result from the process and either displays error messages or an alert. I'm using apex.message.alert instead of apex.message.showPageSuccess because the former supports a callback when the message is dismissed. When the message is dismissed, apex.navigation.redirect takes the user to Google.
Here's what it should look like in the end:
I hope there's enough information here for you to understand what's going on. Let me know if you have any questions. You'll find the documentation for apex.navigation and apex.message here: https://apex.oracle.com/jsapi
P.S. Here's an example of what the PL/SQL code would look like using APEX_JSON.
declare
l_error_count pls_integer := 0;
l_result_obj clob;
begin
apex_json.initialize_clob_output;
apex_json.open_object();
apex_json.open_array('errors');
if :P17_FIRST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_FIRST_NAME');
apex_json.write('message', 'First Name is required.');
apex_json.close_object();
end if;
if :P17_LAST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_LAST_NAME');
apex_json.write('message', 'Last Name is required.');
apex_json.close_object();
end if;
apex_json.close_array();
if l_error_count > 0
then
apex_json.write('status', 'error');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
return;
end if;
null; -- do "success" processing here
apex_json.write('status', 'success');
apex_json.write('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
end;
if command == "dir" then
local filelist = fs.list("")
for _, file in pairs(filelist) do
if fs.isDir(file) == true then
term.setTextColor(8)
print(file)
term.setTextColor(colors.yellow)
else
term.setTextColor(1)
print(file.." "..fs.getSize(file))
end
end
end
this is the code i have it goes through each item and then prints the item and if its a file it prints how big the file is and it changes the text color depending on if its a directory or not but i also want the directory's to be at the top but i dont know how to do that so i need some help
if command == "dir" then
local filelist = fs.list("")
for _, file in pairs(filelist) do
if fs.isDir(file) == true then
term.setTextColor(8)
print("- "..file)
term.setTextColor(colors.yellow)
end
end
for _, file in pairs(filelist) do
if fs.isDir(file) == false then
term.setTextColor(2)
print("- "..file.." "..fs.getSize(file).." bytes")
term.setTextColor(colors.yellow)
end
end
end
i did it
I had read lots of pages on AHK but haven't found any that explains how to make a script that enables me to replace "for" when it's typed by the following:
for(int i=0;i<CONDITION;i++)
{
}
I would like it to set cursor focus on inside the brackets to start writing the loop-code right away.
Here is what I have came up until now:
::for::for(int i=0;i<CONDITION;i++),
{,
,
}
Should replace "for" with the code at top of the post but gets the following error:
Error at line 2.
linetext: ,,
Error: this line does not contain recognised action.
The program will exit.
A hotkey (or hotstring) that executes more than one line must list its first line beneath the hotkey (or hotstring).
https://autohotkey.com/docs/FAQ.htm#autoexec
Comma, semicolon, and other characters such as {}^!+# have special meaning in AHK and need to be escaped in order to be interpreted differently than it normally would.
https://autohotkey.com/docs/commands/_EscapeChar.htm
::for::for(int i=0`;i<CONDITION`;i`{+`}`{+`})`n`{`{`}`n`n`{`}`}{Up}
The easiest way to send such a text is this:
; #If WinActive("ahk_class Notepad")
::for::
ClipSaved := ClipboardAll ; save clipboard
clipboard := "" ; empty clipboard
clipboard = ; send this text to the clipboard:
(
for(int i=0;i<CONDITION;i++)
{
}
)
ClipWait, 1 ; wait for the clipboard to contain data
Send, ^v
Send, {Up}
clipboard := ClipSaved ; restore original clipboard
return
; #If
Also fairly simple is this approach, which works well in Scite and Notepad++ which handles tabbing automatically:
::for::
SendRaw,
(
For(int i=0;i<CONDITION;i++)
{
}
)
Send, {Up}{End}
return
I am looking to populate a list box when a check box is ticked and empty it when the tick is removed.
This code worked for this function in my previous modules but now I am getting an error (im guessing it is with the arguments for Range), and I would like to understand why. Additionally, the list box remains as it is when the checkbox is unticked.
Here is my code:
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
ListBox1.List = Sheets("DATA").Range("C22").Value
Else
ListBox1.ListFillRange = ""
End If
End Sub
Try this:
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Me.ListBox1.AddItem Sheets("DATA").Range("C22").Value
Else
Me.ListBox1.Clear
End If
End Sub
Changing your code to this:
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
ListBox1.ListFillRange = "C22:C24"
Else
ListBox1.ListFillRange = ""
End If
End Sub
will change the listbox to show the contents of cells C22:C24.
I am trying to find a process by which to edit and write to a resource .rc file; I attempted to use the sample code listed at
How to increment values in resourse file by using vbscript but the last line in both samples returned the same error ( fso.OpenTextFile(rcfile, 2).Write rctext ) :
Error: Invalid procedure call or argument
Code: 800A0005
Source: Microsoft VBScript runtime error
I modified the script to write out to a .txt file and that worked fine, but I'm baffled as to what may be causing the problem writing out to a .rc file.
From the linked sample (simplified)
rctext = fso.OpenTextFile(rcfile).ReadAll
rctext = ....
fso.OpenTextFile(rcfile, 2).Write rctext
The idea is read all the file, and as far as there is no variable holding a reference to the opened file, it is closed, then change what needs to be changed and open again the file, now for writing, and write the changed content to file
And, usually, it works. But sometimes the file opened for reading is not closed fast enough to later open it for writing.
To ensure the file is closed and then can be opened for writing, change the reading code to
set f = fso.OpenTextFile(rcfile)
rctext = f.ReadAll
f.Close
As your line
fso.OpenTextFile(rcfile, 2).Write rctext
does three things (access fso, open file, write to it), there are many things that could go wrong. Please see this answer for ideas wrt to problems concerning the first two actions. Another answer concerns the write.
In your case, the evidence - works with a.txt, but not with b.rc - makes it highly improbable that the file's opening is to blame (so .Close won't save you). I suspect that the .rc contains Unicode (UTF-8/UTF-16) data that the textstream can't encode.
So either use the unicode parameter to read/write open the file with UTF-16 encoding or an ADODB.Stream for UTF-8.
It seems that the answer to my question required both of your answers(#MC ND and #Ekkehard.Horner); also, once I changed the vbs script to open and write to the .rc file in Unicode, which I'm not sure why I have to, the script was able to execute without error.
Here is the vbs script in it's final form:
Const ForReading = 1, ForWriting = 2
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Const DoNotCreate = false
rcFile = "C:\Path\To\RC\File.rc"
major = 4
minor = 3
maint = 2
build = 1
version = major & "," & minor & "," & maint & "," & build
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileObj = fso.OpenTextFile(rcFile, ForReading, DoNotCreate, TristateTrue)
rcText = fileObj.ReadAll
fileObj.Close
Set regex = New RegExp
regex.Global = True
regex.Pattern = "(PRODUCTVERSION|FILEVERSION) \d+,\d+,\d+,\d+"
rcText = regex.Replace(rcText, "$1 " & version)
regex.Pattern = "(""(ProductVersion|FileVersion)"",) ""\d+, \d+, \d+, \d+"""
rcText = regex.Replace(rcText, "$1 """ & Replace(version, ",", ", ") & """")
Set fileObj = fso.GetFile(rcFile)
Set textStream = fileObj.OpenAsTextStream(ForWriting, TristateTrue)
textStream.Write rcText
textStream.Close
The only thing that does not seem to work is the regex for replacing the ProduceVersion|FileVersion values, but hopefully I can hammer that out within a reasonable time.