Solved

Form to control .ini or .dat file

Posted on 1998-09-07
5
175 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:DPPro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:DPPro
ID: 1433380
Edited text of question
0
 
LVL 14

Expert Comment

by:waty
ID: 1433381
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
0
 

Author Comment

by:DPPro
ID: 1433382
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.

0
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1433383
You could use a database?

Otherwise, if you still want to use a .dat file, you can use the following function to parse each line :

dim aLine()    as String

nSgmlIn = FreeFile
Open sSgmlCurrent For Input Access Read As #nSgmlIn
sSgmlIn = ""
Do While EOF(nSgmlIn) = False
   Line Input #nSgmlIn, sTmp

   aLine = GetTokens(sTmp, "///") ' <- Here us a delimiter
   
Loop
Close #nSgmlIn



Public Function GetTokens(sToParse As String, sToken As String) As Variant
   ' *** Returns an array to tokenized values
   ' ***  Ex:  GetTokens("This is a test.", " ") = ({ "This", "is", "a", "test." })

    Dim nTokenLen       As Integer
    Dim nTokenCnt       As Integer
    Dim nOffset         As Long
    Dim nPrevOffset     As Long
    Dim aTokens()       As String

    nTokenLen = Len(sToken)
    nOffset = InStr(sToParse, sToken)
   
    Do While nOffset > 0
        ReDim Preserve aTokens(nTokenCnt)
        If nOffset - nPrevOffset > 1 Then
            aTokens(nTokenCnt) = Mid$(sToParse, nPrevOffset + 1, nOffset - 1 - nPrevOffset)
        Else
            aTokens(nTokenCnt) = ""
        End If
       
        nPrevOffset = nOffset
        nOffset = InStr(nOffset + nTokenLen, sToParse, sToken)
        nTokenCnt = nTokenCnt + 1
    Loop
   
    ReDim Preserve aTokens(nTokenCnt)
    aTokens(nTokenCnt) = Mid$(sToParse, nPrevOffset + 1)
    GetTokens = CVar(aTokens)

End Function

0
 

Author Comment

by:DPPro
ID: 1433384
That works for me...thanks and here you go.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question