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

Can I convert a macro into a function used by another macro? 1

Status
Not open for further replies.

tedb13

Technical User
Jan 20, 2011
41
CA
Hi,

Is there a way to use this code in a function or header file that can be accessed by Main()?

Code:
Sub main()
            Dim Sessions As Object
            Dim System As Object
            Set System = CreateObject("EXTRA.System")     ' Gets the system object

            If (System is Nothing) Then
                        Msgbox "Could not create the EXTRA System object.  Stopping macro 						playback."
                        STOP
            End If

	    ' Get the necessary Session Object

            Dim Sess0 As Object

            Set Sess0 = System.ActiveSession

            If (Sess0 is Nothing) Then

                        Msgbox "Could not create the Session object.  Stopping macro playback."

                        STOP

            End If

            If Not Sess0.Visible Then Sess0.Visible = TRUE

            Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
'____________________________________

Dim Sys As Object, OPenSess As Object, MyTerminal As Object

Set Sys = CreateObject("EXTRA.System")

' Assumes an open session

            Sys.TimeoutValue = 850

        Set OpenSess = Sys.ActiveSession

            Set MyTerminal = OPenSess.Screen
[COLOR=purple]
MyTerminal.WaitHostQuiet(500)

NumRtrn=Trim(MyTerminal.GetString(14,72,2))

xLn=10

If NumRtrn = 1 then

    MyTerminal.PutString "x", 15, 72

    MyTerminal.WaitHostQuiet(500)

    MyTerminal.SendKeys("<Enter>")

    MyTerminal.WaitHostQuiet(500)

    GetPer=MyTerminal.GetString(xLn, 21, 8)

ElseIf NumRtrn > 1 then

    MyTerminal.PutString "x", 15, 72

    MyTerminal.WaitHostQuiet(500)

    MyTerminal.SendKeys("<Enter>")

    MyTerminal.WaitHostQuiet(500)

    For x=1 to NumRtrn

        If xLn>10 then

            GetPer=MyTerminal.GetString(xLn, 21, 8)

            NewPer=NewPer & "/"

        ElseIf xLn=10 then

            GetPer=MyTerminal.GetString(xLn, 21, 8)

        End If

        xLn=xLn+1

        NewPer=NewPer & GetPer

    Next x

Elseif NumRtrn = "" OR NumRtrn = 0 then

   ' Do Nothing 

End If

msgBox NewPer

End Sub [/color]

What I'd like to do is only have the "formula" ...
Code:
MyTerminal.WaitHostQuiet(500)

NumRtrn=Trim(MyTerminal.GetString(14,72,2))

xLn=10

If NumRtrn = 1 then

    MyTerminal.PutString "x", 15, 72

    MyTerminal.WaitHostQuiet(500)

    MyTerminal.SendKeys("<Enter>")

    MyTerminal.WaitHostQuiet(500)

    GetPer=MyTerminal.GetString(xLn, 21, 8)

ElseIf NumRtrn > 1 then

    MyTerminal.PutString "x", 15, 72

    MyTerminal.WaitHostQuiet(500)

    MyTerminal.SendKeys("<Enter>")

    MyTerminal.WaitHostQuiet(500)

    For x=1 to NumRtrn

        If xLn>10 then

            GetPer=MyTerminal.GetString(xLn, 21, 8)

            NewPer=NewPer & "/"

        ElseIf xLn=10 then

            GetPer=MyTerminal.GetString(xLn, 21, 8)

        End If

        xLn=xLn+1

        NewPer=NewPer & GetPer

    Next x

Elseif NumRtrn = "" OR NumRtrn = 0 then

   ' Do Nothing 

End If
Then access it from the Main() macro when needed, but the system generates errors. It wants MyTerminal, Sess0, System and the like declared. How would I get it to recognize that these are already open and declared in Main(). I won't say that this is a stupid question, but rather a "this guy just doesn't know" question. What am I missing?

unawares,
 
Hi Zach,

I just thought there might be some way to declare the Session, System and the like variables, globally in one header. I just need to understand the behavior a lot more, I guess, before I can understand the language limitations. I know that Skip is going to say that "VBA is a lot more robust, and that if there's an opportunity to use it, do so!". Trust me, if I knew that others who will benefit from my efforts would use them, I would be trying to learn VBA instead of EB. That may change at a later date, but one thing at a time. I'm sure there's a perfectly logical work around to my problem, I just can't see it yet; there are too many factors involved. I have reviewed your references,and I will review them again. I'm hoping a connection will occur in my brain at some pint. If so, I will name my first macro, Epiphany!.EBM....

I may get back to with more later if I have related information or questions.
 
ted, the link i provided shows you how to call another sub within the main(). it should work for you,unless i misunderstood you
 
No, you did not misunderstand me I guess.
perhaps I just need to rethink how everything will be put together.

btw, I know that new questions should be put in new threads, but what does ..
Code:
Private Sub Wait(Sess As Object)
   Do While Sess.Screen.OIA.Xstatus <> 0
      DoEvents
   Loop

End Sub
..do? What does OIA.XStatus mean? I will be going to work soon, and I will look it up, but jic I don't find the answer...
 
ted, i use the OIA.status after evoking a FIND or ENTER in Extra for the system response time. If you do a search in TEK-TIPS,you will find more information about that

zach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top