| |||||||
![]() |
| | LinkBack | أدوات الموضوع | انواع عرض الموضوع |
|
#1
| ||||||||
| ||||||||
| Having a lot of Problems with a for Loop I have written. with the following code, the it only finds the item if it is top of the list. ie in the following example, it finds jim but not jack, james or peter. Any help would be very much appreciated and I'm sure its something simple note, on the form there are two listboxes (lstbox_items, lstbox_log), two buttons (btn_test, btn_loaditems) and one openfiledialog the code is as follows and there is also a **** file to load which is simply Code: --------- jim jack james peter --------- Code: --------- Imports System.Net Imports System.****.RegularExpressions Imports System.IO Imports System.**** Imports System.IO.Compression Imports System.Threading Imports System.******s.Forms Public Class Form1 Private testthread As Thread Dim streamer As IO.StreamReader Dim TestSource As String Dim CurrentTime As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles My****.Load Control.CheckForIllegalCrossThreadCalls = False End Sub Private Sub btn_loaditems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_loaditems.Click OpenFileDialog1.ShowDialog() Dim itemlist******** = OpenFileDialog1.File**** streamer = IO.File.Open****(itemlist********) Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine) lstbox_items.Items.AddRange(mystring) End Sub Private Sub btn_test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_test.Click testthread = New Threading.Thread(AddressOf test) testthread.IsBackground = True testthread.Start() End Sub Private Sub test() Dim items As String = "jim, jack, james, peter" Dim count = lstbox_items.Items.Count - 1 For i = 0 To count Dim currentitem = GetListboxItem(lstbox_items, i) If items.Contains(currentitem) Then lstbox_log.Items.Add("found " & currentitem) Else lstbox_log.Items.Add("not found " & currentitem) End If Next End Sub Private Function GetListboxItem(ByVal MyControl As System.******s.Forms.ListBox, ByVal index As Integer) As String Dim **** As String If MyControl.InvokeRequired Then Dim args As Object() = {MyControl, index} **** = (MyControl.Invoke(New GetListboxItemInvoker(AddressOf GetListboxItem), args)) Else **** = MyControl.Items.Item(index) End If Return **** End Function --------- Having a lot of Problems with a for Loop I have written. with the following code, the it only finds the item if it is top of the list. ie in the following example, it finds jim but not jack, james or peter. Any help would be very much appreciated and I'm sure its something simple note, on the form there are two listboxes (lstbox_items, lstbox_log), two buttons (btn_test, btn_loaditems) and one openfiledialog the code is as follows and there is also a **** file to load which is simply Code: jim jack james peter Code: Imports System.Net Imports System.****.RegularExpressions Imports System.IO Imports System.**** Imports System.IO.Compression Imports System.Threading Imports System.******s.Forms Public Class Form1 Private testthread As Thread Dim streamer As IO.StreamReader Dim TestSource As String Dim CurrentTime As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles My****.Load Control.CheckForIllegalCrossThreadCalls = False End Sub Private Sub btn_loaditems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_loaditems.Click OpenFileDialog1.ShowDialog() Dim itemlist******** = OpenFileDialog1.File**** streamer = IO.File.Open****(itemlist********) Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine) lstbox_items.Items.AddRange(mystring) End Sub Private Sub btn_test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_test.Click testthread = New Threading.Thread(AddressOf test) testthread.IsBackground = True testthread.Start() End Sub Private Sub test() Dim items As String = "jim, jack, james, peter" Dim count = lstbox_items.Items.Count - 1 For i = 0 To count Dim currentitem = GetListboxItem(lstbox_items, i) If items.Contains(currentitem) Then lstbox_log.Items.Add("found " & currentitem) Else lstbox_log.Items.Add("not found " & currentitem) End If Next End Sub Private Function GetListboxItem(ByVal MyControl As System.******s.Forms.ListBox, ByVal index As Integer) As String Dim **** As String If MyControl.InvokeRequired Then Dim args As Object() = {MyControl, index} **** = (MyControl.Invoke(New GetListboxItemInvoker(AddressOf GetListboxItem), args)) Else **** = MyControl.Items.Item(index) End If Return **** End Function المواضيع المتشابهه:
شاركنا برايك حول الموضوع في الفيس بوك بدون تسجيل في الموقع المصدر: منتديات طرب عراق - طرب العراق - من قسم: المواضيع المحذوفه والمكرره Loop Problems |
![]() |
| مواقع النشر (المفضلة) |
جديد المواضيع المواضيع المحذوفه والمكرره | |||||||||||||
| | |||||||||||||
| أدوات الموضوع | |
| انواع عرض الموضوع | |
| |