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

Statement return 1

Status
Not open for further replies.

jschmidt1

IS-IT--Management
Aug 13, 2015
12
US
Skip,
I was able to fix the For, next issue, but I'm still missing something. My variables are not working, they are returning the same values, and are not capturing the values for all the pages in the statements.
Code:
  Sess0.Screen.Sendkeys("<Reset>")
   Sess0.Screen.Sendkeys("<Clear>")
   Sess0.Save
    Do Until Sess0.Screen.WaitHostQuiet(g_HostSettleTime) 
      DoEvents
   Loop 
   Sess0.Screen.Sendkeys("cis "& acnt$)
   Sess0.Screen.Sendkeys("<Enter>")
   Sess0.Screen.Sendkeys("css")
   Sess0.Screen.Sendkeys("<Enter>")
    Do Until Sess0.Screen.Getstring(02,52,02) <= Sess0.Screen.Getstring(02,60,02)
     DoEvents
      Loop

        For i = 1 To 3
            For rw = 5 To 19
        
                Ret1$ = Sess0.Screen.Getstring(rw,04,04)
                Ret1a$ = Sess0.Screen.Getstring(rw,26,05)
                Ret1b$ = Sess0.Screen.Getstring(rw,72,08)
                Sess0.Screen.Sendkeys("<Pf8>")
                Ret2$ = Sess0.Screen.Getstring(rw,04,04)
                Ret2a$ = Sess0.Screen.Getstring(rw,26,05)
                Ret2b$ = Sess0.Screen.Getstring(rw,72,08)  
                WRITE #2,acnt$,Ret1$,Ret1a$,Ret1b$,Ret2$,Ret2a$,Ret2b$
         
       Next
'          Next
       
'        Sess0.Screen.Sendkeys("<Pf8>")	
'        If Sess0.Screen.Getstring(02,52,02) <> Sess0.Screen.Getstring(02,60,02)+1 then
'        Do Until Sess0.Screen.Getstring(02,52,02) <= Sess0.Screen.Getstring(02,60,02)
'            DoEvents 
'        Loop
'              
'        For j = 1 To 3
'            For rw = 5 To 19  
'                Ret2$ = Sess0.Screen.Getstring(rw,04,04)
'                Ret2a$ = Sess0.Screen.Getstring(rw,26,05)
'                Ret2b$ = Sess0.Screen.Getstring(rw,72,08)   
'  
'                WRITE #2,acnt$,Ret2$,Ret2a$,Ret2b$
                

'         Next
            Sess0.Screen.Sendkeys("<Enter>")
'           Do Until Sess0.Screen.WaitForCursor(01, 02) 'Kept as alernative in event 'Do Until' below doesn't work
            Do Until Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
                DoEvents
            Loop 
            Sess0.Save
     Next
XXX: 
LOOP


CLOSE #1

msgbox "Your macro is complete, have a nice day."
End Sub

I left the old code so you could see my changes and hopefully my logic with that I am trying to do. Thanks Skip!

James
 
Hi,

1) I’m confused.

What about the beginning of your outer loop...
Code:
Do While Not EOF(1)

   Input #1,acnt$

   ACNT$ = LEFT$(ACNT$,16) 

   WRITE #2,acnt$

‘...

2) When you SendKeys this...
Code:
Sess0.Screen.Sendkeys("cis "& acnt$)
...does your screen change, cuz if it does, you need to [tt]WaitFor...[/tt] feedback, until the system is ready.

And you have a bunch of those, including the <PF8>s.

3) Blocks must be nested. Each [tt]Sub...End Sub[/tt], each [tt]For...Next[/tt], each [tt]If...Then...End If, [/tt]each [tt]Do...Loop[/tt] must be totally within a block.

Style wise, I like to indent each block. Procedurally, I enter the skeleton form of my block to insure that I’ve added all the essential elements, and once established, I fill in the particulars. The Excel VBA editor actually helps you out when you set up a Sub or Function, by automatically giving you an End Sub or End Function.
Code:
Sub MyTest()
   
End Sub

BTW, I’ve done ALL my Attachmate screen coding in Excel because a) the VBA Editor is soooo much better and b) because my screen scrapes akways begin with a list from Excel and end up as a list in Excel.

Here’s the beginning of a loop...
Code:
Sub MyTest()
   Dim i As Integer

   For i = 1 To 3

   Next
End Sub

Here’s the beginning of an If, where x is just a temporary placeholder...
Code:
Sub MyTest()
   Dim i As Integer

   For i = 1 To 3
      If x Then

      Else

      End If
   Next
End Sub

I have my block structures in place. Any other blocks must reside totally within an existing block.

Can’t have this...
Code:
Sub MyTest()
   Dim i As Integer, j As Integer

   For i = 1 To 3
      If x Then

      Else
         [b]For j = 1 to 2[/b]
      End If
   Next
         [b]Next[/b]
End Sub

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Thanks skip, I've never used the Excel macro editor before, and it did help me line things up (as well as your explanation). I made a couple changes to make it even easier to read with the variables (at least I think)
Code:
    Dim PageNo As Integer
    Dim Month As Integer
    Dim Pages As Integer
        
    Do While Not EOF(1)

        Input #1, acnt$
        acnt$ = LEFT$(acnt$, 16)
        
        Sess0.Screen.Sendkeys ("<Reset>")
        Sess0.Screen.Sendkeys ("<Clear>")
        Sess0.Save
        Sess0.Screen.Sendkeys ("cis " & acnt$)
        Sess0.Screen.Sendkeys ("<Enter>")
                
        Sess0.Screen.Sendkeys ("css")
        Sess0.Screen.Sendkeys ("<Enter>")
                
        For Month = 1 To 3
             Sess0.Screen.Sendkeys ("<Enter>")
             PageNo = Sess0.Screen.Getstring(2, 60, 2)          
             
             For Pages = 1 To PageNo
               
                For rw = 5 To 19
                
                    Ret1$ = Sess0.Screen.Getstring(rw, 4, 4)
                    Ret1a$ = Sess0.Screen.Getstring(rw, 26, 5)
                    Ret1b$ = Sess0.Screen.Getstring(rw, 72, 8)
                    
                    Write #2, acnt$, Ret1$, Ret1a$, Ret1b$
                Next
                
                Sess0.Screen.Sendkeys ("<Pf8>")
                
             Next
        
        Next    
        
       
        
    Loop
    
    Sess0.Screen.Sendkeys ("<Clear>")


    Close #1
    Close #2
    
msgbox "Your macro has been completed. Have a nice day."

End Sub
Thank you again for your help!
James
 
Much better!

I’d suggest some tips on variables.

Stay away from variable names like

Year, Month, Day, Hour, Minute, Second, Page, Pages

Most are reserve words, Function Names.

Some programmers use naming conventions for variables that give an indication of the Data Type:

i for Integer... Dim iCnt As Integer
l for Long... Dim lRow As Long
s for String... Dim sSQL As String
ws for Worksheet... Dim wsMaster As Worksheet
wb for Workbook... Dim wbAccounts As Workbook
r for Range... Dim rAccounts As Range
o for Object... Dim oScreen As Object
d for Date... Dim dStart As Date, dDate As Date

Once you “format” your declarations, the Excel VBA Editor will provide the capitalization that you provided in your declarations. Same with reserve words like for, next, if, then, else, date, now. It’s a good self-check. If what you thought was a reserve word spelling isn’t, it won’t get capitalized.

Have fun!

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