Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamicly write to .ini File 1

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Hi!

I'am using excel 2007, and im trying to write to an .ini file dynamicly.

And now I need sum guidance on a couple of things.

The purpose of the file is like this:

I want to be able to store new configurations, and then choose them from a dropdown.

This is my pseudo code:

First a function, that opens the file and changes an ID, this ID get incremented everytime, a new configuration is added.

Then I use append to add new configurations, the ID is taken and added to be able to identify the config, after the file is appended, ID get incremented.

Then I run a "for loop" X the times of the ID. To add the name of the configs into a dropdown.

But heres the trouble

I fetch the ID from the file

But I need to convert it to a number to be able to increment it?

I have tried:

id2 = GetPrivateProfileString32(sPath, _
"PERSONUPPGIFTER", "Fornamn")
Dim id As Integer

id = CInt(id2)

id = id + 1

but can't get it to work...

Is there a simpler way or am I doing this efficietly?

/Cheers Carl



 

When you do:
Code:
id2 = GetPrivateProfileString32(sPath, _
        "PERSONUPPGIFTER", "Fornamn")
, what's the value of id2?

Have fun.

---- Andy
 
ouchh it's be empty...
Ill have a look!
 
Got it to work!

It had no value for gods sake.. ;)

Thanks for pointing that out solutions is like this:

Dim sPath As String

'Change your directory here
sPath = "C:\Users\Marsvini\Documents\My Dropbox\Företaget\Presenta\Mall\mallar2.ini"

'Test if directory or file exists
If FileOrDirExists(sPath) Then

'reads information from the file IniFileName


id2 = GetPrivateProfileString32(sPath, _
"PERSONUPPGIFTER", "Fornamn")

Dim id As Integer

id = CInt(id2)

id = id + 1

MyFile = "C:\Users\Marsvini\Documents\My Dropbox\Företaget\Presenta\Mall\mallar2.ini"

MsgBox id

End If
'set and open file for output
fnum = FreeFile()
Open MyFile For Output As fnum



'adressenrad = Replace(TextBox12.Text, vbNewLine, "||")
'sadressenrad = Replace(TextBox13.Text, vbNewLine, "||")




'use Print when you want the string without quotation marks
Print #fnum, "[PERSONUPPGIFTER]"
Print #fnum, "Fornamn=" & id
Print #fnum, "Adress="
Print #fnum, "Sadress="
Print #fnum, "Fastighet=" & TextBox14.Text
Close #fnum

cheers!
 

I was just wondering why the code did not work, but it should. So if that would be me, I would like to know what's the value of id2 - break on the line after that and see what's in there. :)

Glad to help

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top