Can I save the information from common dialog
Save as Jpg or Bmp
format to an INI file and retrive it when the program starts.

Now I have this line

Image4.Picture = LoadPicture(App.Path & "\test.bmp")

to load the picture.
and it's not good.

I would prefer to have that the ini file
loading the last saved picture to
image4.picture.
and how to do it?

please

Recommended Answers

All 8 Replies

I have not tested this.. but this should work..

Dim ojbIni As New FileSystemObject
Dim IniStream As TextStream

If ojbIni.FileExists(App.Path & "\inifilename.ini") Then    'checking if ini file is present on the root of your vb project, if not it will automatically create
    Set IniStream = ojbIni.OpenTextFile(App.Path & "\inifilename.ini", ForWriting, False, TristateUseDefault) 'for writing ini to the file
Else
    Set IniStream = ojbIni.CreateTextFile(App.Path & "\inifilename.ini", True) 'for creating ini file
End If

'Write on the first 2 lines of the .ini file (first line is header, second is your picture path
IniStream.WriteLine "[Last_Browse_Picture]" 'the parent header of the .ini file
IniStream.WriteLine commondialog.filename   'your commondialog filename

IniStream.Close
Set IniStream = Nothing

You must enable "Microsoft Scripting Runtime" in reference..

Hi

I will test it and replay to you how it work's

Blocker

It work's just fine
but how can I retrive
the info from Ini file to

Image4 = app.path & "\inifilename.ini"
is this the right way

You need to read lines of your ini stream just like this (not tested yet):

Dim ojbIni As New FileSystemObject
Dim IniStream As TextStream
Dim filenamex As String

If ojbIni.FileExists(App.Path & "\inifilename.ini") Then
    Set IniStream = ojbIni.OpenTextFile(App.Path & "\inifilename.ini", ForReading, False, TristateUseDefault)  'for reading ini to the file

    While Not IniStream.AtEndOfStream
        filenamex = ""
        filenamex = IniStream.ReadLine
    Wend

   Picture1.Picture = LoadPicture(filenamex)
End If

This code assumes that the last line of your .ini stream is the filename.

Hi

If this is a true ini file that could contain more than one value or section then you should consider using the API's that were created for managing ini files such as GetPrivateProfileString and WritePrivateProfileString.

Check out this tutorial on working with ini files for more information and examples.

HTH

Blocker

It don't load at start up.
the inifile is correct

how can we know...? show your code...

I missed a punktation

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.