Dan13
Dan13

Reputation: 9

End without with using excel and IBM 3270 terminal

I am working on a macro to pull data of receipts and I need to only find the qty for today's receipts. Using the IBM terminal I bring up an excel worksheet and then proceed to make IBM go to screen I need and then look at the date on the screen and match it to the receipt date. if today's date doesn't match the receipt date on the first page then I need to have the macro press enter and then search the second page for the matching date and so on till the dates match or if they never do stop once the receipt date is blank. My code is below. Not sure where the open function is to not let the code finish. I am a novice and have no idea of formatting code, I apologize in advance.

Thanks for any help you provide.

Sub RMBR()
  Dim infile As String
  Dim part As String * 19, COMMENT As String * 7, COMMENT2 As String * 2
  Dim TDATE As String * 7, PLANT As String * 1
  Dim source As String
  Dim SELECTION As Integer, i As Integer, c As String
  Dim Result As Single
  Dim excel As Object
  Dim ACELL As Single, BCELL As Single, CCELL As Single, dcell As Single
  Dim Verify As Single

  infile = InputBox$("input FILE NAME INCLUDING PATH?", "FILE NAME", "C:\CFILES\rmbr.XLSX")
  TDATE = InputBox$("Input Status", "TDATE", "CURRENT")
  
  i = 2
  Set excel = CreateObject("EXCEL.APPLICATION")
  excel.Visible = True
  excel.Workbooks.Open FileName:=infile
  Verify = MsgBox("IS THIS THE CORRECT SPREADSHEET?", 4, "VERIFY SPREADSHEET")
  ACELL = "A2"
  BCELL = "B2"
  CCELL = "C2"
  DCELL = "D2"
  
  excel.Range("A1").Select
  excel.activecell.FormulaR1C1 = "PARTNO"
  excel.Range("B1").Select
  excel.activecell.FormulaR1C1 = "RMBR QTY"
  excel.Range("C1").Select
  excel.activecell.FormulaR1C1 = " "
  excel.Range("D1").Select
  excel.activecell.FormulaR1C1 = "TODAY'S DATE"
  excel.Range(ACELL).Select
  part = excel.activecell.FormulaR1C1
  excel.Range(BCELL).Select
  PLANT = excel.activecell.FormulaR1C1
  excel.Range(CCELL).Select
  COMMENT = excel.activecell.FormulaR1C1
  excel.Range(dcell).Select
  COMMENT2 = excel.activecell.FormulaR1C1
  
  Do Until partnumber = "                "
    With Session
      .TransmitTerminalKey rcIBMClearKey
      .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
      .WaitForEvent rcEnterPos, "30", "0", 1, 1
      .TransmitANSI "RMBR"
      .TransmitTerminalKey rcIBMEnterKey
      .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
      '.WaitForEvent rcEnterPos, "30", "0", 2, 6
      .WaitForDisplayString "FN:", "30", 2, 2
      .MoveCursor 4, 11
      .TransmitANSI part
      .TransmitTerminalKey rcIBMEnterKey
      .WaitForEvent rcKbdEnabled, "30", "0", 1, 1
      Date = .GetDisplayText(4, 73, 8)
      RIP.Date = .GetDisplayText(9, 73, 8)
      
      Dim n As Integer
      For n = 9 To 22
        Do Until Date = RIP.Date
          Date = .GetDisplayText(9, 73, 8)
          RIP.Date = .GetDisplayText(n, 73, 8)
        Loop
        If Date = RIP.Date Then
          Result = .GetDisplayText(n, 32, 6)
          excel.Range(BCELL).Select
          excel.activecell.FormulaR1C1 = Result
        End If
        If Date <> RIP.Date Then
          .TransmitTerminalKey rcIBMEnterKey
        End If
        Do Until Date = RIP.Date
          Date = .GetDisplayText(9, 73, 8)
          RIP.Date = .GetDisplayText(n, 73, 8)
        Loop
        Do Until RIP.Date = "        "
        Loop
        
        i = i + 1
        c = Trim$(Str$(i))
        ACELL = "A" + c
        BCELL = "B" + c
        CCELL = "C" + c
        excel.Range(ACELL).Select
        part = excel.activecell.FormulaR1C1
        excel.Range(BCELL).Select
        PLANT = excel.activecell.FormulaR1C1
        excel.Range(CCELL).Select
        COMMENT = excel.activecell.FormulaR1C1
        excel.Range(dcell).Select
        COMMENT2 = excel.activecell.FormulaR1C1
    End With
End Sub

Upvotes: 0

Views: 260

Answers (1)

Dominique
Dominique

Reputation: 17565

There are quite some issues in your code, let's have a look:

Plenty of this:

  excel.Range("A1").Select
  excel.activecell.FormulaR1C1 = "PARTNO"

You can replace this by (far more readable):

  excel.Range("A1").FormulaR1C1 = "PARTNO"

First:

  i = 2
  ACELL = "A2"

And later:

i = i + 1
c = Trim$(Str$(i))
ACELL = "A" + c

You can use this at the beginning too, so replace the first one by:

i = 2
c = Trim$(Str$(i))
ACELL = "A" + c

For-loop is not ended:

For n = 9 To 22
...
(Where's the Next, or the Step?)

Possible endless loop:

Do Until RIP.Date = "        "
Loop
(Two things: this is a possible endless loop, and second, what's with the list of spaces? You'd better say "... until Trim$(RIP.Date) = """)

Also the large loop is not ended:

Do Until partnumber = "                "
(same comment as above)

Please correct your code further (as your code does not even compile, it's almost impossible to help you further).
In top of this I see that you are mixing small letters and capitals. In Excel this is not a problem but other programming languages might have a problem with that. Please get a good habit of using the same "capitalising" system for all your variables.

Upvotes: 0

Related Questions