Dim a3 as string * 3 vs Left(x,3)

Guus2005

AWF VIP
Local time
Today, 09:12
Joined
Jun 26, 2007
Messages
2,642
In my application users are allowed to create their own queries. I call them user queries.
User queries are lost each time the Frontend on the network is copied to the users temporary directory overwriting the Frontend containing the user queries. So i have come up with a method to store the user queries in a table and they are recreated each time the user starts the application.

I have a string variable which can contain three characters (a3)
Code:
a3 = "qruLongQuery"
?a3
qru

The complete function:
Code:
Public Function SaveUserQueries() As Boolean
'Store query in table when prefix match qru (user) or qra (all)
    
    Dim qdf  As QueryDef
    Dim a3   As String * 3 'Only three characters
    
    DeleteUserQueries 'Delete queries allready stored.
    
    For Each qdf In CurrentDb.QueryDefs
        a3 = LCase$(qdf.name)
        If a3 = "qru" Or a3 = "qra" Then 'If LCase$(Left$(qdf.name, 3)) = "qru" Or LCase$(Left$(qdf.name, 3)) = "qra" Then
            SaveUserQuery qdf.name
        End If
    Next qdf

End Function
My question is: It is a bit dirty (like cheating) but is this valid code?

I want to make sure that in future versions of Access (2007, 2010, ...) this code still works.

Thx!
 
It is valid code for what you are trying to do. In VB6 the big difference between a fixed length string and variable length is that the fixed length string memory was allocated at runtime and the variable length is determined at runtime (not sure how this relates to VBA as it is an interpreted language and not compiled in the same way). Unless they change the VBA architecture I can't see why your code would not work in future versions.
 

Users who are viewing this thread

Back
Top Bottom