News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

wxlistbox Arrays with CASE and SWITCH not working

Started by papayrus, January 25, 2011, 05:16:49 PM

Previous topic - Next topic

papayrus

Hello I need help I been trying to make a list box like one I made in C# where you select and item in the listbox and then press a button and it does something like launch internet explorer. In my program I just have a button and a wxlistbox on the frame. I want to make a number of items and when each item is selected each one will do something different when the button is clicked. Here is my code so far it does not work. Thanks for any help.

void ListBoxFrame::OnButton3Click(wxCommandEvent& event)
{

          for (int i = 0; i < ListBox1.IsSelected.Count; i++)
           {
               switch (ListBox1.IsSelected[i].ToString())
               {
                   case "Foobar":
                       wxMessageBox(_T("Listbox item foobar selected"));
                       break;
                   case "Bazquirk":
                       wxMessageBox(_T("Listbox item Bazquirk selected"));
                       break;
                   case "Widgets":
                       wxMessageBox(_T("Listbox item Widgets selected"));
                       break;
                   case "Gadgets":
                       wxMessageBox(_T("Listbox item Gadgets selected"));

                       break;
               }
           }
}

oBFusCATed

I would have written this:
Quote
Ask in the wxWidgets' forum.
Here we discuss topics related to the IDE C::B.
Not how to program with toolkit/library X.

But then I've realized that you need to find a good C++ book.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

papayrus

No time for a good c++ book right now. Just want to make that code work. Can you send me a link to the wxwidgets forum I can't seem to find it in here.
I forgot to add I am using wxpack.

oBFusCATed

Hm, www.google.com ?

Also read the error messages that the compiler has emitted to help you fix you problem without the need to bother anyone else.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

papayrus

Obviously I know all that I am a c# programmer. My code there is not too far off I can tell you that. You a typical useless retard. Use google oh oh I am so wise to tell people that oh oh I am the nerd king and tell everyone to use google thats the answer to all my problems. Buddy if you don't know how to do it don't comment at all. Nobody in the world needs to be told to use google anymore that's the answer of of lazy psychotic sadistic moron.

oBFusCATed

You're miles away from the correct code :twisted:

But you're a real man and you don't read manuals or books, and then when it doesn't work the way you think it should, you blame others for not writing the code for you.

Sorry, I'm not going to help you and I hope no one would.

p.s. if you want to program in c++ you'll have to read a book on the topic. :twisted:
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

papayrus

Obviously it takes a real man like you to not help. The code is not miles away from proper. If you think this code is right for the purpose then you are miles off.

        int sel = event.GetInt();
        wxLogMessage(_T("Listbox item %d selected"), sel);


That code wont give you options for each selection. The code I wrote is very close because I have been researching and thats what they use or something like it. Oh I did read and read and read I went through and reverse engineered all the examples that wxdev provided and they all come down to that little code up there that does not do what I need to do. I searched google for 2 days and nothing worked and the info for wxlistbox to do what I want to do just is not there or not clear.

papayrus

Obviously the last thing anyone would most likely do is fill out a form to log in to a forum so they can ask for help.

stahta01

See http://forum.wxwidgets.org/ for wxWidgets user help
Read our rules http://forums.next.codeblocks.org/index.php/topic,8962.0.html
Quote
3. Is your problem library, framework specific? There are appropriate forums for it, not the Code::Blocks forum.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Ceniza

The question is completely unrelated to Code::Blocks, and even wxWidgets. Do not be surprised if this thread gets locked or removed.

The C# feature that you are trying to use does not work in C++.

Someone already suggested Google to look for an answer. I will help you with what to search for: "switch on strings in c++". For your next C++ and/or wxWidgets related question, please use a proper forum.

Once again, your question has nothing to do with Code::Blocks, therefore violating the forum rules.

oBFusCATed

Quote from: papayrus on January 25, 2011, 06:28:12 PM
The code I wrote is very close ...
Or you hope, so  :twisted:

Copy and paste doesn't work with C++, neither the Code Completion is writing the code as you've used to :twisted:

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

papayrus

Well since I am using code blocks with wxpack it has everything to do with code blocks and wxwidgets. Yeah and that was written by me in c# not copied and pasted. I saw a c++ method like it

This is C++ and this is the code I saw that looked close to the c# method. They are both C
case MENU_FILE_TRANS:
{
char *ptrBuffer = &buffer[0];

for (int i = 0; i < RecvBytes; i+=2)
{
int firstvalue = RecvData[i] - '0';
int secondvalue;
//if RecvData[i+1] is a letter convert it to integer, otherwise use it.
switch(RecvData[i+1])
{
case 'A':
{
secondvalue = 10;
                 
}break;
case 'B':
{
secondvalue = 11;
                 
}break;
case 'C':
{
secondvalue = 12;
                 
}break;
case 'D':
{
secondvalue = 13;
                 
}break;
case 'E':
{
secondvalue = 14;
                 
}break;
case 'F':
{
secondvalue = 15;
                 
}break;
default:
secondvalue = RecvData[i+1] - '0';
break;
}
         
         
//convert the two values into decimal form
newval =  16 * firstvalue + secondvalue;
         
//change newval into a character
*ptrBuffer = char(newval);

//SendMessage(hlistbox,LB_ADDSTRING,0,(LPARAM)ptrBuffer);
ptrBuffer++;

//vShowText(hlistbox, ptrBuffer);
}

ptrBuffer = &buffer[0];


vShowText(hlistbox, ptrBuffer);


}break;


killerbot

#12
your latest code is comparing a char ('A') where your first code is comparing C-style strings in the switch statement. That's the difference.
Don't switch on C-strings (aka old C-style char arrays).
C-style arrays can not be simply compared (operator ==). The name of a C-style char array is noting more then a pointer, an address.
So you are surprised address 1000 is not the same as address 2000.

Learn std::string ... that might already help ...