Results 1 to 4 of 4
  1. #1
    cesarone82 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2009
    Posts
    25

    Convert a single character to string

    Hi,



    I have a string which needs to be split in single characters to fill in a pdf form. The issue is that it seems that the function is expecting a string, while when i reference I single character i don't get a string type:

    Dim st1 as String
    st1= "ABCDE"

    Dim st2 as String
    st2=st1(1)

    Seems the latter is not possible, how can i create a string with a single character? BTW i saw some examples in internet using Char type, but it seems in VBA7 there is not such type

  2. #2
    cesarone82 is offline Novice
    Windows 11 Access 2016
    Join Date
    Jun 2009
    Posts
    25
    Quote Originally Posted by cesarone82 View Post
    Hi,

    I have a string which needs to be split in single characters to fill in a pdf form. The issue is that it seems that the function is expecting a string, while when i reference I single character i don't get a string type:

    Dim st1 as String
    st1= "ABCDE"

    Dim st2 as String
    st2=st1(1)

    Seems the latter is not possible, how can i create a string with a single character? BTW i saw some examples in internet using Char type, but it seems in VBA7 there is not such type
    Ok i got it using MID function, seems not possible to address with st1(index)

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,445
    seems not possible to address with st1(index)
    you can do it with a byte array, tho' I suspect no better than using the mid function

    Code:
    Dim b() As Byte
    Dim i As Integer
    
    
    b = "ab1De"
    For i = 0 To UBound(b) - 1
       Debug.Print Chr(b(i))
       i = i + 1
    Next i
    note that characters use 2 bytes, hence the need for i+1.

    If you are using characters with an ascii code greater than 254 then you need to use

    Debug.Print ChrW(b(i) Xor b(i + 1))

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,006
    It would be if you used the Split() function, but you have nothing to split it by.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. insert a single character (-) in a string
    By DaveT99 in forum Queries
    Replies: 3
    Last Post: 02-14-2022, 02:01 PM
  2. Replies: 3
    Last Post: 07-20-2020, 01:04 PM
  3. Replies: 2
    Last Post: 04-28-2018, 11:16 AM
  4. Replies: 5
    Last Post: 05-10-2017, 12:10 PM
  5. How do I return last character in a string?
    By SSgtBarry in forum Queries
    Replies: 4
    Last Post: 06-22-2014, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums