CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Oct 2010
    Posts
    6

    Reading a Textbox into an array

    I’m totally stuck.

    Here is what I’m trying to do:

    I’m using Visual C++ 2008 and built a form that uses a text box

    The user enters a four digit alphanumeric code into the text box.

    I read this text using: textbox->text

    Next, I need to separate the four digits into ASCII code.

    The ASCII code of each character is placed in this array (exactly like this)

    InputBuffer[2] = <ascii code of first digit>;
    InputBuffer[3] = <ascii code of second digit>;
    InputBuffer[4] = <ascii code of thrid digit>;
    InputBuffer[5] = <ascii code of fourth digit>;

  2. #2
    Join Date
    Mar 2004
    Posts
    235

    Re: Reading a Textbox into an array

    There should be like a to c string function.

    See
    http://msdn.microsoft.com/en-us/libr...ing.chars.aspx

    and the full doc of string which textbox->text returns

    http://msdn.microsoft.com/en-us/libr...em.string.aspx
    01101000011001010110110001101100011011110010000001110011011001010111100001111001

  3. #3
    Join Date
    Oct 2010
    Posts
    6

    Re: Reading a Textbox into an array

    The reason why I posted here was because I spent hours upon hours searching the internet trying to make the above work. Yes, of course I visited that site numerous times. I do apologize for not being able to understanding it. I certainly wish that I did.

    Back when I was in school (which was decades ago) I had one C class (for the school's Unix system) and all I recall was that a string was nothing but an array of characters with a null pointer at the end, and you passed pointers to the first character of the string around when handing the string off to different functions and whatnot. It was that simple.

    Through haphazard searching last night, I came to a vague understanding that there are other types of strings available, system strings, managed and unmanaged strings (and more?). It seems that a conceptually simple task such as reading a text box string (which seems to be a "system string") and placing that into an array of characters becomes difficult or not possible when these strings and their differences are not well understood.

    Add this to fumbling around in Visual C++ for the first time (in contrast to only knowing a little C) and you're bound to come to your wit's end and seek help through a forum.

    Moving forward.

    So, in an effort to hack my way toward a solution I've come up with this.

    Instead of attempting to typecast the text box string into an array of characters I wrote the following:

    String ^userTXT = "Hello";
    userTXT = (textBox1->Text);

    The "Hello" wasn't necessary, but using String ^userTXT allowed the second line to run properly.

    Next, I used the following to obtain an ASCII code

    (int)userTXT[0];
    (int)userTXT[1];
    (int)userTXT[2];
    (int)userTXT[3];

    As a side note I wasn't sure if I should use (short int)userTXT[0]) or (unsigned short int)userTXT[0], but I just experimented and found (int)userTXT[0]) to work without incident, which is probably okay for the moment. (hacking!)

    By the way, in the second link that you give I would like to use Concat(String, String), but my compiler (I'm using Visual C++ 2008) does not recognize Concat. Is there a *.h file that I need to include? If there's another way to concatenate to the variable userTXT do let me know.

    Thanks for your help.
    Last edited by silver_mica; October 22nd, 2010 at 12:25 PM. Reason: code syntax and grammar

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Reading a Textbox into an array

    The code you showed is NOT a VC++. It looks more like a managed c++/cli code.
    So you have posted to the wrong Forum.
    Victor Nijegorodov

  5. #5
    Join Date
    Oct 2010
    Posts
    6

    Re: Reading a Textbox into an array

    Well, that was certainly helpful. The software package I'm using says Visual Basic C++ 2008. Perhaps it was mislabeled at the factory.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Reading a Textbox into an array

    Quote Originally Posted by silver_mica View Post
    The software package I'm using says Visual Basic C++ 2008.

    "Basic" or "C++"?

    And what type of project did you choose for this one?
    Victor Nijegorodov

  7. #7
    Join Date
    Oct 2010
    Posts
    6

    Re: Reading a Textbox into an array

    Quote Originally Posted by VictorN View Post

    "Basic" or "C++"?

    And what type of project did you choose for this one?
    From what I'm hearing this is beginning to sound a lot like a hodgepodge. I'm sure there's a reasonable explanation somewhere to be heard.

    You can download Visual C++ 2008 Express Edition from the Microsoft website (this is what I'm using).

    Here's the link: http://www.microsoft.com/express/Dow...008-Visual-CPP

    The link doesn't take you directly to VCPP2008, you have to press " Visual Studio 2008 Express" two-thirds up and to the right of the screen and then select Visual C++ 2008 Express Edition.

    Actually, I downloaded the all in one ISO file and this does include C# and Visual Basic as well as Visual C++, but you run each separately.

    I've screen captured what I'm using (by pressing Help-->About) and attached it to this post.

    So, as you might have guessed by this point I had every reason to believe that I was using Visual C++. If this isn't Visual C++ then you could imagine how confusing and frustrated I was while searching for an answer to my original problem. Luckily, I was able to hack something together that seems to work. However, it would be beneficial to know why this works for future reference.

    Thanks
    Attached Images Attached Images
    Last edited by silver_mica; October 22nd, 2010 at 01:06 PM. Reason: Attachment Didn't stay attached.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Reading a Textbox into an array

    You didn't answer my second question:

    ... what type of project did you choose for this one?
    Victor Nijegorodov

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Reading a Textbox into an array

    VictorN is right: What you're using is C++/CLI, and so this is the wrong forum here. But don't worry about that too much: Many beginners fail initially to correctly note that subtle difference. Just post further questions about that topic in the right forum. (And it wasn't really that obvious that you were talking about C++/CLI from your initial post.)

    So, I don't want to talk to much about C++/CLI in the wrong forum, just that little remark:

    Quote Originally Posted by silver_mica View Post
    By the way, in the second link that you give I would like to use Concat(String, String), but my compiler (I'm using Visual C++ 2008) does not recognize Concat. Is there a *.h file that I need to include? If there's another way to concatenate to the variable userTXT do let me know.
    Concat() is a static member function of the String class, therefore you have to qualify it as String::Concat(yourFirstString, yourSecondString).

    BTW: I wonder why MS is still offering the VS 2008 Express versions for download when there already is 2010 around since several months?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  10. #10
    Join Date
    Dec 2009
    Posts
    596

    Re: Reading a Textbox into an array

    Hello Silver Mica. Looks like you are working with a CLR Windows Form Application type project.

    String ^userTXT = "Hello"; is the giveaway. Visual C++ forum is for a family of programming projects and CLR CLI or Mangaged C++ or whatever you call it is the place for questions like yours. Yes you are running the C++ product from microsoft but you're in the wrong forum.

  11. #11
    Join Date
    Dec 2009
    Posts
    596

    Re: Reading a Textbox into an array

    I wrote when Eric523 wrote. Never mind the redundant info.

  12. #12
    Join Date
    Oct 2010
    Posts
    6

    Re: Reading a Textbox into an array

    Quote Originally Posted by Eri523 View Post
    BTW: I wonder why MS is still offering the VS 2008 Express versions for download when there already is 2010 around since several months?
    I really don't know. That would be like asking why Microsoft labels their product Visual C++ 2008 when it is clearly C++/CLI.

    Aside, thanks for the help.

  13. #13
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Reading a Textbox into an array

    Quote Originally Posted by silver_mica View Post
    That would be like asking why Microsoft labels their product Visual C++ 2008 when it is clearly C++/CLI.
    That's not too far off: The product can be used for both.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Reading a Textbox into an array

    Quote Originally Posted by silver_mica View Post
    I really don't know. That would be like asking why Microsoft labels their product Visual C++ 2008 when it is clearly C++/CLI.

    Aside, thanks for the help.
    As you've mentioned earlier, the version you are using does C# and Visual Basic along with C++.

    When you create a new project, you need to choose the correct C++ project template.

    The following is the new project dialog from the VS 2008 Team Edition. The express edition should be something similar.
    Attached Images Attached Images

  15. #15
    Join Date
    Oct 2010
    Posts
    6

    Re: Reading a Textbox into an array

    As stated you can install C#, Visual Basic and C++ separately. They are run as separate programs as well. However, I do see "CLR" as an option inside Visual C++ 2008 (when creating a new project).

    It would be better to label the software correctly if this really isn't Visual C++

    As can be seen in the attached photo Visual C++ is seen everywhere.

    My guess is that they have incorporated bits of other languages for some reason.

    Thanks
    Attached Images Attached Images
    Last edited by silver_mica; October 23rd, 2010 at 08:54 PM. Reason: clarity

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured