Solved

Form to control .ini or .dat file

Posted on 1998-09-07
5
169 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now