Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can I call a function from a menu, pass a argument then run?
#1
Hi Gintaras,

I think I'm going nuts...

This line used in a menu works to open Explorer with only the C:\ drive listed.

c: :run "Explorer" "/e, /root, C:\"

So I wanted to do a menu with the paths I use most and figured using a function to build and execute the run statement would be most efficient. I realize it's probably NOT the best way now that I've looked at it but I'd still like to know what I'm doing wrong.

I figured out how to call the function from a menu and pass the path as a variable but I can not for the life of me build a run statement that works.

Here's what I've got.

The menu:

Code:
Copy      Help
c: :str drive="c:\''"; ExploreOnly2(&drive)

Is there any way to send the path itself without having to plug it into a variable? Couldn't figure that one out either. Kept getting syntax errors if I used variations of:

Code:
Copy      Help
c: :ExploreOnly2("C:\")

and my function ExploreOnly2

Code:
Copy      Help
/
function str&drive
str s="''explorer'' "
str so="''/e, /root, "
run str'z.from(s so drive)

I've tried every combination of with quotes, without quotes, w/spaces, w/o spaces...It's killing me. Even if I hard code the path within the function into str'so I can seem to concatenate a run statement that works.

Any Ideas?
#2
With run, program name and command line must not be in the same string. Quotes are not used.

Code:
Copy      Help
c: :ExploreOnly2("c:\")

Code:
Copy      Help
;/
function $drive

str s.from("/e, /root, " drive)
run "explorer" s

Quote:"Explorer" "/e, /root, C:\"
It would be single string in C++, but two strings in QM.
#3
So I was getting the syntax errors because I was using &drive and not $drive?

I'm so not worthy...
#4
There are several ways to pass strings to functions.

1. Function begins with

function lpstr's

(or function $s, because $ is shortcut for lpstr). Then you can pass any string. If you accidentally try to pass a number, you get error. I use this in most functions. But if you don't know what is lpstr and how to use it, use method 2, or within the function assign s to a str variable.

2. Function begins with

function str's

(or function ~s, because ~ is shortcut for str). Then you can pass any string or number. Numbers are automatically converted. Advantages: easiest, does not require knowledge about lpstr; can be manipulated using str functions without at first storing to a str variable. Disadvantages: whole string is copied, which is slower and in case of large strings requires much memory; not error if you accidentally pass a number.

3. Function begins with

function str&s

(or function ~&s). Then you must pass a str variable. The function can modify the variable. Usually used to return values (instead of using ret).

Also can be used str*s. Similar to 3, but requires knowledge about working with pointers.
#5
I didn't realize I wasn't declaring the right type argument in the function statement.

A few of the examples I was looking at used str& in the function statement and I was thinking that was the syntax.

I thought using lpstr would just pass the pointer to the function (which it does, I get that) not getting the fact that, that is all the function needs to be able to read the variable.

It makes sense now why I've seen you recommend using lpstr if str is not needed. As long as you don't need to access and modify the string, lpstr smaller in memory.

str must be used when not sure if string will be text or numeric and when you need to modify the string or want to use properties of type str.

str& is used when you need to pass a variable

And I don't know a damn thing about str* can you direct me to the right help pages?

Also could you suggest the best course of study since there really is no "How to program in QM" What's the closest thing C++?
#6
Quote:A few of the examples I was looking at used str& in the function statement and I was thinking that was the syntax.

I understand. I'll make corrections in help files.

Quote:And I don't know a damn thing about str* can you direct me to the right help pages?

"pointer, reference, array" topic. Read it only if you really need to use pointers somewhere.

Quote:Also could you suggest the best course of study since there really is no "How to program in QM"

All is in QM help, including "Programming in QM" topic.

Quote:What's the closest thing C++?

QM is not very close to C++ or other languages. From C++ it borrows pointers, references, similar string usage (LPSTR=lpstr, CString=str), ability to use any types, dll functions, system interfaces, and maybe more.
#7
Thanks G-man you're the best!

Most of the examples I was looking at were in the QM folders. I wasn't finding what I was looking for in the help files but I'm finding it today. Go figure. 8) I'm finding pages I have not seen before. Printed a bunch out as well. I can see everything is in the help files but they do seem to expect a certain level of knowledge to fully understand all the concepts. I'll get it.

BTW the "newer" looking pages in the help files look great on my LCD. Just got a new driver update with a new setting and man those pages look crisp. Very easy to read.

Thanks again for all your time Gintaras.


Forum Jump:


Users browsing this thread: 1 Guest(s)