#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11

    Post How can I get Label1->Text To Integer or the length of Label1->Text


    I use VC++ .net, bad for me StrToInt is not working:mad:

    How can I convert Label1->Text to Integer or the length of Label1->Text?
  2. #2
  3. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    I don't really know what your talking about?
    If you want to convert string to integer, like "1016" to 1016, look at the function below, if you want to convert num to string, like 1016 to "1016", look at wsprintf(). GetWindowTextLength gets the length of text in a window. strlen() can be used to get length of a string.

    http://msdn.microsoft.com/library/de...TextLength.asp

    Code:
    int s2n(char *str) 
    {
    	//accept a string, and return the number ("1016" will be 1016.. works for negative)
    	int n=0; 
    	int len=slen(str); 
    	int base=1; 
    	int neg=(str[0]=='-')?1:0; //1==neg,0==pOs 
    
    	for(;--len>=neg;n+=(str[len]-'0')*base,base*=10) //Compact :) 
    		if(str[len] > '9' || str[len] < '0')
    			return 0; 
    	return neg ? n * -1 : n; //if negative, times by -1 
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13
    If what you want is the value represented by the string you could use the atoi : (C)
    #include <stdlib.h>
    int atoi(const char *s).
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    12
    In C++ .NET you can convert almost anything with the Convert class. i.e.

    String *sNum = S"100";
    int iNum = Convert::ToInt32(sNum);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11
    #1 thanks for the answers

    #2 new problem:

    Code:
    String* myString = Convert::ToString(comboBox1->Text);
    int i=strlen(myString);
    causes this error:
    error C2664: 'strlen': Conversion of Parameter 1 from 'System::String __gc *' to 'const char *' not possible

IMN logo majestic logo threadwatch logo seochat tools logo