I am making a script for validating wallet cryptocurrency.
so whenever I copy the address wallet and then I run the script. if the address wallet same as the array value, it will show msgbox that give information about the wallet name. if not it will show n/a.
but I have some problems, where the msgbox shows based many numbers of the array
here is my code
^q::
walletAddr := Object("wallet1", "0x01415e36ce36d07229abf8b0435669088319f656", "wallet2", "0x9d6fb140607e1727c1373624a97ba681ef54f5bk", "wallet3", "0x660f01a47efd305862bc598cad44d1966b376d67")
found := 0
for k, v in walletAddr
if ( clipboard == v ) {
MsgBox % k
found := 1
}
if !found
MsgBox, n/a
return
and I figure out that this problem isn't from the script. but from the array value.
I try to change the value to a simple word and it works perfectly
walletAddr := Object("wallet1", 0xFF0000, "wallet2", 0x0000FF,"wallet3", 0x00FF00)
I have no clue where the problems come from. maybe it's because of length value, value typedata, or others.
can someone help me figure out my problem? thank you
i found tricky way to make it work :D
just add string text ( i use = "wallet_" ) before value and before clipboard.
Related
After many times of seraching i could not find an answer regarding my use case on Google or Stack Overflow.
I'm heavily using Autohotkey snippets like this for email:
:*:emailsignature::
(
Email signature text
)
But sometimes i need to temporarily add some more text inside the existing snippet.
:*:emailsignature::
(
Email signature text
%datewithtext%
Email signature text
)
::datewithtext::*** Date with text ***
So what i was wishing for is to add a variable inside the snippet as shown above. And of course I've tried the variable syntax from AHK, but got all sorts of errors.
So hopefully someone can point my in the right direction or even better show me an example code.
Thanks in advance.
On top of all the other suggestions, I would suggest to prevent you having to write "emailsignature" to trigger the text expansion. Instead, I would use e.g. "es". This short string is unique enough with the \ as the closing character to never (seldom) collide. I use this trick for many long words.
You could try this as a solution
:*:emailsignature:: ; hotstrings expect a literal string on one line,
; but can be used like hotkeys as well.
FormatTime, Date
dateWithText =
( ; the continuation section below works when assigning to a variable
Email signature text
%Date%
Email signature text
)
Return
::datewithtext::
Send % dateWithText
Return
OR, you could get kind of fancy
; auto-execute section
V_EmailSignature := "myemail#yahoo.com"
V_MomEmail := "mom#yahoo.com"
V_StreetAddress := "123 Any Street`r`nAnytown, ID, 12345"
Return ; end auto-execute section
; HOTSTRINGS
:*:emailsignature::
:*:momemail::
:*:streetaddress::
FormatTime, Date
vName := regexReplace(A_ThisHotkey, "\W")
newText := V_%vName%
dateWithText := Join("`r`n", newText, Date, newText)
Return
::datewithtext::
Send % dateWithText
Return
Join(delim, Strs*) {
newStr := ""
for _, Str in Strs {
newStr .= (newStr ? Delim : "") . Str
}
Return newStr
}
Does that help you?
I'm trying to parse a filename and get the first character from it as a string to compare it to a previously inputted variable. My code looks like:
FileSelectFolder, WhichFolder ; Ask the user to pick a folder.
; Ask what letter you want to start the loop from
InputBox, UserInput, Start At What Letter?, Please enter a letter to start at within the folder (CAPITALIZE IT!)., , 450, 150
if ErrorLevel {
MsgBox, CANCEL was pressed.
ExitApp
} else {
inputted_letter = %UserInput%
tooltip %inputted_letter% ; Show the inputted letter
sleep, 2000
tooltip
}
Loop, %WhichFolder%\*.*
{
current_filename_full = %A_LoopFileName%
files_first_letter := SubStr(current_filename_full, 1, 1)
tooltip %files_first_letter% ; Show the file's first letter
sleep, 2000
tooltip
if files_first_letter != inputted_letter
continue
...
Right now, it clearly shows in the tooltips the user-entered capital letter, and then the first letter of each file name from within the selected folder, but for some reason when the two look alike, it doesn't recognize them as a match. I'm thinking maybe because technically A_LoopFileName is not of a string type? Or maybe the inputted letter doesn't match the type of the first filename's letter?
I want it to continue if the inputted letter and the first letter of the filename don't match, but if they do, to carry on with the rest of the script. Any ideas on how I can get these two to successfully match? Thanks!
Firstly, AHK doesn't really have types. At least not how you've experienced types in other languages.
So your assumption about "not being correct type" will pretty much always be wrong.
So the actual cause is because in a legacy if statement, the syntax is
if <name of variable> <operator> <legacy way of representing a value>
So you'd do it like this:
if files_first_letter != %inputted_letter%
You we're comparing if the variable files_first_letter is equal to the literal text inputted_letter.
However, I highly recommend you stop using legacy syntax. It's really just that old.
It'll differ horribly much from any other programming language and you run into confusing behavior like this. Expression syntax is what you want to use in AHK nowadays.
Here's your code snippet converted over to expression syntax in case you're interested:
FileSelectFolder, WhichFolder
;Forcing an expression like this with % in every parameter
;is really not needed of course, and could be considered
;excessive, but I'm doing it for demonstrational
;purposes here. Putting everything in expression syntax.
;also, not gonna lie, I always do it myself haha
InputBox, UserInput, % "Start At What Letter?", % "Please enter a letter to start at within the folder (CAPITALIZE IT!).", , 450, 150
if (ErrorLevel)
;braces indicate an expression and the non-legacy if statement
;more about this, as an expression, ErrorLevel here holds the value
;1, which gets evaluated to true, so we're doing
;if (true), which is true
{
MsgBox, % "CANCEL was pressed."
ExitApp
}
else
inputted_letter := UserInput ; = is never used, always :=
Loop, Files, % WhichFolder "\*.*"
;non-legacy file loop
;note that here forcing the expression statement
;with % is actually very much needed
{
current_filename_full := A_LoopFileName
files_first_letter := SubStr(current_filename_full, 1, 1)
if (files_first_letter != inputted_letter)
continue
}
Also you don't have to be concerned about case with !=, it'll always compare case insensitively.
I'm a fairly new developer and i have run into a problem.
I'm using auto hotkey to automate at longer manual process, and one of the things i'm trying to do is split an address, and then use each individual part of that address in another system. The problem is that addresses can be very different.
I use Strsplit on the entire address, and then i want to check if each part of that address is numerical or a letter.
My problem is that no matter what i try. I always get the same result.
I use "if var is not type" and "if var is type". The problem is that not matter I check for alpha, integer, number or float it always returns true even if the variable is clearly a string and I check for numbers. Sample code below.
xl := ComObjActive("Excel.Application")
Array := StrSplit(xl.Range("C2").text, A_Space, ",")
if Array[1] is not number
{
Msgbox, False
}
if Array[1] is number
{
Msgbox, True
}
Can you help me?
To retrieve an array element use the := operator:
xl := ComObjActive("Excel.Application")
Array := StrSplit(xl.Range("C2").text, A_Space, ",")
element1 := Array[1]
; MsgBox, % element1
if element1 is not number
Msgbox, False
if element1 is number
Msgbox, True
TL;DR I created a new variable (destinationControl) by concatenating a string, a separate string variable, and then another string. I tried using the variable destinationControl with ControlSetText, but its not working. Can anyone tell me why?
Long Explanation:
I'm attempting to send some data from an excel spreadsheet into another application using AHK ControlSetText. My issue comes in when I need the script to detect which one of two possible programs is the active one (the detection part is working) and then based on the name of the program, set the destination control name is slightly different.
prog_A_segment := "abc"
prog_B_segment := "def"
;determine which program is open
IfInString, OpenProgram, ProgA
{
ctrlSegment := prog_A_segment
}
else
ctrlSegment := prog_B_segment
;set control variable
destinationControl := "WindowsForms10.EDIT.app.0." . ctrlSegment . "_r13_ad11"
;activate program
WinActivate, % OpenProgram
WinWaitActive, % OpenProgram,,3
;open vendor form
Sleep 300
Send ^o
Sleep 200
Send Vendors
sleep 200
Send {ENTER}
Sleep 2000
;This does not work:
;pass information to vendor form control
ControlSetText, %destinationControl%, %myNumber%, %OpenProgram%
I know I could just slightly more manually set them based on the open program but i have about 25 controls in total and the only difference is that center segment so I thought this would be a little more elegant and cleaner.
When I use the above method it doesn't appear AHK can find the control. I'm assuming it has something to do with how I combined a string and a variable. Is there some way to make this approach work without doing this instead:
IfInString, OpenProgram, ProgA
{
destinationControl1 := "WindowsForms10.EDIT.app.0.abc_r13_ad11"
....
destinationControl25 := "WindowsForms10.EDIT.app.0.abc_d52_ad11"
}
else
destinationControl1 := "WindowsForms10.EDIT.app.0.def_r13_ad11"
....
destinationControl25 := "WindowsForms10.EDIT.app.0.def_d52_ad11"
I agree with Josh Brobst that your first piece of code would work with the missing quote added.
Well, here's what you want to try anyways:
ctrlSegment := InStr(OpenProgram, ProgA) ? "abc" : "def"
Loop Parse, % "r13, ... ,d52", CSV
ControlSetText % "WindowsForms10.EDIT.app.0." ctrlSegment "_" A_LoopField "_ad11"
, % myNumber, % OpenProgram
I have a list of pdf files in this format "123 - Test - English.pdf". I want to be able to set "111", "Test" and "English.pdf" in their own individual variables. I tried running the code below but I don't think it accounts for multiple dashes "-". How can I do this? Please help Thanks in advance.
Loop,C:\My Documents\Notes\*.pdf, 0, 0
{
NewVariable = Trim(Substr(A_LoopFileName,1, Instr(A_LoopFileName, "-")-1))
I would recommend using a parse loop to get your variables. The following loops through values between the dashes and removes the whitespace.
FileName = Test - file - name.pdf
Loop, parse, FileName, `-
MyVar%A_Index% := RegExReplace(A_LoopField, A_Space, "")
msgbox % Myvar1 "`n" Myvar2 "`n" MyVar3
First, I don't know if it was a typo, but if you use a { under your loop statement, you also need to close it. If your next statement is just one line, you don't need any brackets at all.
Second, if you just use = then your code will output as just that very code text. You need to use a :=
Third, your present code, if coded correctly would result in this:
somepdffile.pd
if it found any pdf files without a dash. Instr() will return the position of a dash. If there is no dash, it returns 0 - in which case, your substr() statement will add 0 and your -1 which adds up to -1 and if you use a negative number with substr(), it will search from the end of the string instead of the beginning - which is why your string would get cut off.
Loop, C:\My Documents\Notes\*.pdf, 0, 0
{
;look at the docs (http://www.autohotkey.com/docs/) for `substr`
}
So there is an explanation of why your code doesn't work. To get it to do what you want to do, can you explain a bit more as to how you want NewVariable to look like?
; here is another way (via RegExMatch)
src:="123 - Test - English.pdf", pat:="[^\s|-]+"
While, mPos:=RegExMatch(src, pat, match, mPos ? mPos+StrLen(match):1)
match%A_Index%:=match
MsgBox, 262144, % "result", % match1 ", "match2 ", "match3