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

Pull String from macroA into macroB 2

Status
Not open for further replies.

2010noACAPS

Technical User
Mar 29, 2004
41
0
0
US
I have created a few macros to use at work to automate some repetitive tasks. I have 1 that I need to alter for a new process. When I'm in Extra I move from 1 "program" to another. My macroA is setup to get StringA from ProgramA, SendKeys, and then paste StringA. MacroB was created to put StringB just inside ProgramB.

My issue is I need to use macroA to get StringC and then send StringB and the new StringC inside macroB. I'm wanting to do that instead of going back into ProgramA to get StringC and then back into ProgramB to put StringB and StringC within macroB.

Is this possible? Or would it just be easier to have macroB go back into ProgramA to get StringC?

There is also the problem of once I get StringC I need the macro to be able to strip either 4 or 5 characters from the beginning of the string. There will always be 10 numerics behind the leading 4 or 5 characters and the 10 numerics is what I need to paste inside macroB. Is there a function that could do that?

Thanks.
T
 
Can you combine these macro's and call Sub A to get String C and then pass it to Sub B? I guess what I'm trying to say is, why are you using two macro's?

Would something like this work?
Code:
Global SomeString as String

Declare Sub B

Sub main
  Dim Sys As Object, Sess As Object, MyScreen As Object

  Set Sys = CreateObject("EXTRA.System")
  Set Sess = Sys.ActiveSession
  Set MyScreen = Sess.Screen

  SomeString = MyScreen.GetString(1,1,80)
  Call B
     
End Sub

Sub B
  msgbox SomeString
End Sub

Or better yet replace sub B with Function B to avoid using Globals.
 
I can't combine those 2 macros because I have 10 different versions of macroA due to going into the correct section of ProgarmB. If I was a better programmer I could do 10 IF/Thens but I have limited experience.

I'm going under the assumption that it would just be easier to go back into ProgramA from macroB and pull StringC myself. And I think I can use Right(result,10) to pull the last 10 digits of the string. But when I did that after telling it that "source" was 15 digits long to take care of the 5 characters I may have in front of my 10 numerics the "result" was missing the leading number and grabbed the last space. I even tried doing RTrim to "result" first but that didn't work either.

Code:
' Get LPM#
        Sess0.Screen.Sendkeys("<attn><Pf1><home>qcus<enter>")
       
        source = Sess0.Screen.GetString(4,60,15)
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        result = RTrim(source)
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        lpm = Right(result,10)
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        
' Go back to Custom        	
	Sess0.Screen.Sendkeys("<Attn><Pf6>")
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
 
        amount = Sess0.Screen.GetString(5,47,12)
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
         
	Sess0.Screen.PutString "blahblah",13,17
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        Sess0.Screen.PutString lpm,13,26
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        Sess0.Screen.PutString amount,13,49
	System.TimeoutValue = OldSystemTimeout
 
source = Sess0.Screen.GetString(4,60,15)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
result = RTrim(source)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
lpm = Right(result,10)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

instead how about

lpm = trim(Sess0.Screen.GetString(4,60,15)
or
lpm = Right(RTrim(Sess0.Screen.GetString(4,60,15)),10)

and you only should be using
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
when your waiting for your screen to paint

will work the same as above

source = Sess0.Screen.GetString(4,60,15)
result = RTrim(source)
lpm = Right(result,10)



give some examples of what your expecting (Format) at Sess0.Screen.GetString(4,60,15) and we can be more helpful

XXXXXXXXXXXXXX
XXXXXXXXX
XX XX XXXX XX
XXXXXXXXXXXXX

ect. ect.

Last question, how do you determine which version of A to run?

Hopefully this helps some.
 
I will try that:
lpm = trim(Sess0.Screen.GetString(4,60,15)
or
lpm = Right(RTrim(Sess0.Screen.GetString(4,60,15)),10)
And let you know what happens. I can only work on this between tasks.

Ok, basically the "version" is based on the state the product is in. I have the 10 versions of macroA assigned to 10 different buttons and created to send a certain company code to ProgramB.
 
What logic is used to determine which button to push?

Is it a keyword somewhere on the screen?

Is it always in the same place?



 
The state abbreviation is located on multiple screens so it would be possible to use that but I'd have to send the macro to a specific page to pull the state which I know how to do. It's the If/Thens that give me problems.
 
Sorry, forgot about formating...
StringC will either look like x9992009999999 or x999x2009999999.

I get 2009999999 with the 1st format but when i run for the 2nd format i get 009999999_,the underscore is present.

And I'm still getting 009999999_ even with:
lpm = Right(RTrim(Sess0.Screen.GetString(4,60,15)),10)
pulling from x9992009999999, but I get the correct 2009999999 using your code and pulling from x999x2009999999.

Do I need to put an If/Then in to see if its the x999x or the x999 format first before I tell the macro how to pull the 10 digit number i need?
 
once you have your abreviation you could use if then's like

If State = "AL" then
source = Sess0.Screen.GetString(1,1,10)
'or navigate to another screen the grab
'or both ect ect
End If
If State = "AK" then
source = Sess0.Screen.GetString(2,1,10)
'or navigate to another screen the grab
'or both ect ect
End If
If State = "AZ" then
source = Sess0.Screen.GetString(3,2,10)
'or navigate to another screen the grab
'or both ect ect
End If

or

If State = "AL" then
source = GetString(1,1,10)
'or navigate to another screen the grab
'or both ect ect
ElseIf State = "AK" then
source = GetString(2,1,10)
'or navigate to another screen the grab
'or both ect ect
ElseIf State = "AZ" then
source = GetString(3,2,10)
'or navigate to another screen the grab
'or both ect ect
End If

Or case statement

Select Case State
Case "AL"
source = GetString(1,1,10)
'or navigate to another screen the grab
'or both ect ect
Case "AK"
source = GetString(2,1,10)
'or navigate to another screen the grab
'or both ect ect
Case "AZ"
source = GetString(3,1,10)
'or navigate to another screen the grab
'or both ect ect
Case "UT","ID","CA" '<-would be if any of the three
source = GetString(4,1,10)
'or navigate to another screen the grab
'or both ect ect
End Select


Basically, it would be like putting one of your macros into each if or case. Then just adding the trigger before your if or case block.
 
show me an dummied up example of the full line and add [ignore] tag at the start of the information you want and [/ignore] tag at the of It end.

I'm confused because you say were getting an _ but I see non in

x9992009999999

or

x999x2009999999

Where did it come from?
 
Try

lpm = Right(trim(Sess0.Screen.GetString(4,60,15),10))
msgbox "*"+lpm+"*"

and see if the bit between *'s is what you think it should be in both cases.

If not I need an example of what the whole line looks like in each of the cases x9992009999999 x999x2009999999.

 
I don't think that will help either, but I can try it tomorrow when i get to work.

But...
x9992009999999______
z120c2009999999_____


It seems that instead of pulling a space it's pulling the physical underscore that is showing the length of the field (20 characters) the source is in.

(I have 4 different 4 digit codes that will proceed the 200... number but I only have one 5 digit code that would ever proceed the number.)
 
Code:
lpm = Sess0.Screen.GetString(4,60,15)
If Right(lpm,1) <> "_" then
  lpm = right(lpm,10)
Else
  lpm = mid(lpm,5,10)
End If
 
One thing you can do is just declare your variable as Global.

Code:
Global strToPassFromAtoB
Sub Main
    MsgBox "I'm macro A"
    strToPassFromAtoB = "Something Here"
End Sub

Code:
Sub Main
    MsgBox "I'm macro B.  The strToPassFromAtoB is: " & strToPassFromAtoB
End Sub

While cleaner coding would suggest it be one contained program. This might be quick fix until you have time to do so.
 
Skie - I was able to use what MgWils gave me and that worked just fine by just doing everything in macroB. It's good enough for now. :)

MgWils - Thanks for all your help. I even got macroA to just one version using the If/then's you suggested. A co-worker is the guinea pig the rest of the week to make sure the speed and accuracy are good before I give it to everybody here.

Todd
 
Skie,

To use two Sub's titled Main would one need to be in a header file? Can you give a more detailed example of how your passing the variable? I think I might be missing something here.

Thanks :)
 
You have macro A that sets a global variable. When macro B runs, it can read the global variable. Two macros, so you'd have two Sub Main.

Macro A
Code:
Global strToPassFromAtoB
Sub Main
    MsgBox "I'm macro A"
    strToPassFromAtoB = "Something Here"
End Sub

By declaring the value Global, it stores the information so that another script could reference it.

So, I run this macro. I now have "Something Here" stored in global variable strToPassFromAtoB.


I forgot the declaration on macro B
Macro B
Code:
Global strToPassFromAtoB
Sub Main
    MsgBox "I'm macro B.  The strToPassFromAtoB is: " & strToPassFromAtoB
End Sub

Now, we declare that we want the Global variable strToPassFromAtoB. Since we've already set the value of this variable in Macro A, the variable no has a value of "Something Here".

So, I run this macro and get a message box and the message box will say "I'm macro B. The strToPassFromAtoB is: Something Here"

For what 2010 needed, it's not optimal. If you ever have two macros that need to interact it's an easy way to do it.

This isn't the greatest example, but it'll give you an idea of when it'd be useful. Macro A is always running and stores the last 10 screen of information. When you run macro B, it's going to scrape multiple screens, but you want to retain the information in macro A. A global variable could be used to turn on/off macro A's screen tracking. If the variable is false, then don't scrape. Macro B sets it to false when it starts and sets it to true when it ends. Another global variable could be used to send the results of macro B's scrapes to A.
 
Skie,

Hmm. I may try that. When macroB runs and takes the user to a certain screen to pull StringC, I've noticed that the user is having to manually go back to a different screen to finish the workflow. What you suggest would allow macroB to run as it did before the update and not mess up the users' normal flow. I'll see if that works for me and let you know. It should work because macroA runs, ends, and then a few minutes later macroB runs. So, if the global variable can hold out in memory that long then your suggestion may work.

Thanks,
T
 
Skie,
Are both Macro A and B in your example required to be in the same script? Or are you saying they can be completely different files?


2010,
you may want to look at Thread1-1185554 alos discussing a global variable.

 
Skie,

The making of StringC into a Global variable in macroA worked great. macroB pulled it over with no problems.

Thanks for the tip.

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top