Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wierd string variable substitution effect 1

Status
Not open for further replies.

SteveGlo

Programmer
Sep 30, 2002
1,560
GB
I came across an anomaly yesterday as a result of mistyping and although I know the resolution of the error I don't know what is going on and I'd like to understand what is happening.

In this code sniplet:


Dim dbpath As String
dbpath = "C:vbrandr\random\db1.mdb"
Set cnnstring = New ADODB.Connection
cnnstring.Provider = "Microsoft.Jet.OLEDB.4.0"
cnnstring.Open dbpath, "admin", ""


I'd missed out the first '\' in "C:\vbrandr\random\db1.mdb".

When I run the code (in IDE) an error was generated that read:

'C:\vbrandr\Random\vbrandr\random\db1.mdb' is not a valid path

What perplexes me is why "C:vbrandr\random\db1.mdb" turns into 'C:\vbrandr\Random\vbrandr\random\db1.mdb' ?

When I correct the typo the code works correctly.

(the folder name is C:\vbrandr\Random)
 
It's because C: without the backslash is the same as saying 'C:starting from the directory I'm in now'

If you're in C:\vbrandr\Random and ask for C:vbrandr\random\db1.mdb (note missing first backslash) you append the bit from C: onto the existing path

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
interesting indeed,
I could produce the same result in one of my apps
Maybe it's an attemted auto-mechanism that doesn't build
the string correctly or the message-box-string is build
incorrectly.
other explications ?
 
John

The penny drops - thanks for explaining that.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top