Using Win32 functions in Visual FoxPro Image Gallery
String
..msdn
CharLower
CharToOem
CharUpper
OemToChar
StrCmpC
StrFormatByteSize
StrFromTimeInterval
StrToInt
StrToIntEx
StrTrim
Code examples:
Converting a decimal string to an integer
StrToInt
..msdn    Add comment     W32 Constants      Translate this page
Converts a decimal string to an integer. The StrToLong macro differs from this function in name only.
Code examples:
Converting a decimal string to an integer
Declaration:
int StrToInt( 
    LPCTSTR lpSrc 
    );

#define StrToLong StrToInt

FoxPro declaration:
DECLARE INTEGER StrToInt IN Shlwapi STRING lpSrc
DECLARE INTEGER StrToLong IN Shlwapi STRING lpSrc
Parameters:
lpSrc
Address of the null-terminated string to be converted.
Return value:
Returns the INT value of a string.
My comment:
See also: StrToIntEx, StrToInt64Ex

Both functions work identically. The difference is 4 bytes for the INT and 8 bytes for the LONG.

Native functions VAL and INT deliver quite sufficient functionality. Though another Win32 function from this family -- StrToIntEx -- gives a bit more.

* * *
When populating or parsing API structures, very often converting between 2, 4 and 8-byte strings to VFP numeric values and back is required.

In VFP9, for converting between binary character representations and numbers use BINTOC() and CTOBIN() native VFP functions.

In all VFP versions, for the same task use buf2word, buf2dword, num2word and num2dword functions.

FUNCTION buf2dword(cBuffer)
RETURN Asc(SUBSTR(cBuffer, 1,1)) + ;
        BitLShift(Asc(SUBSTR(cBuffer, 2,1)), 8) +;
        BitLShift(Asc(SUBSTR(cBuffer, 3,1)), 16) +;
        BitLShift(Asc(SUBSTR(cBuffer, 4,1)), 24)

FUNCTION buf2word(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Asc(SUBSTR(lcBuffer, 2,1)) * 256

FUNCTION num2dword(lnValue)
#DEFINE m0 0x0000100
#DEFINE m1 0x0010000
#DEFINE m2 0x1000000
        IF lnValue < 0
                lnValue = 0x100000000 + lnValue
        ENDIF
        LOCAL b0, b1, b2, b3
        b3 = Int(lnValue/m2)
        b2 = Int((lnValue - b3*m2)/m1)
        b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
        b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

FUNCTION num2word(lnValue)
RETURN Chr(MOD(m.lnValue,256)) + CHR(INT(m.lnValue/256))

Rarely a conversion to and from float binary representation is required. In this reference only a few GDI+ functions may need that.

#DEFINE REAL_BIAS 127
#DEFINE REAL_MANTISSA_SIZE 23
#DEFINE REAL_NEGATIVE 0x80000000
#DEFINE EXPONENT_MASK 0x7F800000
#DEFINE MANTISSA_MASK 0x7FFFFF

FUNCTION Float2Int(num)
* converts 32-bit float form to FoxPro numeric
        IF num = 0
                RETURN 0
        ENDIF
        LOCAL sgn, exponent, mantissa
        sgn = IIF(BITTEST(num,31), -1,1)
        exponent = BITRSHIFT(BITAND(num, EXPONENT_MASK),;
                REAL_MANTISSA_SIZE) - REAL_BIAS
        mantissa = BITAND(num,;
                MANTISSA_MASK) / 2^(REAL_MANTISSA_SIZE-exponent)
RETURN (2^exponent + mantissa) * sgn

FUNCTION Int2Float(num)
* converts FoxPro numeric to 32-bit float form
        LOCAL sgn, exponent, mantissa
        DO CASE
        CASE num < 0
                sgn = REAL_NEGATIVE
                num = -num
        CASE num > 0
                sgn = 0
        OTHERWISE
                RETURN 0
        ENDCASE
        exponent = FLOOR(LOG(num)/LOG(2))
        mantissa = (num - 2^exponent)* 2^(REAL_MANTISSA_SIZE-exponent)
        exponent = BITLSHIFT(exponent+REAL_BIAS, REAL_MANTISSA_SIZE)
RETURN BITOR(sgn, exponent, mantissa)
Word Index links for the StrToInt :
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
Created: 2001-08-15 12:00:00
Modified: 2012-09-25 12:40:07
Visited in last 7 days: 28
User Contributed Notes:
There are no notes on this subject.


Copyright 2001-2017 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.37), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.225.20.73)
11 sec.Function: 'keybd_event'
24 sec.Function: 'ShowHTMLDialog'
38 sec.Function: 'GlobalSize'
50 sec.
Function group: 'Multilingual User Interface'
1.03 min.Function: 'GetModuleHandle'
1.28 min.Function: 'InitCommonControlsEx'
1.53 min.Function: 'NetApiBufferSize'
1.75 min.Function: 'PathIsDirectory'
1.97 min.Function: 'OpenVirtualDisk'
2.17 min.Function: 'GetSecurityDescriptorOwner'
Google
Advertise here!