Sign in to follow this  
Followers 0
kkk

Simple Problem: Command Line Parameter Value

13 posts in this topic

Hi

I have problem, probably it is very simple, but I started with autoit few days ago, and I tried to solve this problem ... but :think:

Simple description:

3 Command line parameter exist: $CmdLine[1] - $CmdLine[3]

An excel-file is selected by the script.

The $CmdLine[1] ist a parameter which shall be written to the selected excel cell.

Problem: the string "$CmdLine[1]" is written into the cell, but not the value of $CmdLine[1].

Can some please help me?

Thanks in advance!

kkk

Code:

WinActivate ("Microsoft Excel - Template-parallel")

WinWaitActive ("Microsoft Excel - Template-parallel", "", 60)

; Select Cell

MouseClick ("", $CmdLine[2], $CmdLine[3])

Sleep (2)

;Send the value in $CmdLine[1] to the selected cell

Send (" " & $CmdLine[1])

;ClipPut(& $CmdLine[1])

Share this post


Link to post
Share on other sites



Hi,

works fine for me.

If $CmdLine[0] > 0 Then
Send (" " & $CmdLine[1])
Else
    MsgBox(0,"Error", "Wrong parameter count!")
EndIf

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks Mega! It works now :think:

Share this post


Link to post
Share on other sites

I don't intend to hijack this thread, but the topic is a good one for this question as well. :(

I want to look for and remove "/" or "-" from the command line if they exist.

This has probably been asked before but I'm out of ideas on how to find it.

This is what I'm trying to do:

If $CmdLine[0] <> 0 Then _CmdLine($CmdLine[1])
Func _CmdLine($Param)
If StringLeft($Param,1) = "-" OR "/" Then $Param=StringTrimLeft($Param,1)
MsgBox(64,"",$Param)

Of course there is more to the function, but this is just for experimentation. :think:

Now my theory here is based on the help file saying that you can use boolean operators as well as logical.

I've tried different parentheses options with no avail.

Share this post


Link to post
Share on other sites

I don't intend to hijack this thread, but the topic is a good one for this question as well. :(

I want to look for and remove "/" or "-" from the command line if they exist.

This has probably been asked before but I'm out of ideas on how to find it.

This is what I'm trying to do:

If $CmdLine[0] <> 0 Then _CmdLine($CmdLine[1])
Func _CmdLine($Param)
If StringLeft($Param,1) = "-" OR "/" Then $Param=StringTrimLeft($Param,1)
MsgBox(64,"",$Param)

Of course there is more to the function, but this is just for experimentation. :think:

Now my theory here is based on the help file saying that you can use boolean operators as well as logical.

I've tried different parentheses options with no avail.

StringReplace()?

If StringInStr($CmdLine[1], '/') Then 
    $SomeVar = StringReplace($CmdLine[1], '/', '')
ElseIf StringInStr($CmdLine[1], '-') Then
    $SomeVar = StringReplace($CmdLine[1], '-', '') 
Else
    $SomeVar = $CmdLine[1]
EndIf

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks, but I wasn't clear enough, sorry. :think:

I can get it to work if I do a multi-line if then else statement, but I'm trying to do it with an if (this or that) statement.

Partially just to learn how to do this and partially because I think the code is neater. :(

Edit:

Or is this even possible?

Edited by d4vr0s

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks, but I wasn't clear enough, sorry. :think:

I can get it to work if I do a multi-line if then else statement, but I'm trying to do it with an if (this or that) statement.

Partially just to learn how to do this and partially because I think the code is neater. :(

Edit:

Or is this even possible?

Sorry, don't even understand what you mean... why don't you type of a pseudo code of what you want and comment next to it.

Edit:

(Neater doesn't always mean more efficient, generally speaking you are (the scripter) the only one that ever sees the code anyway)

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Neater doesn't always mean more efficient, generally speaking you are (the scripter) the only one that ever sees the code anyway

Makes sense, primarily it's to learn how to do stuff for me. :(

Trying again with comments. :)

If $CmdLine[0] <> 0 Then _CmdLine($CmdLine[1])
Func _CmdLine($Param)
; Check for - or / in one statement and remove the leftmost character if they exist
If StringLeft($Param,1) = "-" OR "/" Then $Param=StringTrimLeft($Param,1)
Select
Case $Param = "logon"
If @OSTYPE = "Win32_NT" Then _AdminLogon()
; Other cases continue with future commands
EndSelect
EndFunc

Mainly I just want to know if and how I can do an If statement based on 2 possibilities without nesting statements.

Edit:

I should tell you what the issue I'm having is too. :think:

When I use this code every command is trimmed by 1 character regardless if there is an - or / in it.

Edited by d4vr0s

Share this post


Link to post
Share on other sites

Ok, let's take a look at your syntax for a second:

If StringLeft($Param,1) = "-" OR "/" Then $Param=StringTrimLeft($Param,1)

If StringLeft($Param,1) = "-" OR StringLeft($Param,1) = "/" Then $Param=StringTrimLeft($Param,1)

You have to do another comparison for the Or.

Is the first Character always either the "-" or "/" or correct?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

$var = "test-this/string"

If StringInStr($var, '/') Or StringInStr($var, '-') Then $var = StringReplace(StringReplace($var, '-', ''), '/', '')

MsgBox(0, "", $var)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Excellent, That's exactly what I was trying to do.

The obviousness of it makes me feel stupid. :">

Thank you SmOke_N :think:

Share this post


Link to post
Share on other sites

Excellent, That's exactly what I was trying to do.

The obviousness of it makes me feel stupid. :">

Thank you SmOke_N :think:

No worries, actually after looking at it, I probably would have done it like:
If Not StringIsAlNum(StringLeft($Param,1)) Then $Param = StringTrimLeft($Param, 1)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

That's definitely simpler.

But I'm glad I got the if stuff understood. :think:

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  
Followers 0