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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I don't understand the code 2

Status
Not open for further replies.

quaked2023

Technical User
Joined
Jan 22, 2004
Messages
105
Location
MX
Hello!: I downloaded a vb project from the internet but i don't understand the code completely... here is the code:


Dim dbname As String
Dim db As Database

' Open the database.
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)

Now i know what the code does, that is to open a database using the control data the part that i don't understand is the If part... i have no idea what is the if for, what does Right$(dbname,1) means.... i also notice that ther is no END IF but there is no error because of this.

Can you help me? Thanks in advance (sorry for my bad english)

-The Only Privacy Left Is The Inside Of Your Head!- QUAKED2023
 
App.path returns the path where the application is located if it is located in the root of C then "C:\" is returned, if it is located in a folder then "c:\TheFolderName" is returned. What is happening is app.path is being assigned to the string dbname then the if statement is checking the farthest right character in the string to see if it is a "\" or not and if not its appending it to dbname. As far as no end if, that is valid for single line if statements here's some reading:
Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 

Right$(dbname, 1) is a refereance to the last character (right hand end) of the string.

Right$(dbname, 2) would mean the last 2 characters.

This implies that string dbname (path) may or may not have a / at the end. The code ensures there is onr before appending the file name.


If there is no ELSE clause and the statemant is all on one line you dont need an End If.
 
Hello DrJavaJoe and SonOfEmidec1100 thanks for your tips now i understand the code.... Thank you so much!

-The Only Privacy Left Is The Inside Of Your Head!- QUAKED2023
 
In the old days (Win9x etc) the App.Path statement returned the whole path, including the last backslash:

C:\Program Files\Microsoft Visual Studio\VB98\test\

In later OSs the last backslash is missing

C:\Program Files\Microsoft Visual Studio\VB98\test

That line of code ensures the same result from either version of App.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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top