首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb2005 未设置对象变量或with块变量,该怎么解决

2012-01-23 
vb2005 未设置对象变量或with块变量用listbox显示当天销售票号,当选中某票号时叫LABEL显示票号对应的客户

vb2005 未设置对象变量或with块变量
用listbox显示当天销售票号,当选中某票号时叫LABEL显示票号对应的客户全称,可重复上述工作时却出“未设置对象变量或with块变量”错误,请高手指点,代码如下

VB.NET code
Public Class dksh    Dim astr As String    Dim a As New DataSet    Dim listdaset1 As New DataSet    Dim date1 As String    Dim mybm As BindingManagerBase    Dim dv As System.Data.DataView    Dim pd As String    Dim view As DataView = New DataView    Dim datareader As SqlClient.SqlDataReader    Public stra As String    Public strbjd As String    Dim listdaset3 As New DataSet    Public strbs As String    Public strcs As String    Public Shared thbm As String    Public Shared dkph As String    Dim datacp As New DataSet    Dim com1 As String    Dim com As String    Dim listda As SqlClient.SqlDataAdapter    Sub list1()        If LoginForm1.conn.State = ConnectionState.Closed Then            LoginForm1.conn.Open()        End If        Me.GroupBox2.Text = Button4.Text        If listdaset1.Tables("a") IsNot Nothing Then            listdaset1.Tables("a").Clear()            ' dv.Table.Clear()        End If        Dim list1com As String = "select 票号,此次应收 from " & ComboBox1.Text & ".dbo.ysa where 业务2=1 and substring(票号,5,8)='" & date1 & "'"        listda = New SqlClient.SqlDataAdapter(list1com, LoginForm1.conn)        If listdaset1.Tables("a") Is Nothing Then            listda.Fill(listdaset1, "a")        Else            listdaset1.Tables("a").Clear()            listda.Fill(listdaset1, "a")        End If        ListBox1.DisplayMember = "票号"        ListBox1.DataSource = listdaset1.Tables("a")        view = listdaset1.Tables("a").DefaultView        Label16.Text = listdaset1.Tables("a").Rows.Count        view.Sort = "票号"        'Label17.Text = listdaset1.Tables("a").Compute()        If IsDBNull(listdaset1.Tables("a").Compute("sum(此次应收)", view.RowFilter)) = True Then            Label17.Text = 0        Else            Label17.Text = listdaset1.Tables("a").Compute("sum(此次应收)", view.RowFilter)        End If        '  Me.ContextMenuStrip1.Items.Item("撤消").Visible = False        If LoginForm1.conn.State = ConnectionState.Open Then            LoginForm1.conn.Close()        End If    End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged        Try            If LoginForm1.conn.State = ConnectionState.Closed Then                LoginForm1.conn.Open()            End If            If ListBox1.Items.Count >= 1 Then                dkph = ListBox1.SelectedItem(0).ToString()            End If            ' End If            If dkph IsNot Nothing Then                Dim com1 As String = "select 此次应收 from " & ComboBox1.Text & ".dbo.ysa where  票号='" & dkph & "'"                Dim com As String = "select 客户全称 from " & ComboBox1.Text & ".dbo.ysa where  票号='" & dkph & "'"                Dim adcom As New System.Data.SqlClient.SqlCommand(com, LoginForm1.conn)                Dim adcom1 As New System.Data.SqlClient.SqlCommand(com1, LoginForm1.conn)                Label13.Text = adcom.ExecuteScalar                Label10.Text = adcom1.ExecuteScalar            End If            If LoginForm1.conn.State = ConnectionState.Open Then                LoginForm1.conn.Close()            End If        Catch ex As Exception            MessageBox.Show(ex.ToString)        End Try    End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click        Button5.Enabled = True        Button4.Enabled = False        Button2.Enabled = True        list1()    End Sub 



[解决办法]
看到VB的代码总是很晕~
[解决办法]
探讨
发多了呵呵,顶者有分哦

[解决办法]
楼主是哪一句代码报错?
[解决办法]
这么多代码,那一行错了,请标识一下
[解决办法]
dkph = ListBox1.SelectedItem(0).ToString()//这行没有语法错误啊
[解决办法]
VB.NET code
If ListBox1.SelectedItems.Count > 0 Then    dkph = ListBox1.SelectedItems(0).ToString()或dkph = ListBox1.SelectedItem.ToStringEnd If
[解决办法]
报什么错呀?
[解决办法]
頂了啊,給分吧,呵呵
[解决办法]
探讨
VB.NET codeIf ListBox1.SelectedItems.Count > 0 Then
dkph = ListBox1.SelectedItems(0).ToString()或dkph = ListBox1.SelectedItem.ToString
End If


应该是判断SelectedItems.Count ,而不是Items.Count

热点排行