Results 1 to 13 of 13

Thread: What does =ASC() do?

  1. #1

    Thread Starter
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    What does =ASC() do?

    Says Here But it doesn't really help.

    I have been playing with this function but I have yet to find out if it is useful at all or not.

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: What does =ASC() do?

    Definition from MSDN:

    Asc Function returns an Integer representing the character code corresponding to the first letter in a string.

    This example uses the Asc function to return a character code corresponding to the first letter in the string.

    Dim MyNumber
    MyNumber = Asc("A") ' Returns 65.
    MyNumber = Asc("a") ' Returns 97.
    MyNumber = Asc("Apple") ' Returns 65.
    CS

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: What does =ASC() do?

    This is generally used to distinguish between upper & lower case letters, but you can look up ascii values for all kinds of symbols (and some that aren't, like carriage returns).
    Tengo mas preguntas que contestas

  4. #4

    Thread Starter
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: What does =ASC() do?

    No no no, not in VBA. I use ASC all the time in VBA. But if you use it as a formula, it's different.

    This is quoted from the page which I posted a link to:

    For Double-byte character set (DBCS) languages, changes full-width (double-byte) characters to half-width (single-byte) characters.

    An example it shows:

    Formula Result
    =ASC("EXCEL") "EXCEL"


  5. #5
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: What does =ASC() do?

    In this forum, we would all assume that you are talking about an Excel formula. Your link indicates that you are making reference to "Share Point Services". You might close out this thread and create a new thread specifically referencing "Share Point Services: ASC() Function"
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: What does =ASC() do?

    Its not Share point services only as Excel VBA does have the ASC function and says the same thing in its help file as was linked to.

    http://office.microsoft.com/assistan...61033&Client=1
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: What does =ASC() do?

    So much for the HelpHeap ... this situation must be version specific. I'm running Excel 2003 and there is NO Help info in Excel (not in VBA Editor) for "ASC()", but the cell formula "=ASC(A1)" doesn't barf and returns a text string from the text contents of A1 ("TEST" > "TEST"). Leave it to Megashaft to use the exact same name ("ASC()") for two totally different functions and totally ignore one of them in the HelpHeap.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: What does =ASC() do?

    Well, what practical use is the function?
    Tengo mas preguntas que contestas

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: What does =ASC() do?

    I have no idea other then to compact some text without actually changing the string. Kind of a font width thing. Double byte to Single byte but are we talking about memory bytes or something else?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: What does =ASC() do?

    This made me think of some work I did awhile back (and have completely lost track of) regarding strings and Unicode, and I distinctly remember alternating zeros and ascii codes. I was thinking that this function (ASC()) might be used to convert a Unicode string of ASCII characters into a single-byte string (or an array of characters) ??? I have a note highlighted in my "Definitive Guide to Excel VBA" that says "NOTE: Characters are stored internally in Unicode format, that is, with two bytes per character." I built a quick String-To-Byte-Array (thanks to previous help by Declan Kenny) and my test strings come back as single byte ASCII codes. Am I going crazy or what?
    Code:
    Option Explicit
    'MS Windows API Call
    Private Declare Sub CopyMemory Lib "KERNEL32" _
        Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    
    'Convert a String to an Array of Bytes
    Function StringToByteArray(ByRef aString As String) As Byte()
        Dim StrLen As Long
        Dim Buffer() As Byte
        
        'Fetch the length of the Buffer - assumes single byte
        StrLen = Len(aString)    ' * 2  for Unicode???
        'Don't bother with a null string
        If StrLen > 0 Then
            'Set the new size of the buffer
            ReDim Buffer(0 To StrLen - 1) As Byte
            'Fetch the String into the Byte Buffer
            CopyMemory Buffer(0), ByVal aString, StrLen
            'Set the Return parameter to the loaded buffer
            StringToByteArray = Buffer
        End If
    End Function
    
    Sub Test_It()
        Dim aStr As String
        Dim bStr() As Byte
        Dim i As Integer
        
        aStr = Cells(1, 1).Text
        'aStr = "This is a test.  This is only a test."  < Both of these do the same thing
        
        bStr = StringToByteArray(aStr)
        Debug.Print LBound(bStr), UBound(bStr)
        
        For i = 0 To UBound(bStr)     '<<< Shows single byte ASCII characters !!!
            Debug.Print bStr(i), Chr(bStr(i))
        Next i
        
    End Sub
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: What does =ASC() do?

    But what is this used for? That's what I don't see. Something so memory critical as to require double byte characters to be converted to single byte doesn't really seem compatible with the memory requirements of Excel itself. Maybe if it needs to be exported to some other device, but it seems tedious to do that in formulas for cells instead of in the export process.
    Tengo mas preguntas que contestas

  12. #12
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: What does =ASC() do?

    I suspect it is more aesthetic than memory-related. If you were using Excel as a platform for an app that required outputting to some kind of message area, formed from a merging of a few cells for example, then you might want to make sure that your text was always going to fit in regardless of the font.

    Or maybe you've constructed a multi-column list out of a single cell - you need to know how many spaces to put in between each column and hence you don't want it to get confused by having multiple width fonts. Like you might use Courier to accomplish a similar task.


    Just a thought.

    zaza
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  13. #13

    Thread Starter
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068

    Re: What does =ASC() do?

    Haha wow, haven't been following this due to being busy at work. It seems I have dug up an alien corpse or something.

    Whatever this is used for, it doesn't seem to be anything that any of us need.

    Thanks for all the replies.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width