Solved

Form to control .ini or .dat file

Posted on 1998-09-07
5
168 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
Comment Utility
Edited text of question
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That works for me...thanks and here you go.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now