Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > app.path


Reply
 
Thread Tools Display Modes
  #1  
Old 03-10-2002, 06:08 PM
sara
Guest
 
Posts: n/a
Default app.path


Hi I am getting a error when I call this

the app path is moving to a different directory even though I have put the database in the same location as the VB project any ideas?

g_mypath = App.path & "\dbTPF.mdb"


Call disable(Me)


g_connectstring = "Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=g_mypath"
Reply With Quote
  #2  
Old 03-10-2002, 06:10 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Try this: g_connectstring = "Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & g_mypath

It should not have been inside the quotes

HTH,
Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #3  
Old 03-10-2002, 06:12 PM
sara
Guest
 
Posts: n/a
Default

thanks
Reply With Quote
  #4  
Old 03-10-2002, 10:48 PM
JDT JDT is offline
Original Contributor

Retired Moderator
* Guru *
 
Join Date: Jan 2001
Location: Watch Window
Posts: 2,781
Default

Hi Sara

It looks like you solved your problem but I would like to point out a potential bug with your code:

App.Path has a well known bug with the slash at the end of the path. If the app is in a root directory like A:\, C:\, D:\, etc... then a slash will be returned at the end but if it is in a folder then no slash will be returned at the end. This will cause a run time error if you hard code the slash when your app is run from a root directory.

You can use this code to fix the bug. Just refer to AppPath instead of App.Path.

Code:
Option Explicit

Private AppPath As String 'use this instead of App.Path

Private Sub Form_Load()

  AppPath = App.Path
  If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
  
End Sub

Good Luck


JDT
Reply With Quote
  #5  
Old 03-12-2002, 06:03 AM
sara
Guest
 
Posts: n/a
Default

Do I put that code in a module? As I use app path all over the place!
Reply With Quote
  #6  
Old 03-12-2002, 06:12 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

Most off the time I either use a Public variable in which I store the correct path or I use a function for it.

Code:
' in module
Public sAppPath As String

Public Function MakePath(sPath As String) As String
  MakePath = App.Path
  If Right$(MakePath, 1) <> "\" Then MakePath = MakePath & "\"
End Function

' in sub Main() or Form_Load of main Form
sAppPath = MakePath(App.Path)
Reply With Quote
  #7  
Old 03-12-2002, 06:33 AM
sara
Guest
 
Posts: n/a
Default

Its a global variable so I dont have to reference it each time in the form loads
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->