×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBA code works fine in debug mode but not when I run it

VBA code works fine in debug mode but not when I run it

VBA code works fine in debug mode but not when I run it

(OP)
Hi,

I'm new to VBA and it's really hard to any information online. I have written a code to basically scrape values from the DD.3 screen and paste them into excel sheet.

The code executes without any issues in debug mode, but the cursor seems to have a mind of its own when I run the code.
Any help would be much appreciated.

Sub Main()
Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object
Dim oWS As Worksheet
Set Sys = CreateObject("EXTRA.System")
Dim SIN As String

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

Set oWS = ThisWorkbook.Sheets("DATA") '... Stores reference to data worksheet
Row = 2
lastRow = oWS.Cells(50000, 1).End(xlUp).Row


For Row = 2 To lastRow

SIN = Trim(oWS.Cells(Row, 1))
MyScreen.MoveTo 1, 20
MyScreen.SendKeys (SIN)
MyScreen.SendKeys ("<enter>")

Do Until Len(MyScreen.Search("T4 ")) > 0 Or MyScreen.GetString(2, 2, 6) = "ME 039"
MyScreen.MoveTo 1, 1

MyScreen.SendKeys ("<pf8>")
Loop
If Len(MyScreen.Search("T4 ")) > 0 Then
MyScreen.MoveTo MyScreen.Search("T4 ").Bottom, MyScreen.Search("T4 ").Right - 12
MyScreen.SendKeys ("x")
MyScreen.SendKeys ("<enter>")


Do Until MyScreen.GetString(1, 67, 3) <> "T4 " Or MyScreen.GetString(2, 2, 6) = "ME 039"
For i = 2 To 15
If MyScreen.GetString(1, 67, 3) = "T4 " Then
oWS.Cells(Row, i) = MyScreen.GetString(21, 16, 10)
MyScreen.SendKeys ("<pf8>")
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
i = 15
End If
End If
Next i
Loop
If MyScreen.GetString(2, 2, 6) = "ME 039" Then
End If
End If


Next
End Sub



RE: VBA code works fine in debug mode but not when I run it

Hi,

I'd suggest you READ, fully UNDERSTAND and then IMPLEMENT the Wait measures you absolutely need to include in your code, the FAQ link below.

The tip-off was in "The code executes without any issues in debug mode, but the cursor seems to have a mind of its own when I run the code."

When you're in Debug Mode, the mainframe has a virtual ETERNITY to process each statement, but when your code is operating seemingly at WARP SPEED, compared to what's happening between your PC and the mainframe (I/O) and in the mainframe, all happening in a "black box" of indeterminable duration, your code is haplessly plunging into the next statement instead if WAITING for feedback to GO!

Naturally, if you need help implementing these measures in your code, please do not hesitate to ask for help after you read the FAQ.

FAQ99-7887: Why WAIT? Or how long should I WAIT?

BTW, you have 6 SendKeys commands to compensate for.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code works fine in debug mode but not when I run it

...also you appear to be misusing SendKeys when all you intend is to place characters on MyScreen...

CODE

SIN = Trim(oWS.Cells(Row, 1))  'you really don't appear to use this variable again
MyScreen.MoveTo 1, 20
MyScreen.SendKeys (SIN)
MyScreen.PutString Trim(oWS.Cells(Row, 1)), 1, 20
MyScreen.SendKeys ("<enter>")
Do Until WaitForCursor(row, col) 
    DoEvents 
Loop 
Of course you'll need to use the Cursor Rest Coordinates for the screen that returns after the SendKeys executes.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code works fine in debug mode but not when I run it

did you get it working?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code works fine in debug mode but not when I run it

Hello? Are you there?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: VBA code works fine in debug mode but not when I run it

Guess you've given up!

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close