【问题标题】:How To Create A Loop To Move To The Next Line如何创建循环以移动到下一行
【发布时间】:2019-11-13 08:14:54
【问题描述】:

我正在使用 3270 终端大型机。我有一个有 30 个位置的屏幕,我需要在其中读取文本文件并将 A 列中的值粘贴到屏幕上的 30 个不同位置。文本文件可能有任意数量的行,但每次迭代我只有 30 个位置可以粘贴。填满这 30 个位置后,我单击 Enter,这会清除屏幕,然后我可以再粘贴 30 个,依此类推。如果还有 30 个要粘贴,则可能少于 30 个。

文本文件中只有一列(A 列)。文本文件的 A 列第 1 行将粘贴到第一个位置。 A 列第 2 行将粘贴到第二个位置,依此类推...

我创建了一个循环,它从我的文本文件中读取并将值提取到我的代码中,并且我可以将值粘贴到第一个位置。然后我需要移动到下一行并将下一个值粘贴到下一个位置。我正在尝试这样做,而不必创建 30 个不同的 Do..Until 循环。

这是我从文本文件中读取的循环,它有效:

Sub sub_Run_Loop
    i = 0
    CountLoans = 0
    Do Until objFile.AtEndOfStream
        strLine = objFile.ReadLine
        arrFields = Split(strLine, ",")
        subDoWork (i)
        i = i + 1
    Loop
End Sub

Sub subDoWork (i)
    ColumnA    = arrFields(0)
    CurrentRow = i
    ActualRow  = CurrentRow - 1

    For CurrentRow = 1 To ActualLoans
        subMoveCursor 13, 4
        subEnterData ColumnA
        CountLoans = CountLoans + 1
    Next
    i = i + 1

    'At Right here, I need to move to the next value in Column A
    'from the text file and paste to the next position

    subMoveCursor 14, 4
    subEnterData ColumnA
    CountLoans = CountLoans + 1

    CountLoans = CountLoans + 1
    If CountLoans >= ActualLoans Then
        subEndScript
    End If
End Sub

我试图从一行移动到下一行,同时将值粘贴到不同的位置,而不必创建 30 个不同的循环。

【问题讨论】:

  • 我认为完成此任务的最简单方法是使用全局变量将所需的起始行简单地提供给循环并将其增加所需的数字(在您的情况下为 30),.在循环中,跟踪读取的行数,然后 SkipLine() 直到达到所需的行数,然后读取到所需的行数。这种方法的缺点是您读取文件 totallines/30 次。
  • 感谢您的帮助!
  • 注意:我有 Row 和 Column 向后。列实际上是行,反之亦然

标签: loops vbscript next


【解决方案1】:

我解决了这个问题。我所做的是在保持我需要粘贴到的位置的三列上设置一个阈值,并在每次迭代 30 后将该阈值增加 10(每列 10 行)。我还在循环中重新组织了我的计数,这似乎解决了在三列中按顺序移动的问题。

    Sub sub_Run_Loop
       Column1Threshold = 10 
       Column2Threshold = 20
       Column3Threshold = 30
       CountButtonClicks = 0
       ClickTime = 30
       i = 1
       CountLoans = 1
       Column = 13


    Do Until objFile.AtEndOfStream
     strLine = objFile.ReadLine
            arrFields = Split(strLine,",")              
            subDoWork (i)               
    i = i + 1
    CountLoans = CountLoans + 1
    Column = Column + 1     
    If Column > 22 Then 
            Column = 13
    End If

    If CountLoans > ClickTime Then
            subPressKey "@E"
            Column1Threshold = Column1Threshold + 10
            Column2Threshold = Column2Threshold + 10
            Column3Threshold = Column3Threshold + 10
            ClickTime = ClickTime + 30
            CountButtonClicks = CountButtonClicks +1
    End If                  

    If CountLoans > ActualLoans Then
            subEndScript    
    End If
    Loop
 End Sub



Sub subDoWork (i)
    ColumnA     = arrFields(0)
    CurrentRow  = i     

    If CountLoans <= Column1Threshold Then                  
        Row = 4
    End If

    If CountLoans > Column1Threshold Then
        Row = 31
    End If

    If (CountLoans >= Column2Threshold) and (CountLoans <= 
    Column3Threshold) Then
        Row = 58
    End If

    subMoveCursor Column, Row                                                           
    subEnterData ColumnA
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-20
    • 2019-05-22
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多