Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I use Subtraction With GetString

Status
Not open for further replies.

LearningAsIGo

Technical User
Mar 17, 2008
18
US
I think that GetString is not the best way to get data for math opperations, but i don't know the other way to do it. Thanks in advance.

Code:
'Get Totals from QTRI
MyScreen.Sendkeys("<Home><BackTab>QTRI<Enter>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
MyScreen.MoveTo 3,6
MyScreen.Sendkeys(AccountNum1 + AccountNum2 + AccountNum3)
Qtr$ = InputBox$("Enter Quarter")
MyScreen.MoveTo 4,11
MyScreen.Sendkeys(Qtr)
MyScreen.Sendkeys("<Enter>")
MyScreen.WaitHostQuiet(g_HostSettleTime)
    TotalSubject = MyScreen.GetString(14,62,19)
        TotalSubject = Trim(TotalSubject)
    TotalPit = MyScreen.GetString(18,62,19)
        TotalPit = Trim(TotalPit)
    TotalPitwhld = MyScreen.GetString(19,62,19)
        TotalPitwhld = Trim(TotalPitwhld)
        
'Switch to BWS
MyScreen.Sendkeys("<Pf24>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Home>WIEMP<Enter>")	
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
MyScreen.Sendkeys(AccountNum1 + AccountNum2 + Qtr)
MyScreen.Sendkeys("<Enter>")	
MyScreen.WaitHostQuiet(g_HostSettleTime) 

'Get Wages From BWS
    BWSTotalSubject = MyScreen.GetString(05,57,22)
        BWSTotalSubject = Trim(BWSTotalSubject)
    BWSTotalPit = MyScreen.GetString(06,57,22)
        BWSTotalPit = Trim(BWSTotalPit)
    BWSTotalPitwhld = MyScreen.GetString(07,57,22)
        BWSTotalPitwhld = Trim(BWSTotalPitwhld)  
        
'Return To TAS
MyScreen.Sendkeys("<Pf24>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
        
'Get Differences
    DiffTotalSubject = TotalSubject-BWSTotalSubject
    DiffTotalPit = TotalPit-BWSTotalPit
    DiffTotalPitwhld = TotalPitwhld-BWSTotalPitwhld
 
I'm not sure if this matters, but the Strings I am getting have commas in them like 2,311,934.00
I tried to format the commas out
Code:
TotalSubject = Format(TotalSubject, General)
But that does not work. Again, thanks for any help.
 
I hate to post again, but I found the Val function, and now the math is incorrect

Code:
'Get Totals from QTRI
MyScreen.Sendkeys("<Home><BackTab>QTRI<Enter>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
MyScreen.MoveTo 3,6
MyScreen.Sendkeys(AccountNum1 + AccountNum2 + AccountNum3)
Qtr$ = InputBox$("Enter Quarter")
MyScreen.MoveTo 4,11
MyScreen.Sendkeys(Qtr)
MyScreen.Sendkeys("<Enter>")
MyScreen.WaitHostQuiet(g_HostSettleTime)
    TotalSubject = MyScreen.GetString(14,62,19)
        TotalSubject = Trim(TotalSubject)
        TotalSubject1% = Val(TotalSubject)
    TotalPit = MyScreen.GetString(18,62,19)
        TotalPit = Trim(TotalPit)
        TotalPit1% = Val(TotalPit)
    TotalPitwhld = MyScreen.GetString(19,62,19)
        TotalPitwhld = Trim(TotalPitwhld)
        TotalPitwhld1% = Val(TotalPitwhld)
        
'Switch to BWS
MyScreen.Sendkeys("<Pf24>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Home>WIEMP<Enter>")	
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
MyScreen.Sendkeys(AccountNum1 + AccountNum2 + Qtr)
MyScreen.Sendkeys("<Enter>")	
MyScreen.WaitHostQuiet(g_HostSettleTime) 

'Get Wages From BWS
    BWSTotalSubject = MyScreen.GetString(05,57,22)
        BWSTotalSubject = Trim(BWSTotalSubject)
        BWSTotalSubject1% = Val(BWSTotalSubject)
    BWSTotalPit = MyScreen.GetString(06,57,22)
        BWSTotalPit = Trim(BWSTotalPit)
        BWSTotalPit1% = Val(BWSTotalPit)
    BWSTotalPitwhld = MyScreen.GetString(07,57,22)
       BWSTotalPitwhld = Trim(BWSTotalPitwhld)  
       BWSTotalPit1% = Val(BWSTotalPit) 
        
'Return To TAS
MyScreen.Sendkeys("<Pf24>")	
MyScreen.WaitHostQuiet(g_HostSettleTime)
        
'Get Differences
    DiffTotalSubject = TotalSubject1-BWSTotalSubject1
    DiffTotalPit = TotalPit1-BWSTotalPit1
    DiffTotalPitwhld = TotalPitwhld1-BWSTotalPitwhld1

When I have 2,311,934.00 (totalSubject) subtracted 2,331,014.80 (Bwstotalsubject), I get a returned value of 0.00 (DifftotalSubject).
Please someone point out my mistake
 




Hi,

ANYTHING that you scrape from a screen is TEXT.

Use the IsNumeric function to determine if your string contains a convertable value. THEN convert the string using CLng of CDbl or the like...
Code:
if isnumeric(TotalSubject1) and isnumeric(BWSTotalSubject1) then
   DiffTotalSubject = clng(TotalSubject1)-clng(BWSTotalSubject1)
end if


Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
thanks for the reply, but the numbers fail your If statement and I get a type mismatch error.
I also took off the Val function because it stops at the first non-number. If there was a way i could ignore the thousands separator, then it would work.
Could I use the Format as General then the Val function or the CLng function?
 



One exactly what statement is it failing?

What are the exact values are in each variable?

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
the data i am using to test is:
TotalSubject = 2,311,934.00
TotalPit = 2,293,702.00
TotalPitwhld = 32,541.32
BWSTotalSubject = 2,331,014.80
BWSTotalPit = 2,313,882.83
BWSTotalPitwhld = 32,541.32

The numbers get scraped as i wrote them, and when I used your IF statement, I got a type mismatch error i had to change the code a little
Code:
if isnumeric(TotalSubject) and isnumeric(BWSTotalSubject) then
   DiffTotalSubject = clng(TotalSubject)-clng(BWSTotalSubject)
end if
I got rid of the 1s after , because the TotalSubject1 and BWSTotalSubject were used with the Val Function which I got rid of.
thanks for your help, i hope this answers your questions
 



Sorry, I guess I got those stray characters in there somehow???

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
It still wasn't working. I seperated everything out at the thousands seperators, it works, but it isn't pretty.

Code:
TotalSubjectMillion = MuScreen.GetString(14,67,3)
TotalSubjectMillion = TotalSubjectMillion*1000000
TotalSubjectThousnad = MuScreen.GetString(14,71,3)
TotalSubjectThousnad = TotalSubjectThousnad*1000
TotalSubjectHundred = MuScreen.GetString(14,71,3)
TotalSubjectHundred = TTotalSubjectHundred*1
TotalSubject = TotalSubjectMillion + TotalSubjectThousnad + TotalSubjectHundred

it works, but i need to add If statements in case the strings are empty because the values are not always in the millions or others. Can someone help not make it so complicated.

 



Before you do ANY arithmetic, you need to use the IsNumeric function on each STRING.

Skip,
[sub]
[glasses]Have you heard that the roundest knight at King Arthur's round table was...
Sir Cumference![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top