Ultimate combo box challenge please help.-VBForums
Results 1 to 19 of 19

Thread: Ultimate combo box challenge please help.

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Question Ultimate combo box challenge please help.

    Hello everyone, Im currently making a personal tool. Im learning c# and I've hit a snag using multiple comboboxes and one set button.

    ComboBox1 = Soldier
    ComboBox2 = Loadout
    ComboBox3 = Weapon
    Set Button


    ComboBox1
    Soldier -
    Soldier1 = 0x10000000 offset
    Soldier2 = 0x20000000 offset
    Soldier3 = 0x30000000 offset


    ComboBox2
    Loadout-
    Loadout1 = 0x11100000 offset
    Loadout2 = 0x22200000 offset
    Loadout3 = 0x33300000 offset


    ComboBox3
    Weapon -
    Gun = 0x01 Bytes
    smg = 0x02 Bytes
    LMG = 0x03 Bytes


    When I select the 3 combobox's and hit the set button it should end up writing to...
    P2P.Extension.WriteBytes(0x11100000, new byte[] { 0x03 });
    or something like that...

    Ive searched everywhere and I cant seem to grasp how to actually code this.
    If its easier to code threw team viewer that works to.
    I beg for help please.

    If im lacking any info please ask, thanks so much in advance.

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,350

    Re: Ultimate combo box challenge please help.

    Use ComboBox's Text property
    C# Code:
    1. P2P.Extension.WriteBytes(ComboBox2.Text, new byte[] { ComboBox3.Text });



  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by 4x2y View Post
    Use ComboBox's Text property
    C# Code:
    1. P2P.Extension.WriteBytes(ComboBox2.Text, new byte[] { ComboBox3.Text });

    Thank you for the reply.
    How would I code this, if I have 3 different offsets in two seperate comboboxes, and thrird combo calling for bytes. Then calling it all into one button?
    Like where does all the offsets get called from?

    Sorry for any confusion im really new at this but have a large intrest in learning C#.

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,350

    Re: Ultimate combo box challenge please help.

    Under the Click event of the button get comboboxes' Text property and do whatever you want, e.g.
    C Code:
    1. private void button1_Click(object sender, EventArgs e)
    2.         {
    3.             MessageBox.Show(this, comboBox1.Text + Environment.NewLine + comboBox2.Text + Environment.NewLine + comboBox3.Text);
    4.         }



  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by 4x2y View Post
    Under the Click event of the button get comboboxes' Text property and do whatever you want, e.g.
    C Code:
    1. private void button1_Click(object sender, EventArgs e)
    2.         {
    3.             MessageBox.Show(this, comboBox1.Text + Environment.NewLine + comboBox2.Text + Environment.NewLine + comboBox3.Text);
    4.         }
    Ah ok thats the coding for the buttom, but instead of it writing to a message box how would I send it to ps3?

    PS3.SetMemory(0x10000000, new byte[] { 0x01 }) (this, comboBox1.Text + Environment.NewLine + comboBox2.Text + Environment.NewLine + comboBox3.Text);

    or would it need to be different?
    I just dont know where to add the offsets as a reference to choose from.

    Thank you so much for your time.

    So Where do I add all the offsets in the coding?
    what would you suggest

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,350

    Re: Ultimate combo box challenge please help.

    I don't know PS3, so it is up to you to convert ComboBox.Text to something that you can pass to PS3.SetMemory method

    C Code:
    1. private void button1_Click(object sender, EventArgs e)
    2.         {
    3.             PS3.SetMemory(comboBox1.Text, new byte[] { comboBox2.Text });
    4.         }



  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by 4x2y View Post
    I don't know PS3, so it is up to you to convert ComboBox.Text to something that you can pass to PS3.SetMemory method

    C Code:
    1. private void button1_Click(object sender, EventArgs e)
    2.         {
    3.             PS3.SetMemory(comboBox1.Text, new byte[] { comboBox2.Text });
    4.         }
    This did not work i got an error on the last part {combobox2.text}

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: Ultimate combo box challenge please help.

    If comboBox2 actually contains Strings like "0x03" then you would have to call Byte.Parse to convert that String to a Byte to then put into a Byte array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by jmcilhinney View Post
    If comboBox2 actually contains Strings like "0x03" then you would have to call Byte.Parse to convert that String to a Byte to then put into a Byte array.
    Code:
    byte getweapon(string weapon)
            {
                byte Weapon = 0x00;
                switch (metroComboBox3.SelectedText)
                {
                    case "gun": Weapon = 0x01; break;
                    case "knife": Weapon = 0x02; break;
                    case "smg": Weapon = 0x03; break;
                }
                return Weapon;
            }
            private void metroButton142_Click(object sender, EventArgs e)
            {//set button weapons
                if (this.metroComboBox2.SelectedIndex == 0)
                    PS3.SetMemory(0x0100EA00, new byte[] { });//S1L1
                if (this.metroComboBox2.SelectedIndex == 1)
                    PS3.SetMemory(0x0200EB00, new byte[] { });//S1L2
                if (this.metroComboBox2.SelectedIndex == 2)
                    PS3.SetMemory(0x0300EBD0, new byte[] { });//S1L3
                {
                    byte Weapon = getweapon(metroComboBox3.SelectedText);
                    PS3.Extension.WriteBytes(metroComboBox2.SelectedIndex, metroComboBox3.SelectedText);
                }
    
            }
    Ok, so i got most of it except the very last code.
    ive got errors because it wants to set a offset and a byte. But im trying to say use the comboboxes.
    combobox2 contains the offsets needed to write.
    combobox3 contains the bytes.

    How do I fix this?
    Thank you.

  10. #10

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Code:
    byte getweapon(string weapon)
            {
                byte Weapon = 0x00;
                switch (metroComboBox3.SelectedText)
                {
                    case "gun": Weapon = 0x01; break;
                    case "knife": Weapon = 0x02; break;
                    case "smg": Weapon = 0x03; break;
                }
                return Weapon;
            }
            private void metroButton142_Click(object sender, EventArgs e)
            {//set button weapons
                if (this.metroComboBox2.SelectedIndex == 0)
                    PS3.SetMemory(0x0100EA00, new byte[] { });//S1L1
                if (this.metroComboBox2.SelectedIndex == 1)
                    PS3.SetMemory(0x0200EB00, new byte[] { });//S1L2
                if (this.metroComboBox2.SelectedIndex == 2)
                    PS3.SetMemory(0x0300EBD0, new byte[] { });//S1L3
                {
                    byte Weapon = getweapon(metroComboBox3.SelectedText);
                    //PS3.Extension.WriteBytes(metroComboBox2.SelectedIndex, metroComboBox3.SelectedText);
                }
    
            }
    Ok, so i got most of it except the very last code.
    ive got errors because it wants to set a offset and a byte. But im trying to say use the comboboxes.
    combobox2 contains the offsets needed to write.
    combobox3 contains the bytes.

    How do I fix this?
    Thank you.

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Sorry for the double post.
    Forgot to mention I was able to narrow it down too 2 comboboxes, as mentioned above.

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: Ultimate combo box challenge please help.

    How EXACTLY did you populate these ComboBoxes in the first place? We need to know EXACTLY what they contain. Numbers a string representations of numbers are NOT the same thing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    I'm sorry for the missing information. I'm new and still learning C#, this is my first project.

    metroCombobox2 contains...
    Soldier # 1 - Load Out # 1
    Load Out # 2
    Load Out # 3

    metroCombobox3 contains...
    gun
    knife
    smg

    The only other thing is what you see in my code. Should there be something else I should add as a string?
    If so could you please explain?
    Also if any other questions please ask, and ill do my best to answer.
    Thanks for your time.

  14. #14

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Code:
    byte getweapon(string weapon)
            {
                byte Weapon = 0x00;
                switch (metroComboBox3.SelectedText)
                {
                    case "gun": Weapon = 0x01; break;
                    case "knife": Weapon = 0x02; break;
                    case "smg": Weapon = 0x03; break;
                }
                return Weapon;
            }
            private void metroButton142_Click(object sender, EventArgs e)
            {//set button weapons
                byte weapon = getweapon(metroComboBox3.SelectedText);
                if (metroComboBox2.SelectedIndex == -1) { MessageBox.Show("Error: Please select a soldier first before proceeding, thank you.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                else if (metroComboBox2.SelectedIndex == 0) PS3.Extension.WriteByte(0x01000000, Weapon);//S1L1
                else if (metroComboBox2.SelectedIndex == 1) PS3.Extension.WriteByte(0x02000000, Weapon);//S1L2
                else if (metroComboBox2.SelectedIndex == 2) PS3.Extension.WriteByte(0x03000000, Weapon);//S1L3           
            }
    Ok guys this code is working, Except....
    where it says
    Code:
    byte Weapon = 0x00;
    its writing only this code and not selecting any other SelectedText

    Basically when I call for any guns in the combobox is not seeing this and only focusing on the 0x00 byte.

    And if I switch
    this...
    Code:
    byte Weapon = 0x00;
    no gun

    to this...
    Code:
    byte Weapon = 0x02;
    knife

    how can I fix this? is this a string issue??

  15. #15
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: Ultimate combo box challenge please help.

    SelectedText is not the correct property to be using there. I suggest that you read the documentation for the ComboBox class to see what each property represents. SelectedText means the same in a ComboBox as it does in a TextBox, so it's obviously not what you want.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by jmcilhinney View Post
    SelectedText is not the correct property to be using there. I suggest that you read the documentation for the ComboBox class to see what each property represents. SelectedText means the same in a ComboBox as it does in a TextBox, so it's obviously not what you want.
    Can you personally see an issue with the problem im having?
    Is there a possible fix that you could help me out with?

  17. #17

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    SelectedText is going to select the text from a combobox and/or textbox.

    But Ive also added a referance to each text to a byte ex. case "gun": weapon = 0x01
    So in the combobox you select the (text) "gun" it should select the weapon "gun" and add it as a byte.

    or am I wrong?
    Are you stating maybe use selectedindex, or selecteditem?

    Im here for help, because I have not found anything to help me on google except combo to text to messagebox.....

  18. #18
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: Ultimate combo box challenge please help.

    As I said, SelectedText works EXACTLY the same way in a ComboBox as in a TextBox. Do you populate the SelectedText in a TextBox by selecting an item from a drop-down list? If not then you can't possibly do it that way in a ComboBox either. Just as for a TextBox, if what you want is a String contain the complete text displayed in the control then you use the Text property.

    That said, why not use a the features that a ComboBox provides. Create a type that represents a weapon that has a name and a numerical value. Create multiple instances of that type and bind that list to the ComboBox. Set the DisplayMember and ValueMember such that the name gets displayed and the numerical value gets exposed via the SelectedValue. You then simply get that property value. There are plenty of examples of binding a ComboBox around.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Posts
    12

    Re: Ultimate combo box challenge please help.

    Quote Originally Posted by jmcilhinney View Post
    As I said, SelectedText works EXACTLY the same way in a ComboBox as in a TextBox. Do you populate the SelectedText in a TextBox by selecting an item from a drop-down list? If not then you can't possibly do it that way in a ComboBox either. Just as for a TextBox, if what you want is a String contain the complete text displayed in the control then you use the Text property.

    That said, why not use a the features that a ComboBox provides. Create a type that represents a weapon that has a name and a numerical value. Create multiple instances of that type and bind that list to the ComboBox. Set the DisplayMember and ValueMember such that the name gets displayed and the numerical value gets exposed via the SelectedValue. You then simply get that property value. There are plenty of examples of binding a ComboBox around.
    I am still stuck on this.

    Code:
    byte getWeapon(string weapon)
            {
                byte Weapon = 0x00;
                switch (Weapon)
                {
                    case 0: Weapon = 0x58; break;
                    case 1: Weapon = 0x57; break;
                    case 2: Weapon = 0x26; break;
                }
                return Weapon;
             private void metroButton142_Click(object sender, EventArgs e)
            {//set button weapons
                byte weapon = getweapon(metroComboBox3.SelectedText);
                if (metroComboBox2.SelectedIndex == -1) { MessageBox.Show("Error: Please select a soldier first before proceeding, thank you.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                else if (metroComboBox2.SelectedIndex == 0) PS3.Extension.WriteByte(0x01000000, Weapon);//S1L1
                else if (metroComboBox2.SelectedIndex == 1) PS3.Extension.WriteByte(0x02000000, Weapon);//S1L2
                else if (metroComboBox2.SelectedIndex == 2) PS3.Extension.WriteByte(0x03000000, Weapon);//S1L3           
            }
            }
    I know that im calling for a text, but im not sure how to call for a selectedindex.
    Everything I do im getting errors. Can someone please fix this coding for me. Im still learning, and combobox is difficult as theres not much for this type of coding ive found.
    thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.