Cotswold
Active member
- Local time
- Today, 02:00
- Joined
- Dec 31, 2020
- Messages
- 649
This has probably been there for ever but I've only just found it.
I have a complex function that concatenates a contiguous string, that I have used for some time in another language. I have just converted it into Access and it was falling about, for no apparent reason. In this routine at specific locations, specific numbers are inserted, which are read back from another function later.
In Access it does appear that the Str() function carries with it an additional leading space that other languages do not. This has the result of moving the converted number to the right. In most cases this will not matter or be noticed as it is probably displayed on the screen or printer in a TTfont.
However, in this example it does matter as it places the numbers at an incorrect position and also extends the length of the completed string with each number inserted.
I doubt that MS will correct this but if anyone is using Str() in a concatenated string they will need to use Trim(Str()) to get it right.
I have prepared a simple example showing how Str() is not correct in Access. It is the same in Access2010, 2019 32bit and 2021 64bit.
I have a complex function that concatenates a contiguous string, that I have used for some time in another language. I have just converted it into Access and it was falling about, for no apparent reason. In this routine at specific locations, specific numbers are inserted, which are read back from another function later.
In Access it does appear that the Str() function carries with it an additional leading space that other languages do not. This has the result of moving the converted number to the right. In most cases this will not matter or be noticed as it is probably displayed on the screen or printer in a TTfont.
However, in this example it does matter as it places the numbers at an incorrect position and also extends the length of the completed string with each number inserted.
I doubt that MS will correct this but if anyone is using Str() in a concatenated string they will need to use Trim(Str()) to get it right.
I have prepared a simple example showing how Str() is not correct in Access. It is the same in Access2010, 2019 32bit and 2021 64bit.
Code:
Dim LeftStr, RightStr, AllStr, LenStr As String
Dim MidStr As Long
LeftStr = "01234567890"
RightStr = "9876543210"
MidStr = Len(LeftStr)
AllStr = LeftStr + Str(MidStr) + RightStr
MsgBox AllStr + " <This has the extra space"
LenStr = Trim(Str(MidStr))
AllStr = LeftStr + LenStr + RightStr
MsgBox AllStr + " < with extra space removed"
AllStr = LeftStr + Trim(Str(MidStr)) + RightStr
MsgBox AllStr + " < with extra space removed"