Just looking for some thoughts !!
Within my project there are many instances where I repeat names, telephone numbers, drive paths, folder names etc.
I'm coming to the conclusion that it's better to create an administrator form to hold this repeatable data so it can be called throughout the project.
I'm not sure whether to use an Access database table as the back end because some users don't have office installed.
How would other users go about this?
Setup Form
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Setup Form
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78626
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Setup Form
You can use an Access database in your VB6 project even if your users don't have Access. The data components needed are distributed as part of Windows nowadays.
If the amount of data is small and if you don't need security, another option would be to store the data in an .ini file (using GetPrivateProfileString and WritePrivateProfileString - see for example Accessing an .INI File [VB6]).
If the amount of data is small and if you don't need security, another option would be to store the data in an .ini file (using GetPrivateProfileString and WritePrivateProfileString - see for example Accessing an .INI File [VB6]).
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Setup Form
Using the following , I can read & write one value and populate the txtBox with the example (txtBox.text)
How would I change this to save more than one value?
example:
[Crayolas]
Color1=Blue Crayon
Color2=Red Crayon
Color3=Green Crayon
[Paints]
Paint1=Pastel
Paint2=Oil
Paint3=Water
etc
etc
So I could create the input admin form to save the values with cmdEnd and then use the values later.
I would use this code in the opening splash form which should read and savethe values for later use.
The form is the easy bit...
'Module
How would I change this to save more than one value?
example:
[Crayolas]
Color1=Blue Crayon
Color2=Red Crayon
Color3=Green Crayon
[Paints]
Paint1=Pastel
Paint2=Oil
Paint3=Water
etc
etc
So I could create the input admin form to save the values with cmdEnd and then use the values later.
I would use this code in the opening splash form which should read and savethe values for later use.
The form is the easy bit...
'Module
Code: Select all
Public Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal lpSectionName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFilename As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" _
(ByVal lpSectionName As String, _
ByVal lpKeyName As String, _
ByVal lpValue As String, _
ByVal lpFilename As String) As Long
Public Sub ProfileSaveItem(lpSectionName As String, _
lpKeyName As String, _
lpValue As String, _
lpFilename As String)
Call WritePrivateProfileString(lpSectionName, _
lpKeyName, _
lpValue, _
lpFilename)
End Sub
Code: Select all
'Form Module
Option Explicit
Dim lpSectionName As String
Dim lpKeyName As String
Dim lpValue As String
Dim lpFilename As String
Dim lpReturnedString As String
Dim nSize As Long
Private Sub cmdEnd_Click()
lpFilename = App.Path & "\myInifile.ini"
lpSectionName = "Crayolas"
lpKeyName = "Color1"
lpValue = txtBox.Text
Call ProfileSaveItem(lpSectionName, lpKeyName, lpValue, lpFilename)
End
End Sub
Private Sub Form_Load()
lpFilename = App.Path & "\myInifile.ini"
lpReturnedString = Space$(255)
nSize = Len(lpReturnedString)
nSize = GetPrivateProfileString("Crayolas", "Color1", _
" ", lpReturnedString, 50, lpFilename)
lpReturnedString = Mid(lpReturnedString, 1, nSize)
txtBox.Text = lpReturnedString
End Sub
Cheers ...
Dave.
Dave.
-
- Administrator
- Posts: 78626
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Setup Form
If you have several text boxes txtColor1 through txtColor3, you could use
Or did you mean something else?
Code: Select all
Private Sub cmdEnd_Click()
Dim lpFileName As String
Dim lpSectionName As String
Dim i As Long
lpFilename = App.Path & "\myInifile.ini"
lpSectionName = "Crayolas"
For i = 1 To 3
Call ProfileSaveItem(lpSectionName, "Color" & i, Me.Controls("txtColor" & i).Text, lpFilename)
Next i
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 1728
- Joined: 25 Jan 2010, 08:34
- Location: Stoke on Trent - Staffordshire - England
Re: Setup Form
No that's exactly what I was after.
Can't wait to start this.
Cheers Hans
Can't wait to start this.
Cheers Hans
Cheers ...
Dave.
Dave.
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: Setup Form
Of course you could also write to the registry using GetSetting and SaveSetting...