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!

Compile error on End Sub

Status
Not open for further replies.

link99sbc

Technical User
Apr 8, 2009
141
US
What would cause a compile error on End Sub??????
 



Compilers are renown for returning misleading messages.

Please post your code.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Shell "Notepad c:\My Documents\Print.txt"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "%{tab}"

Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object

Sess0.Screen.Sendkeys("<PF10>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 10,67

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

x = 10

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.Copy
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if


x = 10

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.Copy
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 11

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 11

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 12

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 12

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 13

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 13

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if




Sess0.Screen.Sendkeys("<PF3>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.Paste
Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue


for x = 0 to 9

a = sess.getstring (21,12, 1)

if a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop

Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue

End IF

If a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue

End IF

If a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' Prints the File
' Sendkeys "%FP"

End If

System.TimeoutValue = OldSystemTimeout



End Sub
 


Please post ALL, meaning your ENTIRE procesure if you would like some help.

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

' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

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 = 500 ' 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)

' This section of code contains the recorded events

Shell "Notepad c:\My Documents\Print.txt"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "%{tab}"

Dim Sys As Object, Sess As Object, MyScreen As Object, MyArea As Object

'Gets the Other Tins
Sess0.Screen.Sendkeys("<PF10>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 10,67

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

x = 10

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.Copy
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if


x = 10

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.Copy
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 11

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 11

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 12

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 12

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 13

a = sess.getstring (x, 67, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,68,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if

x = 13

a = sess.getstring (x, 66, 1)

if a = ">" then

Set MyArea = MyScreen.Area(10,67,10,77)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

end if




Sess0.Screen.Sendkeys("<PF3>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.Paste
Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue


for x = 0 to 9

a = sess.getstring (21,12, 1)

if a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop

Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue

End IF

If a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)


' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.MoveTo 21,05
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("SCREEN")
Sess0.Screen.PasteContinue

End IF

If a = "" then

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop

' Prints the File
' Sendkeys "%FP"

Else

IF a = "x" then

Sess0.Screen.Sendkeys("<Enter>")
Do While sess0.Screen.OIA.Xstatus <> 0
DoEvents
Loop
Set MyArea = MyScreen.Area(01,02,20,80)
MyArea.Select
Sess0.Screen.CopyAppend
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

AppActivate "Print.txt - Notepad"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sendkeys "{Enter 8}%EP"
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' Prints the File
' Sendkeys "%FP"

End If

System.TimeoutValue = OldSystemTimeout

End Sub
 

The problem is not with the End Sub statement! After making several syntax corrections, as outlined below, your code COMPILED. That does not mean that it is CORRECT!

You have absolutely horrendously sloppy coding!

Your If...Else...End If structures - HORRIBLE!

Your For...Next structure - HORRIBLE!

You are missing THREE End If's and a NEXT!

I cannot correct your code, because I do not know your requirement logic.

YOU must have an END IF for every BLOCK If.

YOU must have a Next for every For.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Well I'm just learning. I don't have experience with If Statements and reviewing some posts on here I was trying to make something work.

I have a screen that has > 5326547
> 65479895
> 6587961
> 8567421

The screen could have any where from 1-4 lines. I need to copy the first line after the first > (just the numbers) then go to the next line and copyappend "if it exists" and so on until I copy each line of numbers.

Then I go to line 21,12 and paste, enter, copyappend the whole screen, go to line 21,12, pastecontinue. At this point I'm trying to determine if any numbers pasted because sometimes there are less than 4 lines. If they did paste then enter and copyappend the next page, if nothing exists at 21,12 then go to the txt file and paste then print.


 


from 1-4 lines
Starting in what row/column?
Then I go to line 21,12 and paste, enter, copyappend the whole screen
You have 'copy/appended' 1 to 4 strings of numbers. Then you PASTE this string at 21,12 and then do another copy/append ALL the data in the entire screen, so that you end up with a screen's worth of data PLUS the 1 to 4 strings of numbers?

I'm not getting the purpose of this exersize!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Quote:
from 1-4 lines

> line 10,67 numbers are at 10,69,10,77
> line 11,67 numbers are at 11,69,11,77
> line 12,67 numbers are at 12,69,12,77
> line 13,67 numbers are at 13,69,13,77

There are not always 4 lines of numbers on this particular screen.

Quote:
"Then I go to line 21,12 and paste, enter, (brings up the next screen I have to grab) copyappend the whole screen" then go back to line 21,12 pastecontinue which paste's the next row of numbers from line 11.

If I use COPY to copy the whole screen, I loose the rest of the numbers. If I use COPYAPPEND I don't loose the numbers. So I get all the screens that need to be copied then paste to the file.

I hope this makes sense.


 

I AM CONFUSED!!!

You stated...
I have a screen that has > 5326547
> 65479895
> 6587961
> 8567421

The screen could have any where from 1-4 lines. I need to copy the first line after the first > (just the numbers) then go to the next line and copyappend "if it exists" and so on until I copy each line of numbers.
which indicates that the code loops thru these 4 rows and ens up with a string 53265476547989565879618567421

then you state
Then I go to line 21,12 and paste, enter, copyappend the whole screen,
so you 'paste' 53265476547989565879618567421 at 21,12 hit ENTER and then copy/append the current screen?

Frankly, I do not know what 'copy/append' is

Code:
dim r as integer, sVal as string

'concatenate numeric strings
sVal = ""
for r = 10 to 13
   if IsNumeric(Trim(Sess0.Screen.getstring(r, 69, 9))) then
      sVal = sVal & Trim(Sess0.Screen.getstring(r, 69, 9))
   else
      exit for
   end if
next

Sess0.Screen.PutString sVal 21,12 

Sess0.Screen.SendKeys("<ENTER>")

Sess0.Screen.Copy


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

This only works in attachmate!
When you copy something, it is put in a buffer. When you copyappend, it is added to the buffer as a seperate item. If I copy something then copyappend 3 more items, I have 4 items in the buffer. Then I paste the first item, then pastecontinue which will paste the next item in the buffer and so on. If I want to copy something in between paste and pastecontinue (like the whole screen), I copyappend again and it is added to the buffer as the 5th item. Everything stays in the buffer in the order it was copyappended until you use COPY again. Then the buffer is cleared and you have just the item copied. If you want another item, use copyappend again. Then you can PASTE the first item then PASTECONTINUE for the second item.

So if I have 4 lines of numbers, I copy the first line, copyappend the next 3 so I have 4 items in the buffer. At line 21,12 I paste the first item, press enter which brings up the next screen. I copyappend the whole screen which makes it the 5th item in the buffer. Then at line 21,12 I pastcontinue which will paste item 2 in the buffer, press enter, copyappend the whole screen which is item 6 in the buffer and so on. By the time I get 4 whole screens in the buffer, I have a total of 8 items. The 4 lines of numbers and 4 whole screens. Then I Appactivate the file and paste the whole thing in the file. Pasting in Notepad will just paste everyting in the buffer at once.
Hope this makes it clear. Thanks.
If you have a better way to get the screens to the file I'm open to suggestions. I usually paste a screen to the file and add 8 returns then paste the next screen and add 8 returns. So when I print the file it has 2 screens per page and none of screens are split from one page to the other.
 


Personally, I greatly prefer to code my VBA in Excel, since I am either puting data from Excel into the emulator or reading data from the emulator into an Excel sheet. I tolerate the idiosyncrasies of the 3270.

So I can only tell you the method that I would use, would be somethig like...
Code:
dim r as integer, sVal as string

'concatenate numeric strings
sVal = ""
for r = 10 to 13
   Sess0.Screen.MoveRelative 1, 1, 1
   Sess0.Screen.SendKeys("<XYZ_Screen>")
   Do Until .WaitForCursor(3, 19)  'these coordinates resting position for screen XYZ_Screen
      DoEvents
   Loop

   if IsNumeric(Trim(Sess0.Screen.getstring(r, 69, 9))) then
      sVal = sVal & Trim(Sess0.Screen.getstring(r, 69, 9))

      Sess0.Screen.PutString sVal 21,12 

      Sess0.Screen.SendKeys("<ENTER>")

      Sess0.Screen.Copy

      'etc code....
      
   else
      exit for
   end if
next

Sess0.Screen.PutString sVal 21,12 

Sess0.Screen.SendKeys("<ENTER>")

Sess0.Screen.Copy

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top