Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 27th, 2004, 05:04 PM
Mat Mat is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 23 Mat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 22 sec
Reputation Power: 0
Import lines from an ini file

Hi

I want to import certain lines of data from an ini text file and insert it into a form text box
eg Entry in ini file is "ArchiveDir=c:\archive". How can I search this file and insert "c:\archive" in
thetext box txtArchive on a form?
If the user also amends the directory using the text box - how dow you write it back to the ini file on closing ?
Any help from a realatively new VBA programmer would be much appreciated.
Thanks, Mat.

Reply With Quote
  #2  
Old December 28th, 2004, 06:00 PM
samdland samdland is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 4 samdland User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I use the following

Add to Module
Code:
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
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long


Add textbox and command button to form, and add the below code to form.
Code:
Function ReadINI(Section, KeyName, filename As String) As String
	Dim sRet As String
	sRet = String(255, Chr(0))
	ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
 
Function writeini(sSection As String, sKeyName As String, sNewString As String, sFileName) As Integer
	Dim r
	r = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
End Function
Private Sub Command1_Click()
Text1 = ReadINI("section1", "beeoch", App.Path & "\set.ini")
End Sub


Your ini file should be formated like the follwoing example.
Code:
[section1]
Place=junk
beeoch=return-one
poo=crap
[section2]
beeoch=return-two
bog=lop


Sam Land
Dynamic DNS Server Suites

Reply With Quote
  #3  
Old December 29th, 2004, 03:12 AM
Mat Mat is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 23 Mat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 22 sec
Reputation Power: 0
Write to ini file

Sam,
Brilliant ! Thanks for that simple but very useful advice.
I now would like to be able to modify what is in the text box and write that back to the ini file. Could you help with some
pointers for that? Your help is much appreciated from this relatively newbie at VBA.
Mat.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Import lines from an ini file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway