العودة   منتديات طرب عراق - طرب العراق > >

Loop Problems

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

إضافة رد
 
LinkBack أدوات الموضوع انواع عرض الموضوع
#1  
قديم 05-06-2012
الملك الراقي
الملك الراقي غير متواجد حالياً
لوني المفضل Cadetblue
 رقم العضوية : 14367
 تاريخ التسجيل : Feb 2011
 فترة الأقامة : 821 يوم
 أخر زيارة : 02-24-2011 (10:46 AM)
 المشاركات : 3,434 [ + ]
 التقييم : 10
 معدل التقييم : الملك الراقي is on a distinguished road
بيانات اضافيه [ + ]



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





 

إضافة رد

مواقع النشر (المفضلة)


جديد المواضيع المواضيع المحذوفه والمكرره
أدوات الموضوع
انواع عرض الموضوع

تعليمات المشاركة
لا تستطيع إضافة مواضيع جديدة
لا تستطيع الرد على المواضيع
لا تستطيع إرفاق ملفات
لا تستطيع تعديل مشاركاتك

BB code is متاحة
كود [IMG] متاحة
كود HTML معطلة
Trackbacks are متاحة
Pingbacks are متاحة
Refbacks are متاحة


أنظم لمعجبينا في الفيس بوك ...

Powered by vBulletin™ Version 3.8.7
Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.
HêĽм √ 3.1 BY: ! ωαнαм ! © 2010
جميع الحقوق محفوظة لشبكة طرب العراق