PDA

View Full Version : My next simple VB question


cameronlanni
12-07-2006, 08:02 AM
Here's what I'm trying to do:

On the part with class and race selection, there are two list boxes displaying races and classes accordingly. I am trying to get a description of the race/class selected to appear in a text adjacent to the list box. For now, I am simply trying to create a pop-up to display the class selected, for debugging purposes. However, I can't seem to reference the item selected in the list box properly. I am using the following code:

If lstRace.SelectedIndex = "Human" Then
MessageBox.Show("You chose human!")
End If

I've also tried referencing by Index Number, but couldn't get that to work either. Thanks for all of your continual support.

- Cameron

(I'm sure I've got a lot more questions to come)

nikkiH
12-07-2006, 03:33 PM
VB what? VB6? VB.NET?
Saying page (instead of form) makes me think you're talking asp? Is this a windows forms app, or a web application?

Anyway, try this instead. I'm guessing totally here since I don't know what you're actually doing :D

If lstRace.SelectedValue = "Human" Then
MessageBox.Show("You chose human!")
End If

If that variable starts with a number, I'd be surprised it works at all. I can't tell if that's a one or an L. If it's a one, change it.

cameronlanni
12-07-2006, 05:45 PM
Yeah, That didn't work.

I'm (still) using Microsoft Visual Studio 2005. There are no variables involved here, I'm simply trying to read directly from the list box. And yes, that's an "L" not a "1".

Thanks,
Cameron

cameronlanni
12-07-2006, 07:39 PM
While I'm awaiting the response to that question, here's another easy question:

How can I bind a Scroll Bar to a text area so that the vertical scroll bar will adjust the window accordingly, just like the scroll bar on the right side of your browser.

Thanks

nikkiH
12-07-2006, 08:06 PM
vb.net windows form app, then, I assume?
Studio can also do web forms applications. With VB. I'll assume windows form for this one.

A ListBox has several properties, depending on what you're doing there with it -- multiple selections allowed and whatnot.

Studio should give you a list of properties available for your Listbox as you write your code. What does it have there? Things like SelectedValue, SelectedItem, SelectedItems, and so on.
Debug and trace through and see what values are where and why it isn't doing what you expected.
You can try SelectedItem if SelectedValue didn't work, but I don't know how that will work if you allow multiple selections.

Also, there is no such thing as a textarea in a Windows Forms app.
What component are you using? TextBox with multiline supports a scrollbar of its own. Set Scrollbars to auto or vertical, whichever you prefer.

{who stole my crystal ball?}

cameronlanni
12-07-2006, 08:35 PM
Multi-Selection is disabled. The so-called "text area" is actually a 'Rich TextBox'. I've tried every command you suggested and can't get it it work. Let me know if you've got anymore suggestions on either question, I just thought of an idea - I'm gonna go try and will let you know.

cameronlanni
12-07-2006, 08:43 PM
Ok, I got the List box to work.

Initially, I was trying to put the code for it within a button, which would have been a lot easier, but I simply moved the code to the List Box code-area, and it works fine now.

Oh well, I'll make this work.

And for now I don't need the scroll bars, so scratch that.

Thank you again,
Cameron

nikkiH
12-07-2006, 11:05 PM
Ah, cool. :)
It always helps us to help you when you tell us the components you're using, because their properties and methods are different.
Also if you had posted the full code, I might have been able to tell you about events and handlers with the button click. Events fire in a given sequence, and how you set up your full code will affect what things are available and when.