Thread: Some text box loving help...Visual C++

  1. #1
    Registered User
    Join Date
    Mar 2009
    Location
    Boulder, Co
    Posts
    6

    Question Some text box loving help...Visual C++

    This piece is just a tool to check my firmware without having to hard code in values and rebuild constantly.

    I am a nub when it comes to C++ and I just a small program to test my project. What I am trying to do:

    1. User puts a value into TextBox1
    2. A button is pressed
    3. The program takes that value and loads it into a 64 byte buffer
    4. Send to USB endpoint.

    What I have so far: 1, 2, 4 Missing: step 3

    I just don't know how to read the value the user put in the text box. Then how do I write that value to the output buffer.

    Assumption, and not checking as this is a personal debug tool, that the value in the text box is in HEX, and when I read the text box, it stays as hex, and when I write it out it stays as hex.

    Example:
    In I put "050612DEADBEEF" in the text box, I want to read to the output buffer OB [] as:
    OB[1] = 05;
    OB[2] = 06;
    ...
    OB[6] = BE;
    OB[7] = EF;

    Make sense?

    I am using visual studio 2008 express if that matters.

    Any tips are much appreciated. If I can get this to work, I can develop my FW much much faster! (Which I am also a huge nub at...)

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You read the TexBox.Text member to get what is written in the TextBox

    That should be a System::String if I am not mistaken.

    You should then copy two bytes into a new System::String. Then convert the String to int (google for it). Or google for converting System::String to std::string and std::string to int. Once you have had the int, you can assign it to a byte.
    Note that you need to convert to Hex. There are functions that allow you do to so. Don't know exactly which. I know strtol() does the job.

    What exactly is the type of the buffer? In any case you should have a problem assigning an int to a byte.

    Note that there is no
    OB[7] = EF;
    you would do
    OB[7] = 0xEF;
    I am pointing this because it is the same as writting
    OB[7] = 239;

    So don't get overly confused with the hex.

    So
    1) get two bytes and assign them to a string
    2) use appropriate function
    3) if you can do System::String -> std::string you can use string.c_str() to make std::string a char* and use strtol() to make the two characters the appropriate value to assign to a byte. The byte can be a type of char[]

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    Boulder, Co
    Posts
    6
    Thanks! Tremendous help...and yeah I know hex is 0xBE...I would be more comfortable if it were all in hex to be honest. I hate the dog and pony show needed to do this....

    What I have now:

    //0506BEEF is in the text box to start

    System::String^ ReadCommand = System::String::Copy(Command_txtBx->Text);

    //ReadCommand = 0506BEEF

    Int32 tempInt = Convert::ToInt32(ReadCommand, 16);

    // tempInt = 0x506BEEF

    EDIT:
    array<Byte>^DecodeCommand = BitConverter::GetBytes(tempInt);
    DecodeCommand->Reverse(DecodeCommand);

    Does the trick!

    Thanks for pointing me down the right path!
    Last edited by zoobaby; 01-22-2010 at 05:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  3. MS Visual C++ 6 wont include vector.h in a header file
    By bardsley99 in forum C++ Programming
    Replies: 9
    Last Post: 11-06-2003, 12:05 PM
  4. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM