Link to home
Start Free TrialLog in
Avatar of DPPro
DPPro

asked on

Form to control .ini or .dat file

I am going to create a .dat file or .ini file to hold information such as...
Line  cmdName    Caption     Password      Visible       Pwd

Line will be the line number
cmd Name will be the name of the command button
Caption will be a user definable caption for the command button
Password will be the password to access the shelled program
Visible will be a flag to determine if this button is visible or not.
Pwd will be a flag telling whether this button is password protected or not.

Now to keep the user from having to go in and modify the .dat file I want to create a form that the user can modify (only) these items in the columns and rows.
What is my best way of doing this task?

PS..Using VB4 16 bit
Avatar of DPPro
DPPro

ASKER

Edited text of question
You should use INI file and do the structure as follow :
[Line] = Section
cmdName=...
Caption=...    
Password=...      
Visible=...      
Pwd=...

It sill easier for you to handle it.

To finish, if you need sources to read INI filer under 16 bits, I will send them to you.

By the way, here is the code to read under 32 bits, you could convert the API to 16 bits using your API viewer :
Option Explicit

'---------------------------------------------------------------
'-INI API Declarations...
'---------------------------------------------------------------
Declare Function OSGetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Declare Function OSGetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function OSGetPrivateProfileString 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

Declare Function OSWritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Declare Function OSWritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Declare Function OSGetProfileInt Lib "kernel32" Alias "GetProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Long) As Long
Declare Function OSGetProfileSection Lib "kernel32" Alias "GetProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
Declare Function OSGetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long

Declare Function OSWriteProfileSection Lib "kernel32" Alias "WriteProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String) As Long
Declare Function OSWriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long

Private Const nBUFSIZEINI = 1024
Private Const nBUFSIZEINIALL = 4096

Public Function GetPrivateProfileString(ByVal szSection As String, ByVal szEntry As Variant, ByVal szDefault As String, ByVal szFileName As String) As String
   ' *** Get an entry in the inifile ***
   
   Dim szTmp                     As String
   Dim nRet                      As Long
   
   If (IsNull(szEntry)) Then
       ' *** Get names of all entries in the named Section ***
      szTmp = String$(nBUFSIZEINIALL, 0)
      nRet = OSGetPrivateProfileString(szSection, 0&, szDefault, szTmp, nBUFSIZEINIALL, szFileName)
   Else
       ' *** Get the value of the named Entry ***
      szTmp = String$(nBUFSIZEINI, 0)
      nRet = OSGetPrivateProfileString(szSection, CStr(szEntry), szDefault, szTmp, nBUFSIZEINI, szFileName)
   End If
   GetPrivateProfileString = Left$(szTmp, nRet)
   
End Function

Public Sub WritePrivateProfile(ByVal szSection As String, ByVal szEntry As Variant, ByVal vValue As Variant, ByVal szFileName As String)
   ' *** Write an szEntry in the inifile ***
   
   Dim nRet                      As Long

   If (IsNull(szEntry)) Then
      ' *** Delete the section ***
      nRet = OSWritePrivateProfileString(szSection, 0&, 0&, szFileName)
   ElseIf (IsNull(vValue)) Then
      ' *** Delete the entry in the section ***
      nRet = OSWritePrivateProfileString(szSection, CStr(szEntry), 0&, szFileName)
   Else
      ' *** Insert or replace the Entry ***
      nRet = OSWritePrivateProfileString(szSection, CStr(szEntry), CStr(vValue), szFileName)
   End If
   
End Sub

Public Function GetProfileString(ByVal szSection As String, ByVal szEntry As Variant, ByVal szDefault As String) As String
   ' *** Get an entry in the WIN inifile ***
   
   Dim szTmp                    As String
   Dim nRet                     As Long

   If (IsNull(szEntry)) Then
       ' *** Get names of all entries in the named Section ***
       szTmp = String$(nBUFSIZEINIALL, 0)
       nRet = OSGetProfileString(szSection, 0&, szDefault, szTmp, nBUFSIZEINIALL)
   Else
       ' *** Get the value of the named Entry ***
       szTmp = String$(nBUFSIZEINI, 0)
       nRet = OSGetProfileString(szSection, CStr(szEntry), szDefault, szTmp, nBUFSIZEINI)
   End If
   GetProfileString = Left$(szTmp, nRet)
   
End Function


Sub WriteProfile(ByVal szSection As String, ByVal szEntry As Variant, ByVal vValue As Variant)
   ' *** Write an szEntry in the WIN inifile ***
   
   Dim nRet                      As Long
   
   If (IsNull(szEntry)) Then
      ' *** Delete the section ***
       nRet = OSWriteProfileString(szSection, 0&, 0&)
   ElseIf (IsNull(vValue)) Then
      ' *** Delete the entry in the section ***
       nRet = OSWriteProfileString(szSection, CStr(szEntry), 0&)
   Else
      ' *** Insert or replace the Entry ***
       nRet = OSWriteProfileString(szSection, CStr(szEntry), CStr(vValue))
   End If
   
End Sub
Avatar of DPPro

ASKER

I really don't want to use an .ini file. There is over 100 entries with a Line, cmdName, Caption, Password ,Visible and Pwd
section for each. I also would not prefer creating a grid and populate it an .ini file. What I really want is almost a spreadsheet style .dat file that I can read the Row (or Line) numbers. But how do I read the line and column?
I am only familiar with using GetSetting & SaveSetting.

ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DPPro

ASKER

That works for me...thanks and here you go.