232showtime Posted May 21, 2015 Share Posted May 21, 2015 (edited) Good day,in this script I used 3 Hotkeys, How do I read A1, A2 and A3 using single hotkey?like if I press F1 it will read _iReadA1, if I Press F1 again it will read _iReadA2, if I Press F1 again it will read _iReadA3 and if I Press F1 again it will read the first function, _iReadA1 again and so on.. need help dont know which command to use.expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> HotKeySet("{F1}", "_iReadA1") HotKeySet("{F2}", "_iReadA2") HotKeySet("{F3}", "_iReadA3") While 1 Sleep(10) WEnd 1 Func _iReadA1() Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA1 Func _iReadA2() Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A2") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA2 Func _iReadA3() Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A3") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA3 Edited May 21, 2015 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 21, 2015 Moderators Share Posted May 21, 2015 Didn't invest a lot of time reading the help file examples, did you? If you read a single cell it is returned as a string, if you read a number of cells, it is returned as an array. Try this:#include <Array.au3> #include <Excel.au3> HotKeySet("{F1}", "_iReadAll") While 1 Sleep(10) WEnd Func _iReadAll() Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1:A3") _ArrayDisplay($sResult) EndFunc ;==>_iReadAllBTW, on my machine $iText returns just "Microsoft Excel", so unless your workbook is named "Microsoft Excel.xlsx", you're not going to successfully attach. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
232showtime Posted May 21, 2015 Author Share Posted May 21, 2015 (edited) Good day @JLogan3o13 thanks for the reply, i tried your script and it works fine, but what I want to achieved is read the cell one by one using a single hotkey, its like a loop, If I press F1 it will read first function, then if I press F1 again it will jump to 2nd function, then if I press F1 again it will jump to 3rd function, and if I press F1 again it will jump to 1st function, is this possible??? im stuck, please help... expandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> HotKeySet("{F1}", "_iReadA1") HotKeySet("{F2}", "_iReadA2") HotKeySet("{F3}", "_iReadA3") While 1 Sleep(10) WEnd 1 Func _iReadA1();1st function Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA1 Func _iReadA2();2nd function Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A2") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA2 Func _iReadA3();3rd function Local $sText = WinGetTitle("[CLASS:XLMAIN]") $iText = StringLeft($sText, 16) Local $sWorkbook = $iText & ".xlsx" $oWorkbook = _Excel_BookAttach($sWorkbook, "filename") Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A3") MsgBox(0, "", $sResult) EndFunc ;==>_iReadA3 Edited May 21, 2015 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
MikahS Posted May 21, 2015 Share Posted May 21, 2015 Why not just make a counter and a switch statement that executes the next function you want based off the counter number? Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
232showtime Posted May 21, 2015 Author Share Posted May 21, 2015 hi @MikahS kind of confused with your counter, and searched the help file no command for counter,you mean something like this or could you give me a little bit of example???$iCount = 0 Do _Callsomefunc() $iCount += 1 Until $iCount = 6; ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
MikahS Posted May 21, 2015 Share Posted May 21, 2015 It's just a variable with a number that gets incremented. Here is an example:expandcollapse popup#include <GUIConstants.au3> HotKeySet("{F1}", "Example") Local $counter = 0 While 1 WEnd Func Example() Switch $counter Case 0 MsgBox(0, "Test", "You have run the function for the first time!") $counter += 1 Case 1 extFunc1() $counter += 1 Case 2 extFunc2() $counter += 1 Case 3 extFunc3() $counter += 1 Case Else MsgBox(0, "Test", "You've run through my examples already!") Exit EndSwitch EndFunc Func extFunc1() MsgBox(0, "Test", "We are in extFunc1!") EndFunc Func extFunc2() MsgBox(0, "Test", "We are in extFunc2!") EndFunc Func extFunc3() MsgBox(0, "Test", "We are in extFunc3!") EndFunc 232showtime 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
232showtime Posted May 22, 2015 Author Share Posted May 22, 2015 @MikahS this is just exactly what i need thank you very much, you gave me a new idea for scripting.... thanks again... PROBLEM SOLVED.... ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
MikahS Posted May 22, 2015 Share Posted May 22, 2015 @232showtime My pleasure. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now