I have written code to enter data for the ini file in Access 2000. The ini file is the input for a report using Crystal Reports. I would like to replace the value in the current ini file with the new values entered into the Access form. Can someone tell me how to do this.
Here is a sample of the data in the current ini file I would like to replace the value in the lines User*Value= (value):
[ExtraSampleInfo]
ItemCount=11
User1Label=Gas Temperature
User1Value=50
User1SaveData=0
User2Label=Company
User2Value=duke
User2SaveData=0
User3Label=Sample Date
User3Value=2/5/6
User3SaveData=0
User4Label=Station Name
User4Value=test
User4SaveData=0
User5Label=Sampled By
User5Value=jb
User5SaveData=0
User6Label=Station Number
User6alue=
User6SaveData=0
User7Label=Flowing Pressure
User7Value=67
User7SaveData=0
User8Label=Plant
User8Value=Rockcreek
User8SaveData=0
User9Label=Cylinder #
User9Value=23
User9SaveData=0
User10Label=Composite/Spot
User10Value=Spot.
User10SaveData=1
User11Label=Barometer
User11Value=
User11SaveData=0
Col1Label=Item
Col1Width= 2190
Col2Width= 1920
User6Value=12345
Peak1Value=0
[ExtraPeakInfo]
ItemCount=2
Peak1Label=H2S
Peak1Value=0.5
Peak2Label=Oxygen
Peak2value=0.08
Col1Label=" Peak"
Col1Width= 1860
Col2Label=" Result"
Col2Width= 2445
I found the code, VBnet, Randy Birch. I would like to change this code into VBA for Access if anyone can help me couldn't find a way to contact Randy.
thanks for you help
6 21417
Im not sure what code u have but I have used this in the past successfully
Add this lot to a module -
-
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 GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
-
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
-
-
-
Private Const CONFIG_FILE = "C:\EE\DBConfig.ini"
-
-
-
Public Function GetINIString(Byval sApp as String, ByVal sKey As String) As String
-
-
Dim sBuf As String * 256
-
Dim lBuf As Long
-
-
lBuf = GetPrivateProfileString(sApp, sKey, "", sBuf, Len(sBuf), "C:\myfile.ini")
-
GetINIString= Left$(sBuf, lBuf)
-
End Function
-
-
-
Public Function WriteINI(Byval sApp as String, ByVal sKey As String, ByVal sValue As String) As String
-
WritePrivateProfileString sApp, sKey, sValue, "C:\myfile.ini"
-
End Function
-
-
then use GetINIString specifing application and key to get
i.e.
x = GetINIString("ExtraSampleInfo","User1Label")
and WriteINI to save a value
Note example for strings, should work for numbers but u can always use the other api call provided
This code should just about do it. You will need to debug It & modifiy it a little but it should be essentially correct -
Sub IpdateIniFile(UserNo As Integer, NewValue As Long)
-
-
Dim cnt As Integer
-
Dim IniLine As String
-
Dim UserID As String
-
Dim Pth As String
-
Dim TempFile As String
-
-
UserID = Trim(CStr(UserNo))
-
' replace with the path to ytour ini file
-
Pth = "Path\YourIniFile.ini"
-
TempFile = "Path\Temp.ini"
-
Open Pth For Input As #1
-
Open TempFile For Output As #2
-
Do Until EOF(1)
-
Line Input #1, IniLine
-
If Left(IniLine, 4) = "User" And Mid(IniLine, 5, Len(UserID)) = UserID And Mid(IniLine, Len(UserID) + 4, 5) = "Value " Then ' we have found the users entries
-
IniLine = "User" & UserID & "Value=" & Trim(CStr(NewValue))
-
End If
-
Print #2, IniLine
-
Loop
-
Close 1
-
Close 2
-
Kill Pth
-
Name TempFile As Pth
-
-
End Sub
-
Im not sure what code u have but I have used this in the past successfully
Add this lot to a module -
-
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 GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
-
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
-
-
-
Private Const CONFIG_FILE = "C:\EE\DBConfig.ini"
-
-
-
Public Function GetINIString(Byval sApp as String, ByVal sKey As String) As String
-
-
Dim sBuf As String * 256
-
Dim lBuf As Long
-
-
lBuf = GetPrivateProfileString(sApp, sKey, "", sBuf, Len(sBuf), "C:\myfile.ini")
-
GetINIString= Left$(sBuf, lBuf)
-
End Function
-
-
-
Public Function WriteINI(Byval sApp as String, ByVal sKey As String, ByVal sValue As String) As String
-
WritePrivateProfileString sApp, sKey, sValue, "C:\myfile.ini"
-
End Function
-
-
then use GetINIString specifing application and key to get
i.e.
x = GetINIString("ExtraSampleInfo","User1Label")
and WriteINI to save a value
Note example for strings, should work for numbers but u can always use the other api call provided
ok, this is close to the code I was looking at from Randy. But I am not understanding where to enter it. You said in a module, is that the code behind a form or in a code module?
"then use GetINIString specifing application and key to get", how do I do this?
I am still learning Access and have a long way to go. Thanks for your help.
This code should just about do it. You will need to debug It & modifiy it a little but it should be essentially correct -
Sub IpdateIniFile(UserNo As Integer, NewValue As Long)
-
-
Dim cnt As Integer
-
Dim IniLine As String
-
Dim UserID As String
-
Dim Pth As String
-
Dim TempFile As String
-
-
UserID = Trim(CStr(UserNo))
-
' replace with the path to ytour ini file
-
Pth = "Path\YourIniFile.ini"
-
TempFile = "Path\Temp.ini"
-
Open Pth For Input As #1
-
Open TempFile For Output As #2
-
Do Until EOF(1)
-
Line Input #1, IniLine
-
If Left(IniLine, 4) = "User" And Mid(IniLine, 5, Len(UserID)) = UserID And Mid(IniLine, Len(UserID) + 4, 5) = "Value " Then ' we have found the users entries
-
IniLine = "User" & UserID & "Value=" & Trim(CStr(NewValue))
-
End If
-
Print #2, IniLine
-
Loop
-
Close 1
-
Close 2
-
Kill Pth
-
Name TempFile As Pth
-
-
End Sub
-
I put this code into Visual Basic 6, changed the paths to my directories. This seems to work, but what does the Kill Pth do?
and what does the Name Tempfile as Pth do?
When I run the code the Temp.ini file disappears.
Just put the code in a normal module, dont need it in a form module.
If in a module, then all forms and other modules have access to it
Kill pth deletes the original INI file
Name Tempfile as Pth renames the output file to the INI file.
The program works by sequentially reading from the ini file & writing to a temp file, changing the rquired lines as it goes. It then deletes the original INI file and renames the temp file to the INI file.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ^CeFoS^ |
last post by:
Hello to everybody,
I've done an application that draws in a frame the trajectory of a
robot. The robot position is readed through the serial port, and
several commands are wrote through the...
|
by: lec |
last post by:
Hi,
I'm trying to write a program to read from the serial port & write
whatever that is read to the X console (/dev/tty7).
For X to recognize the characters sent, I believe you have to send...
|
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# to open a file and write to file
# do
f=open('xfile.txt','w')
# this creates a file "object" and name it f.
# the second argument of open can be
|
by: Sammy |
last post by:
Hi, my mind is going crazy. I have tried everything I can think of to
no
avail.
I have tried Disable Output Escaping.
I tried to think of a way of enclosing the attribute data in a CDATA...
|
by: Ali |
last post by:
Hi
I want to write (or read) to a stream, but the data is not byte array
I converted the data to byte array manually, but it is very slow, (becuse the data is very large)
Is another way for this...
|
by: lion |
last post by:
helo......
i need help for how to read/write file in C++
i use fstream but i wont to open file one time for all functions(file is glopal)
and i wont the file be open in the constructor of my...
|
by: KWSW |
last post by:
Got a question about reading and writing binary files.
I know that to write a value(integer) to a binary file I can use the fileoutputstream to do it.
try
{
// Create an output...
|
by: Roman Optio |
last post by:
Hi,
I am currently working on a tool to transfer addressbook data such as contacts and organizations between Vondle and Outlook.
For those of you who are wondering what Vondle is, it is an...
|
by: kimmelsd33 |
last post by:
I am using VB6. I want to read a tab delimited file, and assign each column value into a variable. If the variable is "-999.25", I want to make it a "0". I then want to reassemble the values, and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |