Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 15th, 2007, 06:17 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please Help Me to fix this ERRORNYA:"object refere

Help Me Please
Why this Message Box appear with this message "object reference not set to instance of an object"
When I type this code

-------------------------------------------------------------------
Imports System.Data
Imports System.Data.OleDb
Imports System.Text.RegularExpressions
Public Class frmtoken
    Public Enum Data As Integer
        id_Mail = 0
        sbjMail = 1
    End Enum

    Private Sub btnTkn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTkn.Click
        Dim conDtbsSkrip As OleDbConnection = New OleDbConnection( _
                         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                         "Data Source=E:\dtbsSkrip.mdb")
        Dim cmdDtbsSkrip As New OleDbCommand()
        Dim objDataAdapter As New OleDbDataAdapter
        Dim objDataTable As New DataTable
        Dim r As New Regex("[^a-zA-Z]")

            Try
                conDtbsSkrip.Open()
                cmdDtbsSkrip.Connection = conDtbsSkrip

                'COUNT RECORD sbjMail
                cmdDtbsSkrip.CommandType = CommandType.Text
                cmdDtbsSkrip.CommandText = _
                 "SELECT COUNT (*) FROM tblMail WHERE sbjMail"
                Dim returnValue As Object
                returnValue = cmdDtbsSkrip.ExecuteScalar()

                'GET RECORD id_Mail AND sbjMail
                cmdDtbsSkrip.CommandType = CommandType.Text
                cmdDtbsSkrip.CommandText = _
                 "SELECT * FROM tblMail"
                Dim reader As OleDbDataReader = cmdDtbsSkrip.ExecuteReader()

                'RECORD TO ARRAY 1
                Dim Arr1(returnValue, 1) As String
                Dim x1 As Integer = 0
                Dim Tmp1_sbjMail As String = ""
                Dim Tmp1_idMail As String = ""

                If (reader.HasRows) Then
                    While reader.Read()
                        Tmp1_sbjMail = reader("sbjMail")
                        Tmp1_idMail = reader("id_Mail")
                        If r.Match(Tmp1_sbjMail).Success Then
                            Tmp1_sbjMail = r.Replace(Tmp1_sbjMail, " ")
                        End If
                        Arr1(x1, Data.id_Mail) = Tmp1_idMail
                        Arr1(x1, Data.sbjMail) = Tmp1_sbjMail.Trim.ToLower
                        'lst1.Items.Add("H1:" & Arr1(x1, 0) & "H3:" & Arr1(x1, 1))
                        x1 = x1 + 1
                    End While
                End If
                reader.Dispose()
                reader = Nothing

        'RECORD TO ARRAY 3
                Dim Arr3() As String
                Dim x3 As Integer = 0
                Dim x33 As Integer = 0
                Dim Tmp3_idMail As String = ""
                Dim Tmp3_sbjMail As String = ""
                Dim Tmp3_kata As String = ""

                For x3 = 0 To x1
                    Tmp3_idMail = Arr1(x3, 0)
                    Tmp3_sbjMail = Arr1(x3, 1)
                    Arr3 = Tmp3_sbjMail.Split(" ") 'ERROR START FROM HERE
                    MsgBox(Arr3(x3))
                    For x33 = 0 To UBound(Arr3)
                        Tmp3_kata = Arr3(x33).Trim
                        If (Tmp3_kata <> "") Then
                            cmdDtbsSkrip.CommandType = CommandType.Text
                            cmdDtbsSkrip.CommandText = _
                             "INSERT INTO tblKata(id_Mail,Kata) values (@id_Mail,@Kata)"
                            cmdDtbsSkrip.Parameters.AddWithValue("@id_Mail", Tmp3_idMail)
                            cmdDtbsSkrip.Parameters.AddWithValue("@Kata", Tmp3_kata)
                            cmdDtbsSkrip.Parameters.AddWithValue("@Status", 1)
                            cmdDtbsSkrip.ExecuteNonQuery()
                            cmdDtbsSkrip.Parameters.Clear()
                        End If
                    Next x33
                Next x3

                'VIEW DATA TO FORM
                cmdDtbsSkrip.CommandType = CommandType.Text
                cmdDtbsSkrip.CommandText = _
                 "SELECT * FROM tblKata"
                objDataAdapter.SelectCommand = cmdDtbsSkrip
                objDataAdapter.Fill(objDataTable)
                grdToken.DataSource = objDataTable
                grdToken.AlternatingRowsDefaultCellStyle.BackColor = Color.WhiteSmoke
                grdToken.CellBorderStyle = DataGridViewCellBorderStyle.None
                grdToken.SelectionMode = DataGridViewSelectionMode.FullRowSelect

                MessageBox.Show("END ....")
            Catch OleDbExceptionErr As OleDbException
                MessageBox.Show(OleDbExceptionErr.Message, "Access SQL1")
            Catch InvalidOperationExceptionErr As InvalidOperationException
                MessageBox.Show(InvalidOperationExceptionErr.Messa ge, "Access SQL3")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                cmdDtbsSkrip.Dispose()
                cmdDtbsSkrip = Nothing
                conDtbsSkrip.Close()
                conDtbsSkrip = Nothing

            End Try

    End Sub
End Class
----------------------------------------------------------------------
Help me Please

Thanks

  #2 (permalink)  
Old May 15th, 2007, 12:04 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Which actual line is raising the error?
  #3 (permalink)  
Old May 17th, 2007, 01:48 AM
Registered User
 
Join Date: May 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The error start at here : Arr3 = Tmp3_sbjMail.Split(" ") 'ERROR START FROM HERE

  #4 (permalink)  
Old May 17th, 2007, 11:40 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Well, I created a project with just this:
Code:
     Dim Arr3() As String
     Dim Tmp3_sbjMail As String = "One Two Three Four"

     Arr3 = Tmp3_sbjMail.Split(" ")
     MsgBox(Arr3(3))
     and had no errors... I wonder if Split fails on an empty string. I tried, and didn't get an error till the MsgBox line ("Index was outside the bounds of the array").

I tried re-assigning Arr3óno problem...

hmmm....
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fix Error sgafar ASP.NET 1.0 and 1.1 Basics 0 May 30th, 2007 10:22 AM
Pleeeeeeeeeeeeeez fix it!!! Prashant Sahni C++ Programming 4 August 22nd, 2006 01:55 AM
New Chapter 3 Fix .MAttButler BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 August 14th, 2006 09:08 PM
Object reference not ....how to fix khaink ASP.NET 1.0 and 1.1 Basics 7 December 28th, 2005 04:30 AM
Help! How do I fix this? missusfinz Crystal Reports 1 April 1st, 2005 11:27 AM



All times are GMT -4. The time now is 01:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.