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!

Help with Loop Extra to Excel

Status
Not open for further replies.

MOVING2FLA

IS-IT--Management
May 22, 2010
4
US
Hi, I'm trying to pull numbers from an open Excel sheet (col A), Paste into an Extra (open session on correct screen), pull info back to Excel (col B), then loop to next row in column A. The first one works...but then it doesn't loop to next. Nothing is entered in Extra for next row. Here is my enter code...which I copied from here:

Sub ExcelExtraExcel()

Dim Excel As Object, ExcelWorkbook As Object

Set Excel = GetObject(, "Excel.Application")

Set System = CreateObject("EXTRA.System")

Set Sess = System.ActiveSession

Set MyScreen = Sess.Screen

With Excel.Worksheets("Sheet1")

Row = 1

Do

Pull = .Cells(Row, "A").Value '**This will pull information from Excel

MyScreen.Putstring Pull, X, X '**This will put information from Excel into Extra, use your own coordinates

MyScreen.SendKeys ("<Enter>")
MyScreen.WaitHostQuiet 100

NewPull = MyScreen.Getstring(X, X, 20) '**This will pull information from Extra, use your own coordinates

.Cells(Row, "B").Value = NewPull '**This will place information from Extra to Excel

Row = Row + 1 '**This will progress the code to the next line

Loop Until .Cells(Row, "A").Value <> "" '** This will loop your code until there is a blank value in Column A in Excel

End With

End Sub
 



Hi,

Since your are working between Excel and your emulator, I would not waste my time using Extra Basic. It is much less robust than Excel VBA and the debugging features are better in Excel VBA as well.

Not knowing what your [red]X[/red] value is, I can't provide much specific help. If you were coding in Excel VBA, I'd tell you to use the Watch Window to observe the values in each statement.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



Also, here's the technique that I've been using to wait for the cursor response, rather than a specified period of time which may be longer than necessary or too short, if the system is busy...
Code:
                .MoveRelative 1, 1, 1
                .SendKeys ("<enter>")
                Do Until (.WaitForCursor(3, 11))
                    DoEvents
                Loop


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
i completely agree with skip on this. If you are using excel and extra, write your code in excel vba. If you are used to plain old VB like I was, VBA has some subtle language differences which can be difficult at first to overcome but shouldnt provide to much trouble and the VBA expressions for well know VB expressions are available all over the internet. Also, if you arent as lucky as skip to have your return coordinates be the same every time, there is another thread on this forum called "Attachmate functions and methods help" (i think) which will provide a few other ways to 'wait for host'

just in case nobody told you, there is a bug in the WaitHostQuiet function in Extra that will essentially return the function before a new screen has been displayed and 'settled'. that's why we keeping bringing it up :)
 
Thanks for the help! I'm going to try adding the cursor now. BTW, I'm using Excel for this.
 
Still no luck. I'm using Excel for this:

Sub ExcelExtraExcel()

Dim Excel As Object, ExcelWorkbook As Object

Set Excel = GetObject(, "Excel.Application")

Set System = CreateObject("EXTRA.System")

Set Sess = System.ActiveSession

Set MyScreen = Sess.Screen

With Excel.Worksheets("Sheet1")

Row = 1

Do

Pull = .Cells(Row, "A").Value '**This will pull information from Excel

MyScreen.Putstring Pull, 3, 2 '**This will put information from Excel into Extra, use your own coordinates

.MoveRelative 1, 1, 1
.SendKeys ("<enter>")
Do Until (.WaitForCursor(3, 11))
DoEvents
Loop
NewPull = MyScreen.Getstring(9, 30, 20) '**This will pull information from Extra, use your own coordinates

.Cells(Row, "B").Value = NewPull '**This will place information from Extra to Excel

Row = Row + 1 '**This will progress the code to the next line

Loop Until .Cells(Row, "A").Value <> "" '** This will loop your code until there is a blank value in Column A in Excel

End With
 


"Still no luck."

Exactly WHAT does that mean? You must be specific about what is happening, and what you expect.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


BTW, I'm using Excel for this.
Code:
Sub ExcelExtraExcel()
'since "I'm using Excel for this," you do not need to set the Excel application object.

    Dim Pull as string, NewPull as string, lRow as long, System as Object, Sess as object, MyScreen as object
    
    Set System = CreateObject("EXTRA.System")
    
    Set Sess = System.ActiveSession
    
    Set MyScreen = Sess.Screen
    
    With Worksheets("Sheet1")
    
        lRow = 1
        
        Do
        
            Pull = .Cells(lRow, "A").Value  '**This will pull information from Excel
    
            MyScreen.Putstring Pull, 3, 2 '**This will put information from Excel into Extra, use your own coordinates
               
            MyScreen.MoveRelative 1, 1, 1
            MyScreen.SendKeys ("<enter>")

            Do Until (MyScreen.WaitForCursor(3, 11))
                DoEvents
            Loop

            NewPull = MyScreen.Getstring(9, 30, 20) '**This will pull information from Extra, use your own coordinates
                        
            .Cells(lRow, "B").Value = NewPull  '**This will place information from Extra to Excel
            
            lRow = lRow + 1  '**This will progress the code to the next line
            
        Loop Until .Cells(lRow, "A").Value <> ""  '** This will loop your code until there is a blank value in Column A in Excel
        
    End With


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I copied this exactly and when I ran it put the info from field A1 into Extra and hit enter....the screen was populated on Extra. It did not copy the NewPull field to Excel or loop to the next one. It only brought up the first record from the Excel list.
 



Did you STEP thru your code to see what is happeneing with your objects & variables?



Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


faq707-4594

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The problem is probably
Do Until (MyScreen.WaitForCursor(3, 11))

maybe shoud be

Do Until (MyScreen.WaitForCursor(3, 2))

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top