2 Replies - 8018 Views - Last Post: 18 February 2009 - 04:38 AM Rate Topic: -----

#1 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

For Each Statement with listboxes

Posted 17 February 2009 - 04:46 PM

hi all,

i know i always post problems with listboxes but...

i am generating a listbox from a txt file this list box has ip's in and what im trying to do is run a for each statement


for each item in listbox.items
me.query()
next




this is what the query() is


Try
			Dim UdpClient As New UdpClient()


			UdpClient.Connect("my ip in here", 2005)

			' Sends a message to the host to which you have connected.
			Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(8124)

			UdpClient.Send(sendBytes, sendBytes.Length)

			
			Dim udpClientB As New UdpClient()
			udpClientB.Send(sendBytes, sendBytes.Length, "my ip in here", 2005)



		
			Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)


		
			Dim receiveBytes As [Byte]() = UdpClient.Receive(RemoteIpEndPoint)
			Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
			Dim sname As String
			Dim Track As String
			Dim real As String
			Dim raceLen As String

			Dim musers As String

			musers = returnData.Substring(16, 4)
			musers = byte4toint(musers)

			Dim users As String



			users = returnData.Substring(208, 4)
			users = byte4toint(users)


			sname = returnData.ToCharArray(20, 14)
			Track = returnData.ToCharArray(72, 14)
			real = returnData.ToCharArray(86, 10)
			raceLen = returnData.ToCharArray(111, 8)
			ListBox1.Items.Add(sname + "   |   " + Track + "   |   " + real + "   |   " + raceLen + "   |   " + musers + " - " + users)

		Catch
			MsgBox("error")
		End Try




so i would like to query every ip thats in the list box to show the racing community what race servers are open

im populating the list box by...

Try
			Dim file_name As String = ipdata()
			Dim stream_reader As New IO.StreamReader(file_name)
			Dim line As String = stream_reader.ReadLine()

			' Read the file one line at a time.
			' Alternatively you could grab it
			' all, use Split, and the loop through
			' the lines in an array.
			' line = stream_reader.ReadLine()

			Do While Not (line Is Nothing)
				' Trim and make sure the line isn't blank.
				line = line.Trim()



				If line.Length > 0 Then ips.Items.Add(line)
				
				' Get the next line.
				line = stream_reader.ReadLine()
			Loop
			ips.SelectedIndex = 0
			stream_reader.Close()
		Catch exc As Exception
			' Report all errors.
			MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read Error")
		End Try




this is the same code i used for my last app to populate a list box

Thanks for your time reading this

TADS

This post has been edited by TADS: 17 February 2009 - 04:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: For Each Statement with listboxes

#2 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: For Each Statement with listboxes

Posted 17 February 2009 - 05:10 PM

The only weird thing i see is that in your for each loop, you are not passing query any parameters to indicate which IP from the listbox you are currently on (though that looks kinda like pseudocode you wrote on the fly because it isn't capitalized or indented). Please tell us the problem your getting, and where it is happening in the code (if you know).
Was This Post Helpful? 0
  • +
  • -

#3 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: For Each Statement with listboxes

Posted 18 February 2009 - 04:38 AM

THANKS FOR THE REPLY

sorry... what i mean is i dont know how to make a for each loop with a listbox... the for each item in listbox2.items is not in my code yet as im not sure how to do it... and i thought that the for each loop would go after

  If line.Length > 0 Then ips.Items.Add(line)



now to start the ipdata() for line thats just been read before moving on to the next line to read?

why my code isnt capitalized is i was testing the idea to find if it worked i know i should realy do as i mean to go on and do all code as its ment to be the final code maybe something to look at for me!

TADS

This post has been edited by TADS: 18 February 2009 - 04:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1