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>;
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:
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
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
Last edited by silver_mica; October 22nd, 2010 at 01:06 PM.
Reason: Attachment Didn't stay attached.
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:
Originally Posted by silver_mica
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.
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.
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
Last edited by silver_mica; October 23rd, 2010 at 08:54 PM.
Reason: clarity
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.