Board logo

标题: [基础] VB编译时报变量未定义 [打印本页]

作者: fsxw    时间: 2009-4-23 08:39     标题: VB编译时报变量未定义

我的代码:

Option Explicit
Dim ypstr, tjstr, lsstr As String
Dim hj As Integer

Dim ypconn As New ADODB.Connection
Dim cxset As ADODB.Recordset

Dim Reportrk As New CrystalReport2
Dim Reportck As New CrystalReport4



Private Sub Command1_Click()

If Option1.Value = True Then '入库明细datestr = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) + "." + Mid(Format(Date, "YYYY-MM-DD"), 6, 2) + "." + Mid(Format(Date, "YYYY-MM-DD"), 9, 2)
   tjstr = "select * from RKBF"
End If

If Option2.Value = True Then '出库明细
   tjstr = "select * from CKBF"
End If

sjklj (tjstr)

If Not cxset.EOF Then '药品库中有数据
   

   If Text1.Text = "" Then
     If Check1.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Format(Date, "YYYY-MM-DD"), 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Format(Date, "YYYY-MM-DD"), 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Format(Date, "YYYY-MM-DD"), 1, 7) Then
     
       Reportrk.Database.SetDataSource cxset
       Screen.MousePointer = vbHourglass
      CRViewer91.ReportSource = Reportrk
      CRViewer91.ViewReport
      Screen.MousePointer = vbDefault
     End If
   Else
     If Check2.Value = 1 And Mid(cxset!日期, 6, 2) = Mid(Text1.Text, 6, 2) Or Check2.Value = 1 And Mid(cxset!日期, 1, 4) = Mid(Text1.Text, 1, 4) Or Check1.Value = 1 And Check2.Value = 1 And Mid(cxset!日期, 1, 7) = Mid(Text1.Text, 1, 7) Then
      
       Reportck.Database.SetDataSource cxset
       Screen.MousePointer = vbHourglass
       CRViwer91.ReportSource = Reportck
       CRViewer91.ViewReport
       Screen.MousePointer = vbDefault
     End If
   
  End If


Else
    MsgBox " 数据库中没有数据,不能进行统计!", 0, "提示信息"
End If



End Sub
作者: Nothing    时间: 2009-4-27 16:23

去掉这一行 Option Explicit
作者: 牛德龙    时间: 2009-9-25 10:17     标题: 我看不是

我看不是
作者: Nothing    时间: 2009-9-25 23:55

代码前加Option Explicit 就是要求变量必需定义




欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/) Powered by Discuz! 6.0.0