|
-
May 5th, 2013, 07:57 PM
#1
Thread Starter
New Member
Help with Inputbox command**
Hey guys I am in need of some quick assistance, I have a vb project due tonight and I am clueless as to how to get this going.
The program needs to have a listbox with 12 numbers, and a button to start an inputbox dialog pop up, that searches for a number in the list.
For the life of me I cannot through google and my book find a good explanation of how to implement this inputbox into the code, and link it with my listbox.
The hints that my instructor gave were these:
Hint:
1
In this program, you should use nested loop. The outer loop is to check if user wants to continue to search. The inner loop is to search
the value in the listbox.
2.
You should use a Boolean type variable, and initialize it to False at the beginning ofevery search. If the value is found in
the listbox, set it to True
Any help would be much appreciated!
-
May 6th, 2013, 02:37 AM
#2
Re: Help with Inputbox command**
Do you know what a Boolean variable is? Do you know how to write loops? Do you know what different types of loops are available and what sort of situation each is best for?
-
May 6th, 2013, 11:06 AM
#3
Re: Help with Inputbox command**
So, what steps would you need? How about these:
1) Add an InputBox somewhere. The InputBox is a pretty stupid way to get this kind of input (or any other kind, for that matter), but this is a class, so you have to do what you are told.
2) Get the value from the InputBox and put it into a variable. You'll want to use this in the loop, so storing it in a variable would be good.
3) Loop through the items in the listbox comparing the value from step #2 to the item in the listbox.
My usual boring signature: Nothing
 
-
May 7th, 2013, 01:56 AM
#4
Member
Re: Help with Inputbox command**
I'm new myself, so take what I say as such.
I'm not clear what you're program is suppose to do. I'm assuming the list box already has the numbers, and the InputBox is used to get the number to search for. Is this correct?
If so, then basically, you're going to do a loop that compares each number in the list box till it finds one that matches one user inputs. Something on the lines of:
Code:
If Integer.TryParse(inputbox("Please enter number", intUserNumber) Then
Do Until intUserNumber = lstBox.Item(intCounter) Or intCounter = 11 'assumes intCounter is started at zero
intUserNumber <> intUserNumber
intCounter +=1
loop
Else
MessageBox.Show("no match")
End If
I didn't include any variable declarations. I used generic naming of the controls. You may need to convert data from the list into a Integer as well, which you can just use Cint command. I don't claim it's going to work 100% correctly, but you get the idea. The Or intCounter is just to make sure you don't get stuck in some kind of infinite loop since you've stated there are only 12 numbers. Basically, you want to pull the item from the list box and then compare it to the the UserNumber. If doesn't match, go to the next the number in the ListBox till you find a match or go through all the numbers.
Hope that helps some, and in time. Good Luck
-
May 7th, 2013, 09:30 AM
#5
Re: Help with Inputbox command**
I like the use of TryParse, but since this is an InputBox, I'd go a step further. After all, there is that annoying issue with the Cancel button. If the user presses Cancel, they probably want to bail out of the whole thing, but all they will get is the message about no match. Therefore, I'd get the return from the InputBox into a string variable, then check to see whether the string value is "", in which case I'd exit. If the string was not "", I'd then convert it using Integer.TryParse as shown.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|