下面是我的数组和代码,用于检查文本框中的数据是否在数组中。问题是,当我运行程序时,数组的值总是“”或没有找到数据..我的代码有什么问题?请帮帮我..谢谢。
a = Split((a), vbTab)
devices = Array("iPhone5", "iPhone4", "iPhone3", "iPad", "iPod", "iPhone4s", "iPhone3G", "iPhone3gs", "gt-s5360", "gt-i9505", "n7100", "gt-n7100", "i9300", "gt-i9300", "gt-p3100", "s5300", "gt-s5300", "gt-s7562", _
"gt-i8190", "s100", "p5100", "gt-p5100", "gt-s6102", "gt-i9100", "gt-p3110", "gt-p6200", "n8000", "gt-n8000", "gt-i9082", "sm-t210", "gt-n7105", "n7000", "gt-n7000", "gt-n5100", "GT-S5570", "GT-S5830i", _
"GT-S5830", "GT-I8262", "GT-P1000", "Nexus 7", "GT-I8160", "H120", "ALCATEL ONE TOUCH 918N", "HuaweiG510-0200", "MyPhone A919 Duo", "MyPhone A848i Duo", "C6603", "ALCATEL ONE TOUCH 4030E", "LG-E400", _
"GT-P6800", "ICE 350e", "GT-I9070", "ALCATEL ONE TOUCH 5021E", "Cherry w500", "GT-I8150", "LT22i", "Spark TV", "I9500", "GT-I9500", "Burst S280", "W120", "GT-P7500", "MyPhone A888 Duo", "GT-S5301", "Thunder S220", "GT-S7500", _
"GT-I8552", "SM-T211", "GT-S5282", "A818 Duo", "LT26i", "GT-S6802", "GT-S5570I", "HuaweiY210-0100", "LT26w", "HTC One", "ST23i", "ST27i", "SHW-M250S", "Cruize W280", "Titan TV S320", "B1-A71", "GT-I9152", "W110", "7038", _
"LT18i", "GT-P3113", "GT-I9000", "Cherry Sonic", "GT-S5670", "SHW-M110S", "ST26i", "SonyEricssonMT25i", "Excite_352g", "LT25i", "Lenovo A390_ROW", "ST25i", "LG-E612", "GT-I9003")
urls = Array("youtube.com", "ytimg.com", "DoubleClick.net", "google.com", "fbcdn.net", "google -analytics.com", "yimg.com", "googlesyndication.com", "facebook.com", "gstatic.com", "mywebacceleration.com", "yahoo.com", "scorecardresearch.com", _
"google.com.ph", "adnxs.com", "redtubefiles.com", "rubiconproject.com", "wattpad.net", "www.com", "youjizz.com", "bing.net", "akamaihd.net", "xvideos.com", "tumblr.com", "twitter.com", "yieldmanager.com", "sharethis.com", "wikimedia.org", _
"y8.com", "sulitstatic.com", "globe.com.ph", "googleapis.com", "tagstat.com", "quantserve.com", "addthis.com", "blogspot.com", "king.com", "cloudfront.net", "ayosdito.com", "ask.com", "openx.net", "bigspeedpro.com", "gravatar.com", _
"amasvc.com", "bing.com", "cdn.com", "yldmgrimg.net", "cedexis.com")
For intX = 0 To UBound(a)
If Text11.Text = "" Then
a(intX) = UCase(a(intX))
Text11.Text = a(intX)
ElseIf Text12.Text = "" Then
a(intX) = UCase(a(intX))
Text12.Text = a(intX)
If Len(Text12.Text) <= 17 Then
Text12.Text = ""
Else
b = Split(Text12.Text, "/")
For i = 0 To UBound(b)
Text12.Text = b(2)
Next
Text12 = InStr(Text12, urls)
If Text12 = UCase(urls) Then
Text22 = Text12
Text25 = count + 1
Else
Text26 = Text12
Text27 = othercount + 1
End If
End If
答案 0 :(得分:1)
您可以使用ForEach使其更有效。 或者使用此功能... :)
Public Function IsContained(theArray() As Variant, strSearchPharse As String, Optional IsMatch As Boolean = False, Optional IsCaseSensitive As Boolean = True) As Boolean On Error Resume Next If Not UBound(theArray) 0 Then End Dim strExploded As String Dim gsChache As Boolean gsChache = False 'set the default value 'Checking for every array thing For Each strExploded In theArray If IsMatch And Not (Len(strSearchPharse) = Len(strExploded)) Then 'if its matchable... If IsCaseSensitive And strExploded = strSearchPharse Then gsChache = True If Not IsCaseSensitive And LCase(strExploded) = LCase(strSearchPharse) Then gsChache = True ElseIf Not IsMatch And Not IsCaseSensitive Then 'if its not matchable, and not case sensitive If InStr(0, LCase(strExploded), LCase(strSearchPharse)) >= 1 Then gsChache = True Else 'if its not matchable, and Case Sensitive If InStr(0, strExploded, strSearchPharse) >= 1 Then gsChache = True End If DoEvents Next strExploded IsContained = gsChache 'finish End Function
如何使用?
theArray用于数组变量,strSearchPharse是你想要搜索的文本(比如关键字,例如apple或youtube),然后isMatch是你想要搜索的文本需要完全相同的(不区分大小写,如果你启用它将会是buat) it。),IsCaseSensitive是你需要搜索的文本是否需要区分大小写。
默认设置为“不可匹配”和“区分大小写”。
样品:
XYZ = Array("Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh") If IsContained(XYZ, "o", , False) Then MsgBox "The Array contains o alphabet." Else MsgBox "The Array have no o alphabet." End If
结果将显示“数组包含o字母”。 MsgBox ...... :)