Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Help please
#1
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.
#2
Macro Macro2479
Code:
Copy      Help
;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
#3
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

Code:
Copy      Help
#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
#4
if(m5.len = 0) goto error
#5
Code:
Copy      Help
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
#6
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?
#7
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.
#8
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
#9
Macro Macro2486
Code:
Copy      Help
ExcelSheet x.Init
ARRAY(str) a; int i
x.CellsToArray(a "A1:A14")
for i 0 a.len
,out a[0 i]
#10
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?
#11
Macro Macro2487
Code:
Copy      Help
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"
,
#12
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"
#13
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"
#14
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
#15
Also, it is better to use getsel.

'D
str m1.getsel
#16
the m1.trim seems to have sorted it

cheers
#17
Excel likes to add newline when copying a cell with Ctrl+C. Don't know why. But ExcelSheet functions get cells without newline.
#18
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 Smile


Forum Jump:


Users browsing this thread: 1 Guest(s)