2016-11-21 72 views
0

我對QTP/UFT比較新。我正在編寫測試,需要在同一測試中使用Global和本地數據表中的數據。QTP/UFT - 訪問循環中的多個數據表

for循環是這樣的:

Datatable.GetSheet("Global") 
RowCount = Datatable.GetRowCount 
For Cntr = 1 to RowCount 
    Datatable.SetCurrentRow(Cntr) 
    msgbox Datatable("Form", dtGlobalSheet) 'Form is my column Name from Global Data Sheet' 

    Datatable.GetSheet("Action1") 
    RowCount2 = Datatable.GetRowCount 
    For Cntr2 = 1 to RowCount2 
     Datatable.SetCurrentRow(Cntr2) 
     msgbox Datatable("Number", dtGlobalSheet) 'Number is my column Name from Action1 Data Sheet' 
    Next 
Next 

我的列值都可以從兩個片搞砸了。

回答

1

您需要將您的數據表分配給變量,以便更好地使用它。

  • 您打電話給Datatable.GetSheet("Global"),但不能將它分配到任何地方。
  • 當你使用Datatable.GetRowCount你實際上並沒有告訴UFT從哪個數據表中獲得rowcount,這可能是你的問題之一。
  • 在代碼的末尾,您使用的是msgbox Datatable("Number", dtGlobalSheet),但您應該使用msgbox Datatable("Number", dtLocalSheet)(假設您在代碼的某處分配了這些變量)。

檢查這個可能的解決方案(未測試):

Dim dtGlobal : Set dtGlobal = Datatable.GetSheet("Global") 
Dim dtLocal : Set dtLocal = Datatable.GetSheet("Action1") 
RowCount = dtGlobal.GetRowCount 
For Cntr = 1 to RowCount 
    'Working with global datatable 
    dtGlobal.SetCurrentRow(Cntr) 
    msgbox dtGlobal.GetParameter("Form") 'Form is my column Name from Global Data Sheet' 

    'Working with local datatable 
    RowCount2 = dtLocal.GetRowCount 
    For Cntr2 = 1 to RowCount2 
     dtLocal.SetCurrentRow(Cntr2) 
     msgbox dtLocal.GetParameter("Number") 'Number is my column Name from Action1 Data Sheet' 
    Next 
Next 

PS:準確定義什麼數據即將從數據表,你可能要檢查你的循環,以確保在您的邏輯是正確的,因爲我沒有檢查那部分。讓我知道這是否適合你。

快樂編碼。

+1

感謝Victor的快速回復..這隻適用於一個更改..我使用UFT 12.54,它不支持dtGlobal.Value(「Form」)。所以我用dtGlobal.GetParameter(「Form」)代替它 – phpfreak

+0

我很高興它解決了。不幸的是我沒有UFT了,所以我從[tutorialspoint](https://www.tutorialspoint.com/qtp/qtp_data_table_methods.htm)檢查了方法,因爲我不記得它,並且無法事先測試它。我建議您將此網站加入書籤以備將來參考;) –

+0

當然,我確實。謝謝! – phpfreak