【问题标题】:How to show the comment line from a variable?如何显示变量的注释行?
【发布时间】:2020-11-24 12:24:47
【问题描述】:

我需要显示一个带有变量值的 MsgBox,以及该变量中的注释行。

Sub Main

Dim Sys As Object, Sess As Object, MyScreen As Object
Set Sys = CreateObject("EXTRA.System")
Set Sess = Sys.ActiveSession
Set MyScreen = Sess.Screen

Dim a(3) as string, i as integer

a(0) = "123 321 231" ' Lorem ipsum dolor sit amet
a(1) = "211 321 331" ' Consectetur adipiscing elit
a(2) = "121 331 111" ' Sed do eiusmod tempor incididunt
a(3) = "511 321 277" ' Quis nostrud exercitation ullamco

for i = 0 to ubound(a)
  if a(i) = Sess.screen.GetString(04, 19, 11) then msgbox a(i) & "Plus the comment line"
next

End Sub

【问题讨论】:

    标签: vba attachmate-extra


    【解决方案1】:

    如果你切换到对“a”使用锯齿状数组,一切都会好起来的。

    Sub Main()
    
        Dim Sys As Object, Sess As Object, MyScreen As Object
        Set Sys = CreateObject("EXTRA.System")
        Set Sess = Sys.ActiveSession
        Set MyScreen = Sess.screen
    
        Dim a(3) As Variant, i As Integer
    
        a(0) = Array("123 321 231", "Lorem ipsum dolor sit amet")
        a(1) = Array("211 321 331", "Consectetur adipiscing elit")
        a(2) = Array("121 331 111", "Sed do eiusmod tempor incididunt")
        a(3) = Array("511 321 277", "Quis nostrud exercitation ullamco")
    
        For i = 0 To UBound(a)
            If a(i)(0) = Sess.screen.GetString(4, 19, 11) Then MsgBox a(i)(0) & a(i)(1)
        Next
    
    '  Or in a more expressive way
        
    '    Dim myItem As Variant
    '    For Each myItem In a
    '
    '        If myItem(0) = Sess.screen.GetString(4, 19, 11) Then MsgBox myItem(0) & myItem(1)
    '
    '    Next
    
    End Sub
    

    【讨论】:

    • 这是一个非常快速的答案!非常感谢!
    • 不幸的是,额外的 Attachmate!我正在使用的 V8 似乎没有锯齿状数组元素,有没有其他方法可以使用这个有限版本的 VBA 来实现类似的结果?谢谢。
    • 如果您使用的 VBA 支持变体,它将支持锯齿状数组。另一种方法是使用集合或 scripting.dictionary。对于集合,将 a 定义为集合。那么您将使用 a.add Array("123 321 231", "Lorem ipsum dolor sit amet")。获取信息是 a.item(x)(y)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2011-05-26
    • 2019-12-19
    • 1970-01-01
    相关资源
    最近更新 更多