Author Topic: wxlistbox Arrays with CASE and SWITCH not working  (Read 4799 times)

papayrus

  • Guest
wxlistbox Arrays with CASE and SWITCH not working
« on: January 25, 2011, 05:16:49 pm »
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.

Code: [Select]
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;
                }
            }
}
« Last Edit: January 25, 2011, 05:22:33 pm by papayrus »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #1 on: January 25, 2011, 05:37:09 pm »
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

  • Guest
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #2 on: January 25, 2011, 05:53:01 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #3 on: January 25, 2011, 05:54:06 pm »
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

  • Guest
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #4 on: January 25, 2011, 06:07:23 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #5 on: January 25, 2011, 06:21:03 pm »
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

  • Guest
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #6 on: January 25, 2011, 06:28:12 pm »
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.

       
Code: [Select]
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

  • Guest
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #7 on: January 25, 2011, 06:31:09 pm »
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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6636
    • My Best Post
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #8 on: January 25, 2011, 06:39:35 pm »
See http://forum.wxwidgets.org/ for wxWidgets user help
Read our rules http://forums.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++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1442
    • CenizaSOFT
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #9 on: January 25, 2011, 06:44:33 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12001
    • Travis build status
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #10 on: January 25, 2011, 06:56:59 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

  • Guest
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #11 on: January 25, 2011, 07:16:09 pm »
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
Code: [Select]
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;

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5179
Re: wxlistbox Arrays with CASE and SWITCH not working
« Reply #12 on: January 25, 2011, 08:54:41 pm »
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 ...
« Last Edit: January 25, 2011, 08:57:03 pm by killerbot »