|
-
Oct 2nd, 2001, 09:20 AM
#1
Thread Starter
New Member
select file from combobox and open database in alchemy viewer
Hi i posted an earlier message todag and ask how to access an .ini file select a string from it an use that to open a database
well Peet send me the following code (many thanks) but i stil have a question.
==============================================
Option Explicit
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long, ByVal lpFileName As String) As _
Long
Private Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As Any, ByVal _
lpString As Any, ByVal lpFileName As String) As Long
Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Private Sub Command1_Click()
WriteINI "DBParam", "DBName", "C:\myapp\db\mydb.mdb", "C:\TEST.INI"
WriteINI "Temp", "TMPPath", "C:\myapp\tmp", "C:\TEST.INI"
End Sub
Private Sub Command2_Click()
MsgBox ReadINI("DBParam", "DBName", "C:\TEST.INI")
MsgBox ReadINI("Temp", "TMPPath", "C:\TEST.INI")
End Sub
==============================================
Well this code selects from the ini file a section [DBParam] a key "DBName" and a path of a database. So the ini file will look like this
[DBParam]
DBName=C:\myapp\db\mydb.mdb
[Temp]
TMPPath=C:\myapp\tmp
Ok so far so good
Now my ini file look a little bit different
example:
[Open database]
\\BJ2046\Databases\Databases\image.ald=Image Database
\\BJ2046\Bart\Test\Databases\odbc.ald=ODBC Demo Database
So i can't select the key because their isn't one. I just what to select the following string "\\BJ2046\Databases\Databases\"
Ok well i have a combo box that connect to odbc. So in the combo box i can select the name of the database (like: Image and odbc)
So what I what to do is, when i select a database in the combo box and press a button ("ok") the database must be opened in an alchemy viewer (not of importance at this moment)
Everything seems working correct like, connecting to odbc and opening the viewer, but the viewer isn't referencing to the correct path (adress). This because the ini file changes very often so i cant say:
Dim DB As Alchemy.Database
Set DB = au.Databases.Add("\\BJ2046\Databases\Databases\" & combobox.text & "*.ald")
because then i can't open the odbc database but only the image database
Ok well finaly here is my REAL question:
How can i use the Read.INI function (without the key) to select the path. So when i select "odbc" it has to use
\\BJ2046\Bart\Test\Databases\ as path and when i select
"image" it has to use \\BJ2046\Databases\Databases\ as path.
Many thanks
Bart
-
Oct 2nd, 2001, 11:36 AM
#2
This should work if you store both paths in your .InI file, one under a section called ODBC and one under a section called Image.
Then, depending on what was selected from your Combo box, your program would read the appropriate part of you .InI file.
-
Oct 3rd, 2001, 02:06 AM
#3
Thread Starter
New Member
thanks, but....
Thanks Hack but,
the ini file is generated automaticly from the server. So there is an ini file local on my pc. But when i restart the ini file is put to his defeault settings from the server. And when I run the program on an other pc the alchemy.ini has also the default settings
So when i open a alchemy database it writes it's path to the alchemy.ini under [open database] \\BJ2046\etc
So what i want my program to do is when i select a database from a combobox, and press a button ("ok") the database must be opened in a alchemy viewer.
Bart
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|