does VB have the capapbilities to be able to use textboxes that user can add information and then click a button and this will write a .ini file. for example can I use text boxes for the user to add their information and then this will update the .ini file
If you do a search of the forums for WritePrivateProfileString you'll find a lot of examples of writing and reading ini files. But ini files are old-fashioned. If you want to use the Registry then look at the example in my signature.
Sorry Rhinobull if you misunderstood me, what I am trying to acheive is to have a number of text boxes that the user can insert info and then have a cmd button that will add this to thi ini file - if you get me.
Just a word of caution, even though INI is old stuff and Registry is the place where information is stored now a days, you need to keep in mind following things:
1. Whether there will be multiple Windows users using your program.
2. Where to save in registry based on above.
3. All users dont have access to Write to HKLM.
4. Every user has his own HKCU, so settings become user specific here.
All this above details may not be relevent to your post 100%, but you should also consider this.
If there is 1 setting per computer, then you better save it to INI and place this INI in "All Users" folder so that everybody can write to it.
Im not too sure how that example would work. What I was hoping to do was to have all the fields required as text boxes and then when the user has entered their information they click a button and it will write/update a named ini file
I did undesrtand what you want so I sent you a sample project which instead of saving some text saves form's left/top ... What you need is to take alook at it one more time and [b]try]/b] to modify it. Other than that you have everything.
Nothing wrong with that except that you will ahve a hard time finding some particular entry and if you use few APIs instead then you'll have no problem what-so-ever.
Right I got the file writing OK using the method doofusboy explained because I understood that more. One question though is there a way that I can have a check box next to some of the text boxes so that if the field isnt required it can be hashed out.
i.e so it will originally display port=3784 and when checked this # port=3784
I have been using .ini files ever since the first time I tried to use the registry
While ini files are "out of date" I think they are the best solution because they are easy to use, and alot of programers these days just dont seem to care if their registry entries get deleted when their program is uninstalled, causing all sorts of annoyances and problems for your users computer.
That is however just my opinion.
Here is a module I have been using for the last 3 or 4 years
VB Code:
'Put this in a module
'--------for INI file read/write
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpString As String, 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
'-------------------
'reads ini string
Public Function ReadIni(filename As String, Section As String, Key As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, "", RetVal, 255, filename)
ReadIni = left(RetVal, v)
End Function
'reads ini section
Public Function ReadIniSection(filename As String, Section As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileSection(Section, RetVal, 255, filename)
ReadIniSection = left(RetVal, v - 1)
End Function
'writes ini
Public Sub WriteIni(filename As String, Section As String, Key As String, Value As String)
SaveSetting App.EXEName, "My Checkbox", "check1", Check1.Value
&
Check1.Value = GetSetting(App.EXEName, "My Checkbox", "check1", "")
???
Yes but with one small change. The 4th parameter of GetSetting is the default value that is used if VB can not find any data. That would happen for example the first time your program runs. Since you are trying to get the value for a checkbox you want to use either one of the three built-in constants for the checkbox value which are vbChecked, vbUnchecked and vbGrayed and so if you want the checkbox to be unchecked the first time the program runs your GetSetting should look like
Check1.Value = GetSetting(App.EXEName, "My Checkbox", "check1", vbUnChecked)
I need to save certian information that needs to be available to different users on the same computer such as Database type (MySQL, MS SQL etc.), the IP Address of the server etc. Would I be better off using an INI File or saving the data to the registry? Is it possible to save data into another part of the registry other than in the HKEY_CURRENT_USER|Software|VB and VBA Program Settings?
Will the module post in this LINK allow me to save and read different registry sections?
Thanks!
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
' Two lines are read, because we only want data from every other line
' Put data after '=' into textbox
Text1(i).Text = Split(read_data, "=")(1)
Wend
' Close input file
Close #1
If you write more than just textbox data to the ini file, you'd obviously need to run some sort of check to determine whether the data read is for a checkbox, textbox, or whatever and code accordingly.
Do canibals not eat clowns because they taste funny?