Navigation:  thinBasic Modules > Core > String handling >

ASC

Previous pageReturn to chapter overviewNext page

 

Description

 

Return the ASCII code (0 to 255) of the specified character in a string.

 

Syntax

 

y = ASC(StringExpression [, position])

 

Returns

 

Number

 

Parameters

 

Name

Type

Optional

Meaning

StringExpression

String

No

A string expression from which to extract the ASCII code.

Position

Number

Yes

Position inside string_expression from which to extract ASCII code.

If position is not specified, the first position is taken.

If position is negative ASC counts from the end of the string.

If position is zero or greater than the length of the string -1 is returned

 

Remarks

 

Restrictions

 

See also

 

String Handling, CHR$,

 

Examples

 

'---ASC can be used to avoid some MID$ operations. For example:

char = ASC(Mid$(MyString, Position, 1))

'---is equivalent to ...

char = ASC(MyString, Position)

 

 

Thanks to Abraxas for the following script example

' Usage of the ASC Instruction example

' Return Values of a string. Will show a box with String to check

'

' HELLO

'

'Current Char H Value 72

'Current Char E Value 69

'Current Char L Value 76

'Current Char L Value 76

'Current Char O Value 79

 

Dim MyString  As String VALUE = "HELLO"

Dim sMsg      As String

Dim StrPos    As Long

Dim CharVal   As Byte

 

sMsg = "String to check " & $CRLF & $CRLF & MyString & $CRLF & $CRLF

 

For StrPos = 1 To Len(MyString) '---Loop for the length of the string

  CharVal = ASC (MyString,StrPos)

  sMsg += " Current Char " & Mid$(MyString,StrPos,1) & " Value " & CharVal & $CRLF

Next

 

MSGBOX 0, sMsg

 

 

 

© 2004-2008 thinBasic. All rights reserved. Version 1.7.0.0 Web Site: http://www.thinbasic.com