Function help
I am trying to get the information from textbox1 and output it into an array. I have tried this:
char chrsplit[1000]
strcpy(chrsplit, enctextbox->Text->ToCharArray());
but i get this error
error C2664: 'strcpy' : cannot convert parameter 2 from 'cli::array<Type,dimension> ^' to 'const char *'
with
[
Type=wchar_t,
dimension=1
]
i found on another forum that this may be because "the ToCharArray() function does not return a char*" so they told me to try and find a diffrent function dose anyone know of a diffrent function to do the same thing. or is there away to fix the code i already have.
Why are you trying to load it into an array? Is that your goal, or just the way your trying to reach your goal?
In the end i want to take the characters from the text box and change them to an ineger. then put them into an equation. then on the other tab it will take the integers run them through the reverse operation and out put the original charachters.
What about this:
int x;x = System::Convert::ToInt16(enctextbox->Text); //Convert to int
.
.
your equation
.
.
enctextbox->Text = System::Convert::ToString(x); //convert to string
Just to restate the problem i am trying to conver letters into numbers from the text box enctextbox.
dose this function even convert characters to integers or dose it convert a string of numbers into integers.
but anyway I tried that but for now I am taking out my equation just to get the basics running first. The program runs but when I put in a letter it says
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
just as extra:
ive tried this
encout->Text = x; but the program won't even run and i get the error
error C2664: 'void System::Windows::Forms::Control::Text::set(System::String ^)' : cannot convert parameter 1 from 'int' to 'System::String ^'
No user-defined-conversion operator available, or
No standard conversion exists from the boxed form of the arithmetic type to the target type
To get the string from the textbox you can use
String^ myString = myTextbox->Text;
You can verify it with
MessageBox::Show ( myString );
You should be able to do your conversion from there.
This is what i am trying to use to convert the string into an array or characters but im getting some errors.
String^ mystring = textbox1->Text;
int x;
char number[100];
do
{
if (mystring=='a')
number[x]=11;
if (mystring=='.')
number[x]=99;
x++;
}while(mystring =! '.');
textbox2->Text = ( mystring ); but i am getting these errors
error C2446: '==' : no conversion from 'int' to 'System::String ^'
No user-defined-conversion operator available, or
No standard conversion exists from the boxed form of the arithmetic type to the target type
error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int'
error C2446: '==' : no conversion from 'int' to 'System::String ^'
No user-defined-conversion operator available, or
No standard conversion exists from the boxed form of the arithmetic type to the target type
error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int'
error C2440: '=' : cannot convert from 'bool' to 'System::String ^'
No user-defined-conversion operator available, or
No standard conversion exists from the boxed form of the arithmetic type to the target type
I am guessing that it cannot read through a string and convert it like i want. So what do i need to do?
I don't think your description of the problem is clear. What exactly are you trying to do?
For example:
1. You want to convert the individual characters to their ASCII equivalent integer value, and add the numbers?
2. You want to convert the characters to an integer value based on some particular algorithm that you specified, such as 'a' = 1, 'b' = 2, ... 'z' = 26, etc., and add the numbers?
Also note that if you simply add the values, get an integer, and try to decode it back to the original string, your answer will be ambiguous. For instance, ('a'=1) + ('z'=26) = 27, which could also represent a special character, or a string of 27 'a' characters.
1.What i want to do is get the message from the text box.
2.Then i want to assigne each letter its own value.
3.Then i want to run it through an algorithum. for example the number +1
4.Then out put it into another textbox.
1. then on the other tab of the program i want to input the numbers that you get from the second text box run them through the revers algorithum. the number - 1
2. Then i want to take the numbers and put them back to abc ext
3. And finally print the decoded message to another textbox
now i know there is a problem with taking a string of integers and changing it to individual integers but i fixed that with this code. I already have this program running for dos but i want to do it in windows form now. that is what this is all about. If it would help i can send email you the .cpp files for the original dos program.
for(y=0; y<x-1; y++)
{
place = y%2; //convert string to dgits
if(place==0)
tens = number

* 10;
if(place==1)
{
ones = number

;
integers
![[Z]](/library/msdn/emoticons/emotion-47.gif)
= tens + ones;
convertints();
cout <<message
;
z++;
}
}
Search the VC++ Express help for "convert string array"
The code sample should help.
Can you post a link to what you are talking about.
i googled what you said and i found a page that told me to use this.
int x, size;
char strArray;
char Array[100]
String^ mystring = enctextbox->Text;
size = StrLen(mystring);
strArray = ArrDimension(size);
do
{
Array[x] = strSub(mystring, x+1, 1);
}while(x<size-1);
im not sure if i have everything declared right so correct me if im worng. But i know that StrLen and strSub and mabey ArrDimension are functions. but they are not recognized. I have string.h included and i have tried to include Strsafe.h but that is not found.
In the VC++ 2005 Express Edition help file there is an article titled:
"How to: Convert char * String to System::Byte Array"
If you launch the help file, and search for the words "convert string array" (without the quotes), you will find the article.
If you successfully coded this in DOS, then you are probabaly doing something wrong in regards to libraries, namespaces, or unmanaged code. See if the above article helps.
no im getting an error. This is what i tried
char buf[] =textbox1->Text;
int len = strlen(buf);
array< Byte >^ byteArray = gcnew array< Byte >(len + 2);
// convert native pointer to System::IntPtr with C-Style cast
Marshal::Copy((IntPtr)buf,byteArray, 0, len);
for ( int i = byteArray->GetLowerBound(0); i <= byteArray->GetUpperBound(0); i++ )
{
char dc = *(Byte^) byteArray->GetValue(i);
Console::Write((Char)dc);
}
Console::WriteLine();
and this is the error im getting. im guessing it can't convert sytem string into an array.
error C2440: 'initializing' : cannot convert from 'System::String ^' to 'char []'
No user-defined-conversion operator available, or
There are no conversions to array types, although there are conversions to references or pointers to arrays
i also tried
String^ buf = textbox1->Text;
but i get these errors
error C2664: 'strlen' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
No user-defined-conversion operator available, or
Cannot convert a managed type to an unmanaged type
error C2440: 'type cast' : cannot convert from 'System::String ^' to 'System::IntPtr'
Conversion requires a constructor or user-defined-conversion operator, which can't be used by const_cast or reinterpret_cast