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!

Add a "tab" so I can paste in multiple fields

Status
Not open for further replies.

Chinacat55

Technical User
Jan 9, 2007
9
CA
I'm still learning how to write these macros so I appreciate any suggestions.

Can anyone tell me how to insert a "tab" function into data I have collected from an Attachmate session. In the example below, I would like to insert a "tab" between AccountNumber and SSN so that when I use paste,
the AccountNumber will paste in one field, tab to the next field, and paste the SSN.

'Copies the Account number from the screen

Set MyArea1 = MyScreen.Area(5,21,5,25 , ,)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
MyArea1.Select
MyArea1.Copy
AccountNumber = MyArea1

'Copies the SSN from the screen

Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Set MyArea2 = MyScreen.Area(6,21,6,31 , ,)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
MyArea2.Select
Sess0.Screen.copyappend
SSN = MyArea2



I have written a macro that collects 5 pieces of data from different parts of the screen. I now want to paste this data using the paste tool in another application. When I paste, only the first field is populating. I figure if I can add a "tab" to each piece of info I've gathered, I would be able to paste the info in all the fields on the other application.

Thanks for any suugestions.
 
Is switch from the copy/paste to
AccountNumber = MyScreen.GetString(5,21,x)
x being the length of your account number

AccountNumber = MyScreen.GetString(5,21,10)
would grab 1o characters starting from row 5 column 21 on your screen.

To better answer your other question what app are you inputting the information to?


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks for the reply.

I'm inputting the information to an indexing database application that runs on Internet Explorer. There a five pieces of information manually entered in the Attachmate session.

AccountNumber = MyScreen.GetString(5,21,5)
SSN = MyScreen.GetString(6,21,10)
LastName = MyScreen.GetString(7,21,18)
FirstName = MyScreen.GetString(7,50,18)
ClientID = MyScreen.GetString(4,21,6)

I want the macro to gather this information after it has been manually entered, and paste it in the fields of the other application. The other application just has 5 fields that require the same data. So far I have the macro gather the five pieces of information, but when I go to the first field of the indexing application and click paste, only the first field pastes. This is why if I could enter a "tab" between the information gathered, I would be able to paste into all five fields by clicking paste on the first field. I thought using the clipboard with copy/paste might be the easiest first phase of this macro.

The alternative to this would be to have the macro export the information to the other application. This may be my next endeavor. Is it possible to gather the information and then have the macro export it to the other application, specifying for it to start in the first field?

Thanks again for your suggestions

 
I am assuming your using send keys to paste into IE based on your description, is this correct?

Show me the code your using to do this and I may be able to help further.

The best option would be to setup an IE object and tell it exactly where you want each peice of information to go rather than paste tab paste ......

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks again, this is a HUGE help.

I've changed this to GetString instead of:

Set MyArea1 = MyScreen.Area(5,21,5,25)
MyArea1.Select
MyArea1.Copy
ContractNumber = MyArea1

However, this new method is not working for me. I get the error message "Object value is set to nothing" at the first line using "GetString" ContractNumber = MyScreen.GetString(6,19,5)

Here is the code as I have it so far:



Sub Main()
'----------------------------------------------------------
' Get the main system object
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
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'----------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 1 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
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, Sess As Object, MyScreen As Object


Set Sys = CreateObject("EXTRA.System")

' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen

'----------------------------------------------------------

'Checks to see if user is on the correct screen

Dim CustomerScreen As Object, IndexMacro As Integer

Set MyScreen = Sess0.Screen
Set CustomerScreen = MyScreen.Search ("MLPENPI")

If CustomerScreen = ("MLPENPI") then

IndexMacro = 1
Else

Msgbox "Not on the Correct Screen. Macro Stopped."
GoTo Done

End If

'----------------------------------------------------------

Dim ContractNumber As Object, Clientid As Object, LastName As Object
Dim FirstName As Object, SSN As Object

If IndexMacro = 1 then

'Copies Contract #

ContractNumber = MyScreen.GetString(6,19,5)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies Client ID

Clientid = MyScreen.GetString(5,19,7)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies Last Name

LastName = MyScreen.GetString(8,27,20)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies First Name

FirstName = MyScreen.GetString(8,60,20)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies SSN

SSN = MyScreen.GetString(7,19,11)
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

End if

'---------------------------------------------------------------------------------
done:
exit sub

System.TimeoutValue = OldSystemTimeout

End Sub
 
You can either create a new IE window each time you run the script:
Code:
Set objIE = CreateObject("InternetExplorer.Application")
strURL = "[URL unfurl="true"]http://www.google.com"[/URL]
objIE.Navigate strURL
While objIE.Busy = True
Wend
objIE.Visible = True
Set objElements = objIE.Document.getElementsByName("q")
For each objElement in objElements
  objElement.Value = YourVariable
Next
Or if the window is already open you can use the existing window:
Code:
Set objApps = CreateObject("Shell.Application")
For Each objWindow in objApps.Windows
  If objWindow.Name = "Microsoft Internet Explorer" Then
    strURL = objWindow.LocationURL
    If strURL = "[URL unfurl="true"]http://www.google.com"[/URL] Then
      objWindow.Document.Focus
      Set objElements = objWindow.Document.getElementsByName("q")
      For each objElement in objElements
        objElement.Value = YourVariable
      Next
    End If
  End If
Next
strURL is the URL for the page and you'll need to know the HTML elements name.
 
Typed not tested...
Code:
Global mySystem As Object
Global mySession As Object
Global myScreen As Object

'----------------------------------------------------------
Sub ThisError(sErrMsg As String)
    Msgbox sErrMsg
    Stop
End Sub

'----------------------------------------------------------
Sub Connections() 'Set Globaly declared Extra Objects

    Set mySystem = CreateObject("EXTRA.System")    ' Gets the system object
    If (mySystem is Nothing) Then 
        Call ThisError("No System object.  Stopping macro playback.")
    End If
    Set mySession = mySystem.ActiveSession
    If (mySession is Nothing) Then
        Call ThisError("No Session object.  Stopping Macro.")
    End If
    Set MyScreen = mySession.Screen
    If (myScreen is Nothing) Then
        Call ThisError("No Screen object.  Stopping Macro.")
    End If
End Sub

'----------------------------------------------------------

Sub Main()

    Dim sClientInfo(5) As String

    Call Connections 'Set Globaly declared Extra Objects
    
    If Not MyScreen.Search("MLPENPI") Then
        Call ThisError("Macro started on incorect screen. Stopping Macro")
    End If
    
       
    sClientInfo(1) = MyScreen.GetString(6,19,5)     'Contract
    sClientInfo(2) = MyScreen.GetString(5,19,7)     'Client ID
    sClientInfo(3) = MyScreen.GetString(8,27,20)    'Last Name
    sClientInfo(4) = MyScreen.GetString(8,60,20)    'First Name
    sClientInfo(5) = MyScreen.GetString(7,19,11)    'SSN
    
    For x = 1 to 5 
        msgbox sClientInfo(x)
    Next

End Sub
From here you'll work in Skie's suggestion for the IE object.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Thanks so much. This is really a huge help. I've inserted my info into the code but I'm getting many errors. So far the code collects all the info from the Attachmate seesion correctly. I'm having some trouble sending it to the open Internet explorer App.

Any suggestions? I'm still very new at using this so I greatly appreciate the help.

'--------------------------------------------------------------------------------

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$
Global MySystem As Object
Global MySession As Object
Global MyScreen As Object
Global System As Object
Global Session As Object
Global Screen As Object

'--------------------------------------------------------------------------------

Sub ThisError (sErrMsg As String)

MsgBox sErrMsg
STOP

End Sub




Sub Main()
'--------------------------------------------------------------------------------


' Get the main system object
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
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 1 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
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, Sess As Object, MyScreen As Object


Set Sys = CreateObject("EXTRA.System")

' Assumes an open session
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen

'---------------------------------------------------------------------------



'---------------------------------------------------------------------------

'Checks to see if user is on the correct screen

Dim CustomerScreen As Object, IndexMacro As Integer

Set MyScreen = Sess0.Screen
Set CustomerScreen = MyScreen.Search ("MLPENPI")

If CustomerScreen = ("MLPENPI") then

IndexMacro = 1
Else

Msgbox "Not on the Correct Screen. Macro Stopped."
GoTo Done

End If

'---------------------------------------------------------------------------

Dim sClientInfo(5) As String
'Call Connections 'Set Globally declared Extra Objects

If IndexMacro = 1 then

'Copies Contract #

sClientInfo(1) = MyScreen.GetString(6,19,5) 'ContractNumber
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies Client ID

sClientInfo(2) = MyScreen.GetString(5,19,7) 'Clientid
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies Last Name

sClientInfo(3) = MyScreen.GetString(8,27,20) 'LastName
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies First Name

sClientInfo(4) = MyScreen.GetString(8,60,20) 'FirstName
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

'Copies SSN

sClientInfo(5) = MyScreen.GetString(7,19,11) 'SSN
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


'---------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
Set objApps = CreateObject("Shell.Application")

For Each objWindow in objApps.Windows
If objWindow.Name = "DBT Client 3.1 - Microsoft Internet Explorer" Then
strURL = objWindow.LocationURL
If strURL = "\\ALLSGSTPOOL09\DBT31Client\REV_7\SETUP\DBTUI.htm" Then
objWindow.Document.Focus
Set objElements = objWindow.Document.getElementsByName("x")
For each objElement in objElements
objElement.Value = sClientInfo (x)
Next
End If
End If
Next

'---------------------------------------------------------------------------------
'---------------------------------------------------------------------------------
done:
exit sub

System.TimeoutValue = OldSystemTimeout

End Sub
 
Sorry, I pulled my code from vbscript. You have to dim your objects first in Extra and you can't do a For Each Loop. Try this (typed not tested):
Code:
Sub Main() 
 Dim Sess As Object
 Dim MyScreen As Object
 Dim System As Object
 Set System = CreateObject("EXTRA.System")
 If (System is Nothing) Then
  Msgbox "Could not create the EXTRA System object.  Stopping macro playback."
  STOP
 End If
 Set Sess = System.ActiveSession
 If Sess Is Nothing Then
  Msgbox "Could not create the Session object.  Stopping macro playback."
  STOP
 End If
 If Not Sess.Visible Then Sess.Visible = TRUE

 Dim CustomerScreen As Object
 Dim IndexMacro As Integer        
 Set MyScreen = Sess.Screen        
 Set CustomerScreen = MyScreen.Search ("MLPENPI")
 If CustomerScreen = ("MLPENPI") Then
  IndexMacro = 1
 Else
  Msgbox "Not on the Correct Screen.  Macro Stopped."
  GoTo Done
 End If

 Dim sClientInfo(5) As String
 If IndexMacro = 1 Then
  sClientInfo(1) = MyScreen.GetString(6,19,5)
  sClientInfo(2) = MyScreen.GetString(5,19,7)
  sClientInfo(3) = MyScreen.GetString(8,27,20)
  sClientInfo(4) = MyScreen.GetString(8,60,20)
  sClientInfo(5) = MyScreen.GetString(7,19,11)

  Dim objApps As Object
  Dim objWindow As Object
  Dim objElement As Object
  Set objApps = CreateObject("Shell.Application")
  For i = 1 to 50
   Set objWindow = objApps.Windows(i)
   If objWindow.Name = "DBT Client 3.1 - Microsoft Internet Explorer" Then    
    strURL = objWindow.LocationURL
    If strURL = "\\ALLSGSTPOOL09\DBT31Client\REV_7\SETUP\DBTUI.htm" Then
     objWindow.Document.Focus
     Set objElements = objWindow.Document.getElementsByName("x")
      For each objElement in objElements
       objElement.Value = sClientInfo (x)
      Next
    End If
   End If
  Next
 End If

done:
System.TimeoutValue = OldSystemTimeout
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top