Totally stuck... Clipboard and Variable problem Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
doctorafterman
Posts: 26
Joined: 26 Aug 2019, 08:45

Totally stuck... Clipboard and Variable problem

25 Sep 2019, 10:38

I have a very disruptive bug in my script. If anyone can 1. tell me why my Return isn't working to stop this or 2. help me figure out why this is happening and fix it all together I would be so grateful.

What I expect this to do/what it does most of the time:
Copy data from chrome from NameX/Y and NumberX/Y coords and paste both of them in the specified sequence. This stores the Name in LeadName, replaces the clipboard with the Number, pastes the Number, restores LeadName to the clipboard, and pastes LeadName.

The problem:
Instead of pasting the value it just copied from NumberX/Y coords sometimes it will paste the LeadName twice in a row.
I've tried
If Clipboard = LeadName
If Clipboard is not digit/integer
etc. to stop it, but the message box and return don't stop the script. It still continues.

Code: Select all

Click %NameX%, %NameY%, 2
sleep 100
Send ^c
Clipboard := StrReplace(Clipboard, "`r`n")
sleep 100
ComObjCreate("SAPI.SpVoice").Speak(Clipboard)
LeadName := Clipboard
Sleep 100
if LeadName is upper
	StringLower, LeadName, LeadName, T
sleep 100
Click %NumberX%, %NumberY%, 3
sleep 100
Send ^c
sleep 100
Send ^{tab}
Click %NewTextX%, %NewTextY%
Clipboard := RegExReplace(Clipboard, "^1|[^0-9]", "")
sleep 100
If Clipboard = LeadName
{
MsgBox, ,Autopilot Error, Phone number not in clipboard.
BlockInput MouseMoveOff
return
}
Send ^v
Send {tab}{tab}
Clipboard := LeadName
LeadName = 
send Hi%A_Space%
sleep 100
send ^v
sleep 100
User avatar
Nextron
Posts: 1377
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Totally stuck... Clipboard and Variable problem

25 Sep 2019, 11:25

You're checking if clipboard contains the literal text "Leadname". Use If (Clipboard = LeadName) (an expressional if) instead.
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: Totally stuck... Clipboard and Variable problem

25 Sep 2019, 11:28

Hi there

Read the Comments in the Code below

Code: Select all

Click %NameX%, %NameY%, 2
sleep 100
Send ^c

;Give Exact (or Example) text that copied From ^c

Clipboard := StrReplace(Clipboard, "`r`n")
sleep 100
ComObjCreate("SAPI.SpVoice").Speak(Clipboard)
LeadName := Clipboard
Sleep 100
if LeadName is upper
	StringLower, LeadName, LeadName, T
sleep 100
Click %NumberX%, %NumberY%, 3
sleep 100
Send ^c

;Give Exact (or Example) text that copied From ^c

sleep 100
Send ^{tab}
Click %NewTextX%, %NewTextY%
Clipboard := RegExReplace(Clipboard, "^1|[^0-9]", "")
sleep 100
If Clipboard = LeadName
{
MsgBox, ,Autopilot Error, Phone number not in clipboard.
BlockInput MouseMoveOff
return
}
Send ^v
Send {tab}{tab}
Clipboard := LeadName
LeadName = 
send Hi%A_Space%
sleep 100
send ^v
sleep 100
:wave: There is always more than one way to solve a problem. ;)
doctorafterman
Posts: 26
Joined: 26 Aug 2019, 08:45

Re: Totally stuck... Clipboard and Variable problem

25 Sep 2019, 14:02

Examples of copied text below. The name is changed to always be Title case and the phone number uses regex to change it to just a 10 digit without 1 at the beginning.

Code: Select all

Click %NameX%, %NameY%, 2
sleep 100
Send ^c

;Example: Michael or MICHAEL

Clipboard := StrReplace(Clipboard, "`r`n")
sleep 100
ComObjCreate("SAPI.SpVoice").Speak(Clipboard)
LeadName := Clipboard
Sleep 100
if LeadName is upper
	StringLower, LeadName, LeadName, T
sleep 100
Click %NumberX%, %NumberY%, 3
sleep 100
Send ^c

;Example text: 1 (555) 867- 5309

sleep 100
Send ^{tab}
Click %NewTextX%, %NewTextY%
Clipboard := RegExReplace(Clipboard, "^1|[^0-9]", "")
sleep 100
If Clipboard = LeadName
{
MsgBox, ,Autopilot Error, Phone number not in clipboard.
BlockInput MouseMoveOff
return
}
Send ^v
Send {tab}{tab}
Clipboard := LeadName
LeadName = 
send Hi%A_Space%
sleep 100
send ^v
sleep 100
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: Totally stuck... Clipboard and Variable problem  Topic is solved

26 Sep 2019, 03:52

try this

Code: Select all

OldClip := Clipboard
Clipboard :=

Click %NameX%, %NameY%, 2
sleep 100

;Example: Michael or MICHAEL
Send ^c
ClipWait, 2
if !Clipboard
{
	MsgBox, Nothing Copied!!!!
	return
}

LeadName := Clipboard
Clipboard :=

IfInString, LeadName, `r`n
	LeadName := StrReplace(LeadName, "`r`n")

sleep 100
ComObjCreate("SAPI.SpVoice").Speak(LeadName)

Sleep 100
if (LeadName is upper)
	StringLower, LeadName, LeadName, T
sleep 100
Click %NumberX%, %NumberY%, 3
sleep 100


;Example text: 1 (555) 867- 5309
Send ^c
ClipWait, 2
if !Clipboard
{
	MsgBox, ,Autopilot Error, Phone number not in clipboard.
	BlockInput MouseMoveOff
	return
}

PhoneNumber := Clipboard
Clipboard :=


sleep 100
Send ^{tab}
Click %NewTextX%, %NewTextY%
PhoneNumber := RegExReplace(PhoneNumber, "^1|[^0-9]", "")
sleep 100

Clipboard := PhoneNumber
PhoneNumber :=

Send ^v
Send {tab}{tab}
Clipboard := LeadName
LeadName := 
send Hi%A_Space%
sleep 100
send ^v
sleep 100


Clipboard := OldClip
OldClip :=
:wave: There is always more than one way to solve a problem. ;)
doctorafterman
Posts: 26
Joined: 26 Aug 2019, 08:45

Re: Totally stuck... Clipboard and Variable problem

26 Sep 2019, 10:15

Great! I used your approach of keeping the clipboard clear and storing everything in variables, used Send %Variable% instead of pasting ^v, and used:

Code: Select all

While !Clipboard
{
	ClipWait, 2
	Send ^c
}
to ensure the clipboard fills before moving on. I have an emergency exitapp.

Code: Select all

Clipboard :=
Click %NameX%, %NameY%, 2
sleep 50
Send ^c
While !Clipboard
{
	ClipWait, 2
	Send ^c
}
LeadName:= Clipboard
Clipboard:=
IfInString, LeadName, `r`n
	LeadName:= StrReplace(LeadName, "`r`n")
sleep 50
ComObjCreate("SAPI.SpVoice").Speak(LeadName)
Sleep 50
if LeadName is upper
	StringLower, LeadName, LeadName, T
Sleep 50
NewContinue:
Click %NumberX%, %NumberY%, 3
sleep 50
Send ^c
While !Clipboard
{
	ClipWait, 2
	Send ^c
}
LeadNumber:= Clipboard
Clipboard:=
sleep 50
Send ^{tab}
sleep 50
Click %NewTextX%, %NewTextY%
LeadNumber := RegExReplace(LeadNumber, "^1|[^0-9]", "")
sleep 100
Send %LeadNumber%
Send {tab}{tab}
sleep 50
If (A_Hour < 09)
{
	send Good morning%A_Space%
}
else if (A_Hour >= 09) AND (A_Hour < 17)
{
	send Hi%A_Space%
}
else if (A_Hour >= 17)
{
	send Good evening%A_Space%
}
sleep 50
send %LeadName%
LeadName =
sleep 50
YoucefHam wrote:
26 Sep 2019, 03:52
try this

Code: Select all

OldClip := Clipboard
Clipboard :=

Click %NameX%, %NameY%, 2
sleep 100

;Example: Michael or MICHAEL
Send ^c
ClipWait, 2
if !Clipboard
{
	MsgBox, Nothing Copied!!!!
	return
}

LeadName := Clipboard
Clipboard :=

IfInString, LeadName, `r`n
	LeadName := StrReplace(LeadName, "`r`n")

sleep 100
ComObjCreate("SAPI.SpVoice").Speak(LeadName)

Sleep 100
if (LeadName is upper)
	StringLower, LeadName, LeadName, T
sleep 100
Click %NumberX%, %NumberY%, 3
sleep 100


;Example text: 1 (555) 867- 5309
Send ^c
ClipWait, 2
if !Clipboard
{
	MsgBox, ,Autopilot Error, Phone number not in clipboard.
	BlockInput MouseMoveOff
	return
}

PhoneNumber := Clipboard
Clipboard :=


sleep 100
Send ^{tab}
Click %NewTextX%, %NewTextY%
PhoneNumber := RegExReplace(PhoneNumber, "^1|[^0-9]", "")
sleep 100

Clipboard := PhoneNumber
PhoneNumber :=

Send ^v
Send {tab}{tab}
Clipboard := LeadName
LeadName := 
send Hi%A_Space%
sleep 100
send ^v
sleep 100


Clipboard := OldClip
OldClip :=

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Chunjee, Googleye, jarhead, leehere10, mikeyww, roonyroox, RubbeH, w0z, william_ahk and 57 guests