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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find the Total Sum

Status
Not open for further replies.

vzachin

Technical User
Feb 10, 2006
305
US
Hi,

I have the following code that brings back the Units & Spares on each page. It then scrolls (page advances) until it reaches the "END". On each page are different Units & Spares. How can I total the number of Units & Spares?

Code:
Do Until Sess0.Screen.GetString(24, 2, 3) = "END"
Units = Sess0.Screen.GetString(3, 12, 4)
Spares = Sess0.Screen.GetString(3, 28, 4)
Sess0.Screen.SendKeys ("<PF1>") 'page advance
Do While Sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Sess0.Screen.WaitHostQuiet (1000)
Loop

I thought the following would work but of course it's incorrect:
NbrUnits = NbrUnits + NbrUnits

thanks
vzachin
 
Hi SkipVought,

Thanks for the speedy reply. I have a serious problem.
When I use the
Units = Units + Sess0.Screen.GetString(3, 12, 4),
I get a concatenation of the two fields.
So I tried subtraction, multiplication & division and all 3 worked correctly.
Units = Units - Sess0.Screen.GetString(3, 12, 4),
Units = Units * Sess0.Screen.GetString(3, 12, 4), and
Units = Units / Sess0.Screen.GetString(3, 12, 4).

I don't understand why the concatenation instead of addition. Any ideas?

thanks
vzachin
 
Use the Value function instead.

Units = Units + Val(Sess0.Screen.GetString(3, 12, 4))

Depending on how you're working with Units you may need to also use the "val" function on it.

calculus
 




When I scrape values I

1. use the TRIM function
2. if the field is REALLY a number (Part NUMBER, Invoice NUMBER, Employee NUMBER are not REALLY numbers that you will do arighmetic on. Rather they are IDENTIFIERS containing NUMERIC CHARACTERS) I capture it as a numeric data type. Otherwise, if the value is numeric, I prepend a single quote OR append and store the value as a string.

Skip,

[glasses] [red][/red]
[tongue]
 
Hi Calculus:
Using the following
The Units = Units + Val(Sess0.Screen.GetString(3, 12, 4))
works correctly as ADDITION.


Hi SkipVought:
I used the TRIM function but it still concatenates. When you get a chance, can you explain how I would capture it as a numeric data type as you suggested? I'm still trying to learn all this.



thanks for all your help
vzachin
 
You by using the "Val" function you are capturing it as a number instead of text.

calculus
 




If your variable, Units, is a Variant, it will concatenate as string.

best to CONVERT using Val. Assigning to a Numeric Variable type, VB does the conversion implicitly.

Skip,

[glasses] [red][/red]
[tongue]
 
Calculus & SkipVought,

Thanks again for the info.
[2thumbsup]

vzachin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top