Results 1 to 10 of 10

Thread: Did i reach a string limit?

  1. #1

    Thread Starter
    Junior Member dutchstudent's Avatar
    Join Date
    Sep 2011
    Location
    Netherlands, the Hague
    Posts
    23

    Question Did i reach a string limit?

    Hi guys,

    I have a string wich contains a couple of values, these values are run through by a loop. The only problem is that my program gives the following error:

    Code:
    System.InvalidOperationException was unhandled
      Message=Er is een fout opgetreden bij het maken van het formulier. Zie ExceptionInnerException voor details. De fout is: De rekenkundige bewerking heeft geresulteerd in een overloop.
      Source=Hash Creator
      StackTrace:
           bij Hash_Creator.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 190
           bij Hash_Creator.My.MyProject.MyForms.get_Form1()
           bij Hash_Creator.My.MyApplication.OnCreateMainForm() in C:\Users\Gebruiker\documents\visual studio 2010\Projects\Hash Creator\Hash Creator\My Project\Application.Designer.vb:regel 35
           bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           bij Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           bij Hash_Creator.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:regel 81
           bij System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           bij System.Threading.ThreadHelper.ThreadStart()
      InnerException: System.OverflowException
           Message=De rekenkundige bewerking heeft geresulteerd in een overloop.
           Source=Hash Creator
           StackTrace:
                bij Hash_Creator.Form1..ctor() in C:\Users\Gebruiker\documents\visual studio 2010\Projects\Hash Creator\Hash Creator\Hash Creator.vb:regel 13
           InnerException:
    when I run my program.

    The specific string is as follows:
    Code:
    Dim chars As String() = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
    What is strange is that when I remove one value, the program runs perfectly. Anyone got an idea what may be causing this?

    Jordy
    Saying thanks only takes a few seconds.

    Please give kama if you found this post helpful
    (click the scales on the left <--)

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Did i reach a string limit?

    Seems odd that declaring the following would give you an exception or are you saying there is code you have not shown which is erroring out? If there is code which is not being shown than it is hard to indicate how to resolve the issue.

    Code:
    Dim chars As String() = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Did i reach a string limit?

    That works fine for me in 2008, even with more values.

    Note, your chars is actually strings, did you actually want that? You can get the same doing this:

    Code:
    Dim charString As String = "abcdefghijklmnopqrstuvwxyz1234567890"
    charString.Chars(3) = "d"c

  4. #4

    Thread Starter
    Junior Member dutchstudent's Avatar
    Join Date
    Sep 2011
    Location
    Netherlands, the Hague
    Posts
    23

    Re: Did i reach a string limit?

    Hi kevin,

    I do have some code that is not shown, but I was afraid to post it, because i'm a noob at VB and my code is rather nasty looking :P, well you asked for it, so here it is XD:

    Code:
    Imports MySql.Data.MySqlClient
    
    Public Class Form1
        Dim connectieString As String
        Dim connectie As MySqlConnection
        Dim sql As String
        Dim cmd As MySqlCommand
        Dim chars As String() = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
        Dim lengte As Integer = 6
        Dim buffer As String = ""
        Dim huidigeRecord As Integer = 0
        Dim aantalMogelijkheden As Integer = chars.Length ^ lengte
        Dim sqlUitkomst As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            actiefProgrammaCheckTimer.Start()
        End Sub
    
        Private Sub isProgrammaActief()
            If Process.GetProcessesByName("wampmanager").Length > 0 Then
                wampActief_lbl.ForeColor = Color.Green
                wampActief_lbl.Text = "Wampserver online"
                loginVeldenWrapper.Visible = True
            Else
                wampActief_lbl.ForeColor = Color.Red
                wampActief_lbl.Text = "Wampserver offline"
                loginVeldenWrapper.Visible = False
                infoGroupBox.Visible = False
                wachtwoord_txt.Text = ""
                sluitVerbinding()
                loginVeldenWrapper.Enabled = True
            End If
        End Sub
    
        Private Sub start_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start_btn.Click
            start_btn.Enabled = False
            infoGroupBox.Visible = True
            updateInfoTimer.Start()
            Dim teller As Integer = 0
            Dim teller2 As Integer = 0
            Dim teller3 As Integer = 0
            Dim teller4 As Integer = 0
            Dim teller5 As Integer = 0
            Dim teller6 As Integer = 0
    
            aantalMogelijkheden_lbl.Text = "Aantal mogelijkheden: " & Format(aantalMogelijkheden, "#,###")
    
            Do While teller < 35
                huidigeRecord += 1
    
                Application.DoEvents()
                buffer = chars(teller)
                teller += 1
                If teller = 35 Then
                    teller = 0
                    Do While teller < 35
                        huidigeRecord += 1
                        Application.DoEvents()
                        buffer = chars(teller)
                        buffer += chars(teller2)
                        teller2 += 1
                        If (teller2 = 35) Then
                            teller2 = 0
                            teller += 1
                        End If
                    Loop
                    If teller = 35 Then
                        teller = 0
                        teller2 = 0
                        Do While teller < 35
                            huidigeRecord += 1
                            Application.DoEvents()
                            buffer = chars(teller)
                            buffer += chars(teller2)
                            buffer += chars(teller3)
                            teller3 += 1
                            If (teller3 = 35) Then
                                teller3 = 0
                                teller2 += 1
                                If (teller2 = 35) Then
                                    teller3 = 0
                                    teller2 = 0
                                    teller += 1
                                End If
                            End If
                        Loop
                        If teller = 35 Then
                            teller = 0
                            teller2 = 0
                            teller3 = 0
                            Do While teller < 35
                                huidigeRecord += 1
                                Application.DoEvents()
                                buffer = chars(teller)
                                buffer += chars(teller2)
                                buffer += chars(teller3)
                                buffer += chars(teller4)
                                teller4 += 1
                                If teller4 = 35 Then
                                    teller4 = 0
                                    teller3 += 1
                                    If teller3 = 35 Then
                                        teller4 = 0
                                        teller3 = 0
                                        teller2 += 1
                                        If teller2 = 35 Then
                                            teller4 = 0
                                            teller3 = 0
                                            teller2 = 0
                                            teller += 1
                                        End If
                                    End If
                                End If
                            Loop
                            If teller = 35 Then
                                teller = 0
                                teller2 = 0
                                teller3 = 0
                                teller4 = 0
                                Do While teller < 35
                                    huidigeRecord += 1
                                    Application.DoEvents()
                                    buffer = chars(teller)
                                    buffer += chars(teller2)
                                    buffer += chars(teller3)
                                    buffer += chars(teller4)
                                    buffer += chars(teller5)
                                    teller5 += 1
                                    If teller5 = 35 Then
                                        teller5 = 0
                                        teller4 += 1
                                        If teller4 = 35 Then
                                            teller4 = 0
                                            teller3 += 1
                                            If teller3 = 35 Then
                                                teller4 = 0
                                                teller3 = 0
                                                teller2 += 1
                                                If teller2 = 35 Then
                                                    teller4 = 0
                                                    teller3 = 0
                                                    teller2 = 0
                                                    teller += 1
                                                End If
                                            End If
                                        End If
                                    End If
                                Loop
                                If teller = 35 Then
                                    teller = 0
                                    teller2 = 0
                                    teller3 = 0
                                    teller4 = 0
                                    teller5 = 0
                                    Do While teller < 35
                                        huidigeRecord += 1
                                        Application.DoEvents()
                                        buffer = chars(teller)
                                        buffer += chars(teller2)
                                        buffer += chars(teller3)
                                        buffer += chars(teller4)
                                        buffer += chars(teller5)
                                        buffer += chars(teller6)
                                        teller6 += 1
                                        If teller6 = 35 Then
                                            teller6 = 0
                                            teller5 += 1
                                            If teller5 = 35 Then
                                                teller6 = 0
                                                teller5 = 0
                                                teller4 += 1
                                                If teller4 = 35 Then
                                                    teller6 = 0
                                                    teller5 = 0
                                                    teller4 = 0
                                                    teller3 += 1
                                                    MessageBox.Show(buffer)
                                                    If teller3 = 35 Then
                                                        teller6 = 0
                                                        teller5 = 0
                                                        teller4 = 0
                                                        teller3 = 0
                                                        teller2 += 1
                                                        If teller2 = 35 Then
                                                            teller6 = 0
                                                            teller5 = 0
                                                            teller4 = 0
                                                            teller3 = 0
                                                            teller2 = 0
                                                            teller += 1
                                                            If teller = 35 Then
                                                                start_btn.Enabled = True
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        End If
                                    Loop
                                End If
                            End If
                        End If
                    End If
                End If
            Loop
        End Sub
    
        Private Sub actiefProgrammaCheckTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles actiefProgrammaCheckTimer.Tick
            isProgrammaActief()
        End Sub
    
        Private Sub verbind_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles verbind_btn.Click
            If database_txt.Text = "" Then
                database_txt.BackColor = Color.Red
            Else
                maakVerbinding()
            End If
        End Sub
    
        Private Sub maakVerbinding()
            connectieString = "Database=" & database_txt.Text & ";Data Source=" & host_txt.Text & ";" _
            & "User Id=" & gebruikersnaam_txt.Text & ";Password=" & wachtwoord_txt.Text & ""
            connectie = New MySqlConnection(connectieString)
            database_txt.BackColor = Color.White
            Try
                connectie.Open()
                connectieStatus_lbl.ForeColor = Color.Green
                connectieStatus_lbl.Text = "Database connectie actief"
                tabelInfoWrapper.Visible = True
                loginVeldenWrapper.Enabled = False
            Catch ex As MySqlException
                connectieStatus_lbl.ForeColor = Color.Red
                connectieStatus_lbl.Text = "Database connectie niet actief, controlleer je gegevens."
                start_btn.Enabled = False
            Finally
            End Try
        End Sub
    
        Private Sub checkTabel()
            ' Kijk of tabel bestaat
    
            sql = ("SELECT COUNT(*)" _
                   & "FROM(information_schema.tables)" _
                   & "WHERE table_schema = '" & database_txt.Text & "'" _
                   & "AND table_name = '" & table_txt.Text & "'")
            cmd = New MySqlCommand(sql, connectie)
            sqlUitkomst = Convert.ToString(cmd.ExecuteScalar())
            If sqlUitkomst < 1 Then
                tabelInfo_lbl.ForeColor = Color.Red
                tabelInfo_lbl.Text = "Deze tabel bestaat niet."
            Else
                tabelInfo_lbl.ForeColor = Color.Green
                tabelInfo_lbl.Text = "Tabel gevonden."
                If (plainTextKolom_txt.Text = "") Then
                    plainTextKolom_txt.BackColor = Color.Red
                ElseIf (MD5Kolom_txt.Text = "") Then
                    plainTextKolom_txt.BackColor = Color.White
                    MD5Kolom_txt.BackColor = Color.Red
                Else
                    MD5Kolom_txt.BackColor = Color.White
                    plainTextKolom_txt.BackColor = Color.White
                    checkKolom()
                End If
            End If
        End Sub
    
        Private Sub checkKolom()
            'Kijk of plain text kolom bestaat
            sql = ("SELECT COUNT(*)" _
                 & "FROM(information_schema.columns)" _
                 & "WHERE table_schema = '" & database_txt.Text & "'" _
                 & "AND table_name = '" & table_txt.Text & "'" _
                 & "AND column_name = '" & plainTextKolom_txt.Text & "'")
            cmd = New MySqlCommand(sql, connectie)
            sqlUitkomst = Convert.ToString(cmd.ExecuteScalar())
            If sqlUitkomst < 1 Then
                sql = ("ALTER TABLE " & table_txt.Text & " ADD " & plainTextKolom_txt.Text & " VARCHAR(65);")
                cmd = New MySqlCommand(sql, connectie)
            End If
            'Kijk of plain text kolom bestaat
            sql = ("SELECT COUNT(*)" _
                 & "FROM(information_schema.columns)" _
                 & "WHERE table_schema = '" & database_txt.Text & "'" _
                 & "AND table_name = '" & table_txt.Text & "'" _
                 & "AND column_name = '" & MD5Kolom_txt.Text & "'")
            cmd = New MySqlCommand(sql, connectie)
            sqlUitkomst = Convert.ToString(cmd.ExecuteScalar())
            If sqlUitkomst < 1 Then
                Try
                    sql = ("ALTER TABLE " & table_txt.Text & " ADD " & MD5Kolom_txt.Text & " VARCHAR(65);")
                    cmd = New MySqlCommand(sql, connectie)
                Catch ex As Exception
                    MessageBox.Show("Error: " & ex.ToString())
                End Try
    
            End If
            tabelInfoWrapper.Enabled = False
            start_btn.Enabled = True
        End Sub
    
        Private Sub sluitVerbinding()
            connectie.Close()
            connectieString = ""
            connectieStatus_lbl.ForeColor = Color.Red
            connectieStatus_lbl.Text = "Database connectie niet actief, controlleer je gegevens."
            start_btn.Enabled = False
        End Sub
    
        Private Sub updateInfoTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateInfoTimer.Tick
            huidigeRecord_lbl.Text = ("Bezig met record " & Format(huidigeRecord, "#,###") & " van " & Format(aantalMogelijkheden, "#,###"))
            huidigeText_lbl.Text = "Huidige text: " & buffer
            Application.DoEvents()
        End Sub
    
        Private Sub controlleerTabel_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles controlleerTabel_btn.Click
            checkTabel()
        End Sub
    End Class
    Thanks for your reply Grimfort, I'm still learning the language, but I think that what I have is what I want, maybe you can give me an example on how to implement the code you discribe into my code that you can see in this reply?

    Jordy
    Saying thanks only takes a few seconds.

    Please give kama if you found this post helpful
    (click the scales on the left <--)

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Did i reach a string limit?

    In the code posted, which line is causing the error?

    You should go into Project Properties, compile tab and set Option Strict On. This will ensure less run time issues i.e.

    Code:
    Dim aantalMogelijkheden As Integer = chars.Length ^ lengte
    Should be
    Code:
    Dim aantalMogelijkheden As Integer = CInt(chars.Length ^ lengte)

  6. #6
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Did i reach a string limit?

    I'm wondering if it's huidigeRecord that's overflowing and should be a Long, not an Integer.

    BTW, have you removed a load of lines before the start_btn handler since you got the error?

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Did i reach a string limit?

    6 ^ 35 = 1719070799748422591028658176
    6 ^ 34 = 286511799958070431838109696

    Integer.MaxValue = 2147483647
    Longer than an int... just a little .

  8. #8

    Thread Starter
    Junior Member dutchstudent's Avatar
    Join Date
    Sep 2011
    Location
    Netherlands, the Hague
    Posts
    23

    Re: Did i reach a string limit?

    Inferrd you are absolutely right, its indeed the integer that is to long, thanks to all of you guys

    Solution:
    change:
    Code:
    Dim aantalMogelijkheden As String = chars.Length ^ lengte
    into:
    Code:
    Dim aantalMogelijkheden As Long = chars.Length ^ lengte
    Jordy
    Saying thanks only takes a few seconds.

    Please give kama if you found this post helpful
    (click the scales on the left <--)

  9. #9

    Thread Starter
    Junior Member dutchstudent's Avatar
    Join Date
    Sep 2011
    Location
    Netherlands, the Hague
    Posts
    23

    Re: Did i reach a string limit?

    Is there any way to change the state of my thread to resolved or something? Or do I just have to change the title of my thread?

    Jordy
    Saying thanks only takes a few seconds.

    Please give kama if you found this post helpful
    (click the scales on the left <--)

  10. #10
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Did i reach a string limit?

    Thread Tools - > Top of the forum

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width