2011-04-07 73 views
0

簡單的問題,我希望。所以我需要確保labels.text和labels2.name是平等的。我認爲它很簡單,我將標籤重新命名爲與標籤相同的名稱,我也將它比較,但它出現錯誤。任何幫助?在visual basic中比較lbl.txt和lbl.name

回答

1

這些WebForms或WinForms標籤?用下面的'ID'代替你想要檢查的財產。

Dim areSame As Boolean = (lblFirst.Text=lblSecond.ID) 

或者你可以使用.NET String.Compare()

Dim areSame As Boolean = String.Compare(lblFirst.Text, lblSecond.ID)=0 

對於case-sensitivity with String.Compare()

Dim areSame As Boolean = String.Compare(lblFirst.Text, lblSecond.ID, False)=0