cashiba 发表于 2019-8-15 22:43:38

Array(Empty, Empty, Empty, "VIEW")如何改写?[已解决]

本帖最后由 cashiba 于 2019-8-16 00:10 编辑

Public Sub Main()
On Error GoTo ErrorHandler

Dim Cnxn2 As ADODB.Connection
Dim rstSchema As ADODB.Recordset
Dim strCnxn As String

Set Cnxn2 = New ADODB.Connection
strCnxn = "Provider=sqloledb;" & _
"Data Source=MySqlServer;Initial Catalog=Pubs;Integrated Security=SSPI; "
Cnxn2.Open strCnxn

Set rstSchema = Cnxn2.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "VIEW"))

Do Until rstSchema.EOF
Debug.Print "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
rstSchema.MoveNext
Loop

rstSchema.Close
Cnxn2.Close
Set rstSchema = Nothing
Set Cnxn2 = Nothing
Exit Sub

ErrorHandler:
If Not rstSchema Is Nothing Then
If rstSchema.State = adStateOpen Then rstSchema.Close
End If
Set rstSchema = Nothing

If Not Cnxn2 Is Nothing Then
If Cnxn2.State = adStateOpen Then Cnxn2.Close
End If
Set Cnxn2 = Nothing

If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
.
Local $oCn = ObjCreate("adodb.connection")
Local $oRs = ObjCreate("adodb.recordset")
Local $sdb = @ScriptDir & "\Data.accdb"
Local $sPw = ""
Local $sCn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sdb & _
                ";persist Security Info=False;Jet OLEDB:Database Password=" & $sPw
$oCn.Open($sCn)

Local $t = ["", "", "", "VIEW"]
Local $oSm = $oCn.OpenSchema(20, $t)

Local $t = ["", "", "", "VIEW"]
Local $oSm = $oCn.OpenSchema(20, $t)Local $oSm = $oCn.OpenSchema(20, $t)
Local $oSm = $oCn^ ERRORArray(Empty, Empty, Empty, "VIEW")
$t = ["", "", "", "VIEW"]
$t =
以上错误不知道是不是empty改成""或Null造成的......

AU3里空值好像也就""或Null以及0三种形式
不知道为啥运行有错误,还是问题不在这里呢.....

chishingchan 发表于 2019-8-15 23:10:53

索性"斩脚趾避沙虫" :face (33):
$t="VIEW"

cashiba 发表于 2019-8-15 23:37:17

chishingchan 发表于 2019-8-15 23:10
索性"斩脚趾避沙虫"
$t="VIEW"

版主的办法确实可行,绕开了直接赋空值
不过经常会遇到空值空对象之类的问题,而且转换其它编程语言到AU3的时候也常遇到这种问题
像上述数组空元素,AU3里如何像VB、js一样有明确的变量或常量表示呢?


chishingchan 发表于 2019-8-16 21:12:29

要不学一下 Dictionary 对象
http://www.autoitx.com/thread-37424-1-1.html
页: [1]
查看完整版本: Array(Empty, Empty, Empty, "VIEW")如何改写?[已解决]