Jump to content
Sign in to follow this  
232showtime

Need help for Hotkey/Excel Read

Recommended Posts

232showtime

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.

#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 by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
JLogan3o13

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   ;==>_iReadAll

BTW, on my machine $iText returns just "Microsoft Excel", so unless your workbook is named "Microsoft Excel.xlsx", you're not going to successfully attach.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
232showtime

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... :'(:'(

 

#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 by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
MikahS

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 ~ getENVvars
My 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

 

Share this post


Link to post
Share on other sites
232showtime

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 graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
MikahS

It's just a variable with a number that gets incremented. Here is an example:

#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

 

  • Like 1

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Share this post


Link to post
Share on other sites
232showtime

@MikahS this is just exactly what i need thank you very much, you gave me a new idea for scripting.... :lmao::lmao::lmao:

thanks again...

 

PROBLEM SOLVED....


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
MikahS

@232showtime My pleasure. :) 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×