Grab numbers from a list box?

My method is only doing numbers 1 - 10 :/

Page 1 of 1

4 Replies - 1761 Views - Last Post: 16 May 2009 - 05:48 PM Rate Topic: -----

#1 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Grab numbers from a list box?

Posted 05 May 2009 - 04:15 AM

					// Run the level searcher
					do
					{
						if (Varz.EquippedItem.Contains(Convert.ToString(t)))
						{
							x = t;
							Varz.level = t;
						}
						t++;
					} while (x == 0);


As you can see as I select an item is loops until it resolves a number, but this does not work for double digit and beyond.

How is it possible to grab a double digit + number from a listbox?

Is This A Good Question/Topic? 0
  • +

Replies To: Grab numbers from a list box?

#2 papuccino1   User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Grab numbers from a list box?

Posted 05 May 2009 - 05:16 AM

I'm guessing this doesn't work beyond 10 because when it checks for 11 is see a double 1?

I'm not sure what your code is supposed to be doing. Can you be a bit more specific? What do you mean resolves a number?
Was This Post Helpful? 0
  • +
  • -

#3 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Grab numbers from a list box?

Posted 05 May 2009 - 12:53 PM

View Postpapuccino1, on 5 May, 2009 - 04:16 AM, said:

I'm guessing this doesn't work beyond 10 because when it checks for 11 is see a double 1?

I'm not sure what your code is supposed to be doing. Can you be a bit more specific? What do you mean resolves a number?


Well, It's for a game (lol a game on a forum yeah right) and this list box stores your inventory, what this does is actually loop until it hits a single digit number then says that item is level 'x', but it's only looping until it can get 1 digit, I need it to go above 1 digit for higher leave items, this is the last REAL XOMG HUGE bug in my game, i've been working on it for about a month now, I wanna release it soon i hope, just as a trial.
Was This Post Helpful? 0
  • +
  • -

#4 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Grab numbers from a list box?

Posted 05 May 2009 - 08:53 PM

I'm going to learn, to do regx and apply that to this.
Was This Post Helpful? 0
  • +
  • -

#5 frostyraver   User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Grab numbers from a list box?

Posted 16 May 2009 - 05:48 PM

Using Regex is harder than it looks, anyone have a different way to do this or is regex the only way?


Edit: Actually I could set something up that loops untill all numbers are resolved...hmmm...

Edit 2: Since I only need to grab the numbers after "Level " how would I go about implementing a loop? maybe since my loop is stopping then grab the number after that 'place' in the list box.

Say I have selected "Bad armor of the Tiger Level 23", My loop searchs for the first number then stops so this will make the item level 2, It needs to grab the second number so it makes the item level 23!, should I do a loop then some how fix up for it to grab what ever numbers are ahead after level?

EDIT 3: I found my solution!

		private void btnCheck_Click(object sender, EventArgs e)
		{
			// Set up selected items
			string lisAInventory = (string)lisInv.SelectedItem;

			// Reset the numbers
			int tempNumber = 0;
			int finalNumber = 0;
			int x = 0;
			int t = 0;

			StringBuilder sb = new StringBuilder();

			// Do the level searcher
			do
			{
				if (lisAInventory.Contains(Convert.ToString(t)))
				{
					tempNumber = 0;
					x = t;
					if (x != 0)
					{
						foreach (object o in lisAInventory)
						{
							string line = o.ToString();

							for (int i = 0; i < line.Length; i++)
							{
								char c = line[i];

								if (int.TryParse(c.ToString(), out tempNumber))
								{
									sb.Append(tempNumber);
								}
							}
						}
					}
				}
				t++;
			} while (x == 0);

			finalNumber = int.Parse(sb.ToString());

			// Output the name
			MessageBox.Show("That item is level "+finalNumber.ToString());
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			// Add the item to the inventorylistbox
			if (lisAdd.SelectedItem != null)
			{
				lisInv.Items.Add(lisAdd.SelectedItem);
			}
		}




And there you go :D.


Edit: This code will no longer add ALL the items in the list box together and only do what's selected :D.

This post has been edited by frostyraver: 16 May 2009 - 08:32 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1