View Single Post
  #1 (permalink)  
Old 12-01-2008, 6:14 AM
Spilled Spilled is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Nov 2008
Location: USA
Age: 22
Posts: 14
Reputation: 18
Spilled is on a distinguished programming path ahead
Default Problem Accessing Controls from class

Hello all i am having a problem accessing my controls from my class. I did quite a bit of research and I'm using delegates but i still seem to be having a problem.

When I run my program first thing i do is load a txt file into my listbox "lbWordlist" Here: (form1.vb)
Code:
    Private Sub btnLoadWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadWord.Click
        lbWordlist.Items.Clear()
        With OpenFileDialog1
            .Title = "Select Your WordList..."
            .Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                lbWordlist.Items.AddRange(Split(My.Computer.FileSystem.ReadAllText(.FileName), vbNewLine))
            End If
            Me.tbWordlist.Maximum = lbWordlist.Items.Count
        End With
    End Sub
At the bottom of that function I insert a breakpoint and tbWordlist.Max is set to 3407 (tbWordlist is my trackbar to keep track of my position in my wordlist).

Also in my form1.vb is the public get property i have here:
Code:
Delegate Function GetComboCallBack() As String
Code:
    Public ReadOnly Property GetCombo() As String
        Get
            Dim d As New GetComboCallBack(AddressOf GetTheCombo)
            Return d.Invoke()
        End Get
    End Property
Here i use a function delegate (otherwise crossthreading error) And here is the function.
Code:
    Public Function GetTheCombo() As String
        Dim tmp As String
        tmp = lbWordlist.Items.Item(tbWordlist.Value - 1)
        If tbWordlist.Value = tbWordlist.Maximum Then
            StopBots = True
        Else
            tbWordlist.Value += 1
        End If
        Return tmp
    End Function
Now I get an error at:
tmp = lbWordlist.Items.Item(tbWordlist.Value - 1)
in here saying
argumentoutofrangeexception
"InvalidArgument=Value of '0' is not valid for 'index'."
when there is a listcount of 3047 and also my tbWordlist.maximum is set back to 1 when it should be 3047 because i just loaded the wordlist into it and thats what the count was on my previous breakpoint in btnLoadWord.
Now is there anyone that can help me out here? Sorry i tried to make my problem as clear as possible. Thanks in advance
Reply With Quote