Converting a text box value into a character array?

This is a discussion on Converting a text box value into a character array? within the Windows Programming forums, part of the Platform Specific Boards category; I'm using a .NET Forms Application, and I have a text box that I want to copy the value of ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Red face Converting a text box value into a character array?

    I'm using a .NET Forms Application, and I have a text box that I want to copy the value of to an array of char's. I'll be the first to admit, I'm quite inexperienced with .NET, and honestly, C/C++ in general.

    Maybe I'm just lazy, but I can't figure it out.

    My character array is char sVModel[64], in struct SGlockInfo sglock_info.
    My text box is this->ModelNameViewPistol.

    I've done it one way:
    Code:
    this->ModelNameViewPistol->set_Text((System::String*)sglock_info.sVModel);
    I'm sure that's kinda sleazy, but...

    The trouble is, I can't seem to do it the other way around. Am I just missing something? I suppose I should wait until tomorrow to be working on a non-negative amount of sleep, but when I come across a problem, my mind refuses to let it rest.

    Please, someone point out whatever it is that my mind refuses to comprehend.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    To create a System::String from a char array you can probably do:
    Code:
    System::String^ str = gcnew System::String(chArray);
    The other way around (System::String to char array) is probably more difficult, especially since (as far as I know) System::String is only unicode

    This thread might be able to help you.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Is there a reason why you are mixing char arrays and strings?

    Why not just use strings?

    or try....

    char szBuffer[256]={0};
    this->ModelNameViewPistol->GetWindowText(szBuffer);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    The reason I'm mixing these things is because the program that I need the text for requires the char array.

    I guess I forgot to mention this, but this->ModelNameViewPistol is 'System::Windows::Forms::TextBox', thus GetWindowText is not a member of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 08:06 AM
  3. Converting character array to integer array
    By quiet_forever in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2007, 06:48 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 06:48 PM
  5. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21