I am writing this macro to take a list of account numbers in column A of an excel sheet, enter those accounts in a terminal program called attachmate, and retrieve a SSN#, EIN# or a Central Bill #. I have been able to get it working until the point where I had to write multiple if/else statements to determine which type of # to retrieve.
The conditions are based on checking the Visa Type of the account after each account number is entered into attachmate.
In attachmate:
If Visa Type is not the letter "B" or Null, then get the SSN # which is located on the same page
If Visa type is null, then check if there is a visatype MCB
If Visa type MC-B is in the specified location, then get the Central Bill # which is located on the same page
if Visa type is "B" then send keystrokes F4,F5,F5 to go to page with EIN#
if EIN# is "000000000" then send keystroke F9 to go back to page with Central Bill # and get Central Bill#
This is the logic behind how I need to determine which number to get. I am new to learning VBA and learning fast, but I need help with writing this correctly, structuring it correctly and declaring variables correctly. I also tried to use a Select Case method but had difficulty with that as well. This is a little more complex than what I have written so far because it is working in Attachmate and is running in a For Next loop.
I only included the section I need help with
Any help would be greatly appreciated
Code:
For p = 1 To 10000 Step 59
For r = p + 7 To p + 58 Step 4
pull = Cells(r, 1).Value ' declare as variable?
Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' Waits for attachmate before moving to next acct#
Sess0.screen.PutString pull, 1, 7 ' enters acct# into line 1 column 7 in attachmate
Sess0.screen.SendKeys ("0091 <Enter>") ' enter keystrokes in attachmate
Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' need to wait for attachmate after using sendkeys
If InStr(Sess0.screen.GetString(3, 36, 1), "B") Then ' if the letter B is in this location get TIN#
Sess0.screen.SendKeys ("<Pf4> <Pf5> <Pf5> <Pf5>") ' enter keystrokes to get to page with TIN#
Sess0.screen.WaitHostQuiet (g_HostSettleTime) '
tnpull = Sess0.screen.GetString(20, 58, 10) 'declare as variable?
Cells(r, 2).Value = tnpull 'enters EIN# into excel from attachmate
ElseIf InStr(tnpull, "000000000") Then
Sess0.screen.SendKeys ("<Pf9>")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
cbpull = Sess0.screen.GetString(20, 58, 10)
Else
snpull = Sess0.screen.GetString(12, 6, 11) ' declare as variable?
Cells(r, 2).Value = snpull 'enters SSN# into excel from attachmate
End If
Sess0.screen.SendKeys ("<clear>") ' clear page and repeat
Next
Next
End Sub
The conditions are based on checking the Visa Type of the account after each account number is entered into attachmate.
In attachmate:
If Visa Type is not the letter "B" or Null, then get the SSN # which is located on the same page
If Visa type is null, then check if there is a visatype MCB
If Visa type MC-B is in the specified location, then get the Central Bill # which is located on the same page
if Visa type is "B" then send keystrokes F4,F5,F5 to go to page with EIN#
if EIN# is "000000000" then send keystroke F9 to go back to page with Central Bill # and get Central Bill#
This is the logic behind how I need to determine which number to get. I am new to learning VBA and learning fast, but I need help with writing this correctly, structuring it correctly and declaring variables correctly. I also tried to use a Select Case method but had difficulty with that as well. This is a little more complex than what I have written so far because it is working in Attachmate and is running in a For Next loop.
I only included the section I need help with
Any help would be greatly appreciated
Code:
For p = 1 To 10000 Step 59
For r = p + 7 To p + 58 Step 4
pull = Cells(r, 1).Value ' declare as variable?
Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' Waits for attachmate before moving to next acct#
Sess0.screen.PutString pull, 1, 7 ' enters acct# into line 1 column 7 in attachmate
Sess0.screen.SendKeys ("0091 <Enter>") ' enter keystrokes in attachmate
Sess0.screen.WaitHostQuiet (g_HostSettleTime) ' need to wait for attachmate after using sendkeys
If InStr(Sess0.screen.GetString(3, 36, 1), "B") Then ' if the letter B is in this location get TIN#
Sess0.screen.SendKeys ("<Pf4> <Pf5> <Pf5> <Pf5>") ' enter keystrokes to get to page with TIN#
Sess0.screen.WaitHostQuiet (g_HostSettleTime) '
tnpull = Sess0.screen.GetString(20, 58, 10) 'declare as variable?
Cells(r, 2).Value = tnpull 'enters EIN# into excel from attachmate
ElseIf InStr(tnpull, "000000000") Then
Sess0.screen.SendKeys ("<Pf9>")
Sess0.screen.WaitHostQuiet (g_HostSettleTime)
cbpull = Sess0.screen.GetString(20, 58, 10)
Else
snpull = Sess0.screen.GetString(12, 6, 11) ' declare as variable?
Cells(r, 2).Value = snpull 'enters SSN# into excel from attachmate
End If
Sess0.screen.SendKeys ("<clear>") ' clear page and repeat
Next
Next
End Sub