Hi all, I wrote a macro that will take a SSN input it and scrape the screen. This was all fine and dandy until now that I have to do the same for 20 or 30 SSNs at a time. I tried adding to the code to read from the file and loop until eof but I get a file already open error.
Seems logical to me but I'm not much of a programmer
Here is what I have:
' Get the next available file number
filenum2% = FreeFile
' Open the file.
Filename2$="C:\ssn.txt"
Open FileName2$ For Input as filenum2%
' Initialize Screen Buffer
screenbuf$ = ""
' Determine the size of the Presentation Space
MaxRows%=MyScrn.Rows()
MaxColumns%=MyScrn.Cols()
' Initialize variables to hold screen information
linebuf$ = Space$ (MaxColumns%)
do
Input # filenum2%, ssnum$
MyScrn.Sendkeys(ssnum$ + "<Enter>")
MyScrn.WaitHostQuiet(g_HostSettleTime)
' Copy the Presentation space
For row% = 3 to 4
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Copy the Presentation space
For row% = 8 to 9
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Copy the Presentation space
For row% = 10 to 22
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Move to the next Page if applicable
If MyScrn.GetString(24,2,2) <> "LAST PAGE" Then
MyScrn.Sendkeys("<pF8>")
End If
MyScrn.WaitHostQuiet(g_HostSettleTime)
' Copy the Presentation space
For row% = 12 to 22
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Get the next available file number
filenum% = FreeFile
' Open the file.
FileName$="C:\scrnout.txt"
Open FileName$ For Output as filenum%
' Print the screen with a form feed
Print # filenum%, screenbuf$;
'Close file
Loop until eof(filenum2%)
Close filenum%
System.TimeoutValue = OldSystemTimeout
Seems logical to me but I'm not much of a programmer
Here is what I have:
' Get the next available file number
filenum2% = FreeFile
' Open the file.
Filename2$="C:\ssn.txt"
Open FileName2$ For Input as filenum2%
' Initialize Screen Buffer
screenbuf$ = ""
' Determine the size of the Presentation Space
MaxRows%=MyScrn.Rows()
MaxColumns%=MyScrn.Cols()
' Initialize variables to hold screen information
linebuf$ = Space$ (MaxColumns%)
do
Input # filenum2%, ssnum$
MyScrn.Sendkeys(ssnum$ + "<Enter>")
MyScrn.WaitHostQuiet(g_HostSettleTime)
' Copy the Presentation space
For row% = 3 to 4
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Copy the Presentation space
For row% = 8 to 9
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Copy the Presentation space
For row% = 10 to 22
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Move to the next Page if applicable
If MyScrn.GetString(24,2,2) <> "LAST PAGE" Then
MyScrn.Sendkeys("<pF8>")
End If
MyScrn.WaitHostQuiet(g_HostSettleTime)
' Copy the Presentation space
For row% = 12 to 22
' Get a row of data from the host screen
linebuf$ = MyScrn.Area(row%, 2, row%, MaxColumns%, , xBlock)
' Store the line read into screenbuf$
screenbuf$ = screenbuf$ + linebuf$ + Chr$ (13) + Chr$ (10)
Next
' Get the next available file number
filenum% = FreeFile
' Open the file.
FileName$="C:\scrnout.txt"
Open FileName$ For Output as filenum%
' Print the screen with a form feed
Print # filenum%, screenbuf$;
'Close file
Loop until eof(filenum2%)
Close filenum%
System.TimeoutValue = OldSystemTimeout