If statement 条件1或条件2
我想这样做:If statement 条件1或条件2,if-statement,vb6,If Statement,Vb6,我想这样做: strCurrentName = rstAux.Fields("Name") strCurrentMat = rstAux.Fields("ID") Dim rstAux As Recordset Dim rstReal As Recordset Dim strCurrentName As String Dim strCurrentMat
strCurrentName = rstAux.Fields("Name")
strCurrentMat = rstAux.Fields("ID")
Dim rstAux As Recordset
Dim rstReal As Recordset
Dim strCurrentName As String
Dim strCurrentMat As String
Set rstAux = New ADODB.Recordset
Set rstReal = New ADODB.Recordset
If( (strCurrentName = rstReal.Fields("Name")) OR (strCurrentMat = rstReal.Fields("ID")) Then
'codeee
End If
在VB6上可以吗
我尝试了不同的方法,但总是出现如下错误:变量使用Visual Basic中不支持的自动化类型
好的,我明白消息的意思,但我想知道是否有办法做到这一点。好的,所有变量都是字符串,检查`rstReal.(“field”)的返回是否也是字符串,如果不是,进行转换。我相信名称是字符串,所以请检查“ID” 这应该起作用:
Dim rstAux As New ADODB.Recordset
Dim rstReal As New ADODB.Recordset
Dim strCurrentName As String
Dim strCurrentMat As String
If strCurrentName = rstReal.Fields("Name").Value Or _
strCurrentMat = rstReal.Fields("ID").Value Then
'codeee
End If
但是由于
.Value
是字段
对象的默认属性,因此它也应该与您的版本一起工作。当然有办法做到这一点。VB6支持布尔逻辑,就像世界上所有其他编程语言一样<代码>使用Visual Basic中不支持的自动化类型是问题的根源,要回答这个问题,您需要告诉这些变量是什么以及它们来自何处。显示您的实际代码并添加一些解释。这在VB6中当然是可能的。你的说法基本上是正确的,我会跳过最外层的父母,但除此之外看起来还可以。我认为这个错误指的是其他的东西,而不是或部分-你的情况如何?@Tomalak更新了我的question@GTG请看一下更新。您仍然没有解释什么是rstReal
以及.Fields()返回的数据类型。我只能怀疑这是某种类型的记录集(ADO?DAO?),但作为一条规则:如果你想要有用的答案,不要让人们猜测。我太笨了!非常感谢。实际上,rstReal.Fields(“ID”)是一个
Integer`我必须将它转换成字符串=我太笨了,你说得对。将字符串与整数进行比较会触发类型不匹配错误。
Dim rstAux As New ADODB.Recordset
Dim rstReal As New ADODB.Recordset
Dim strCurrentName As String
Dim strCurrentMat As String
If strCurrentName = rstReal.Fields("Name").Value Or _
strCurrentMat = rstReal.Fields("ID").Value Then
'codeee
End If