Posts: 12
Threads: 2
Joined: Feb 2015
Basically, I've had some time away from the coding world and apparently my knowledge has gone (for now...)
I'm trying to get QM to go to a cell in one excel doc, copy the value, then do a check to make sure its not blank, if its blank the macro will end, if not it will paste into a seperate file?
Nice and easy one for whatever reason I cant get my head round it.
Posts: 11,922
Threads: 138
Joined: Dec 2002
Macro
Macro2479
;Example.
;At first open both files in Excel.
;Edit file names in this macro to match what is displayed in Excel title bar for each file.
;Then run this macro.
ExcelSheet A B ;;variables
A.Init("" 0 "Book1.xls") ;;connect to the first open file
B.Init("" 0 "Book2.xls") ;;connect to other open file
str s=A.Cell("A1") ;;get cell
if s.len ;;if not empty
,out s ;;display in QM
,B.SetCell(s "C10") ;;set cell in other file
Posts: 12
Threads: 2
Joined: Feb 2015
Ah ok this is down a different route to what I had initially mean sorry.
I've got a table which houses staff names and then runs a macro in another prograam (already made and made) when it realizes which name is selected. the names will change on weekly basis so I had initially thought of something like
#region Recorded 22/04/2015 13:12:30
int w1=act(win("Book 2.xlsx - Excel" "XLMAIN"))
setting my str variables
str m1
str m2
str m3
str m4
str m5
str m6
str m7
copies the 7 boxes i need
lef 136 251 w1 1 ;;EXCEL7 'Book 2.xlsx'
'D Cc
m1.getclip
'D Cc
m2.getclip
'D Cc
m3.getclip
'D Cc
m4.getclip
'D Cc
m5.getclip
'D Cc
m6.getclip
'D Cc
m7.getclip
if m5 = ""
goto error
Basically if one of the boxes is blank I want it to skip to another part in the macro/ I know this isnt efficient coding but i like to start at basic and build on it ha
Posts: 11,922
Threads: 138
Joined: Dec 2002
if(m5.len = 0) goto error
Posts: 12
Threads: 2
Joined: Feb 2015
str m1=m1.getclip
if(m1.len = 0)
out "SUCESSS"
else
out "failed"
Doesnt matter if m1 is empty or has a value, the out is the same
Posts: 12
Threads: 2
Joined: Feb 2015
Actually is there something wrong with my QM? I run the following simply macro
int i
if i=10
out "i is 10"
else
out "i is not 10"
and the data that is 'out''d says "i is not 10" when it clearly is?
Posts: 11,922
Threads: 138
Joined: Dec 2002
str m1.getclip
out m1.len
if(m1.len = 0)
out "empty"
else
out "not empty"
if i=10
does not assign 10, just compares.
Posts: 12
Threads: 2
Joined: Feb 2015
Hi sorry to be a pain but I simply cant figure out the best way of essentially doing the following.
I have a list in Excel, I want QM to run through the list and perform a specific action depending on what the item in the list is, i know ill need to create an array with the possibile items but how do i get QM to differentiate between the items?
For example.
if item1 = "run"
mac "run"
if item2 = "walk"
mac "walk"
My array will consist of around 14 items with a number of different macros, I can write it the long winded way but itll be very messy.
Thanks
Posts: 11,922
Threads: 138
Joined: Dec 2002
Macro
Macro2486
ExcelSheet x.Init
ARRAY(str) a; int i
x.CellsToArray(a "A1:A14")
for i 0 a.len
,out a[0 i]
Posts: 12
Threads: 2
Joined: Feb 2015
The array bit i understand mate, its the part below i dont get
if a1 = "hello"
mac "hello"
if a2 = "failed"
run "notepad.exe"
The part im struggling on is getting the Macro to identify whats been caputred and run the corresponding macro from that?
Posts: 11,922
Threads: 138
Joined: Dec 2002
Macro
Macro2487
str a1 a2
a1="hello"; a2="failed"
if a1 = "hello"
,mac "hello"
if a2 = "failed"
,run "notepad.exe"
;to compare single variable with multiple strings better use sel/case:
sel a1
,case "hello"
,mac "hello"
,
,case "failed"
,run "notepad.exe"
,
Posts: 12
Threads: 2
Joined: Feb 2015
Right im convinced this isnt me and there is a bud or something with my QM
Ive the following
int w1=act(win("Port Requirements - Master.xlsx - Excel" "XLMAIN"))
lef 138 235 w1 1 ;;EXCEL7 'Book 2.xlsx'
'D
'Cc
str m1.getclip
if(m1 = "test")
mes "yes"
else
mes "no"
Even though the correct sell is selected and m1 does definitely equal "test" no matter what I still get the mes "yes"
Posts: 12
Threads: 2
Joined: Feb 2015
loughy Wrote:Right im convinced this isnt me and there is a bud or something with my QM
Ive the following
int w1=act(win("Port Requirements - Master.xlsx - Excel" "XLMAIN"))
lef 138 235 w1 1 ;;EXCEL7 'Book 2.xlsx'
'D
'Cc
str m1.getclip
if(m1 = "test")
mes "yes"
else
mes "no"
Even though the correct sell is selected and m1 does definitely equal "test" no matter what I still get the mes "no"
Posts: 11,922
Threads: 138
Joined: Dec 2002
To debug, insert this after str m1.getclip:
out F"|{m1}|" ;;should show |test| in QM output
If it shows blank characters after or before test:
m1.trim
Posts: 11,922
Threads: 138
Joined: Dec 2002
Also, it is better to use getsel.
'D
str m1.getsel
Posts: 12
Threads: 2
Joined: Feb 2015
the m1.trim seems to have sorted it
cheers
Posts: 11,922
Threads: 138
Joined: Dec 2002
Excel likes to add newline when copying a cell with Ctrl+C. Don't know why. But ExcelSheet functions get cells without newline.
Posts: 12
Threads: 2
Joined: Feb 2015
Cool, still need to figure out how do a search to see if the value that was set for m1 is in my array.
I'll figure it out somehow