The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: [VB6] Read/Write Functions

  1. #1

    [VB6] Read/Write Functions

    how can i get this code:

    Code:
    Public Function ReadINI(INIpath As String, KEY As String, Variable As String) As String
    Dim NF As Integer
    Dim Temp As String
    Dim LcaseTemp As String
    Dim ReadyToRead As Boolean
        
    AssignVariables:
            NF = FreeFile
            ReadINI = ""
            KEY = "[" & LCase$(KEY) & "]"
            Variable = LCase$(Variable)
        
    EnsureFileExists:
        Open INIpath For Binary As NF
        Close NF
        SetAttr INIpath, vbArchive
        
    LoadFile:
        Open INIpath For Input As NF
        While Not EOF(NF)
        Line Input #NF, Temp
        LcaseTemp = LCase$(Temp)
        If InStr(LcaseTemp, "[") <> 0 Then ReadyToRead = False
        If LcaseTemp = KEY Then ReadyToRead = True
        If InStr(LcaseTemp, "[") = 0 And ReadyToRead = True Then
            If InStr(LcaseTemp, Variable & "=") = 1 Then
                ReadINI = Mid$(Temp, 1 + Len(Variable & "="))
                Close NF: Exit Function
                End If
            End If
        Wend
        Close NF
    End Function
    Public Function WriteINI(INIpath As String, PutKey As String, PutVariable As String, PutValue As String)
    Dim Temp As String
    Dim LcaseTemp As String
    Dim ReadKey As String
    Dim ReadVariable As String
    Dim LOKEY As Integer
    Dim HIKEY As Integer
    Dim KEYLEN As Integer
    Dim VAR As Integer
    Dim VARENDOFLINE As Integer
    Dim NF As Integer
    Dim X As Integer
    
    AssignVariables:
        NF = FreeFile
        ReadKey = vbCrLf & "[" & LCase$(PutKey) & "]" & Chr$(13)
        KEYLEN = Len(ReadKey)
        ReadVariable = Chr$(10) & LCase$(PutVariable) & "="
            
    EnsureFileExists:
        Open INIpath For Binary As NF
        Close NF
        SetAttr INIpath, vbArchive
        
    LoadFile:
        Open INIpath For Input As NF
        Temp = Input$(LOF(NF), NF)
        Temp = vbCrLf & Temp & "[]"
        Close NF
        LcaseTemp = LCase$(Temp)
        
    LogicMenu:
        LOKEY = InStr(LcaseTemp, ReadKey)
        If LOKEY = 0 Then GoTo AddKey:
        HIKEY = InStr(LOKEY + KEYLEN, LcaseTemp, "[")
        VAR = InStr(LOKEY, LcaseTemp, ReadVariable)
        If VAR > HIKEY Or VAR < LOKEY Then GoTo AddVariable:
        GoTo RenewVariable:
        
    AddKey:
            Temp = Left$(Temp, Len(Temp) - 2)
            Temp = Temp & vbCrLf & vbCrLf & "[" & PutKey & "]" & vbCrLf & PutVariable & "=" & PutValue
            GoTo TrimFinalString:
            
    AddVariable:
            Temp = Left$(Temp, Len(Temp) - 2)
            Temp = Left$(Temp, LOKEY + KEYLEN) & PutVariable & "=" & PutValue & vbCrLf & Mid$(Temp, LOKEY + KEYLEN + 1)
            GoTo TrimFinalString:
            
    RenewVariable:
            Temp = Left$(Temp, Len(Temp) - 2)
            VARENDOFLINE = InStr(VAR, Temp, Chr$(13))
            Temp = Left$(Temp, VAR) & PutVariable & "=" & PutValue & Mid$(Temp, VARENDOFLINE)
            GoTo TrimFinalString:
    
    TrimFinalString:
            Temp = Mid$(Temp, 2)
            Do Until InStr(Temp, vbCrLf & vbCrLf & vbCrLf) = 0
            Temp = Replace(Temp, vbCrLf & vbCrLf & vbCrLf, vbCrLf & vbCrLf)
            Loop
        
            Do Until Right$(Temp, 1) > Chr$(13)
            Temp = Left$(Temp, Len(Temp) - 1)
            Loop
        
            Do Until Left$(Temp, 1) > Chr$(13)
            Temp = Mid$(Temp, 2)
            Loop
        
    OutputAmendedINIFile:
            Open INIpath For Output As NF
            Print #NF, Temp
            Close NF
        
    End Function
    to read and write multiple lines? as it is it will only write a single line..

  2. #2
    I waited 2 days before saying this, and I did PM you but, you need to update your IDE to 2008... not enough people still use VB6 for your question to be answered.

    See if the #vb6 IRC channel still exists on freenode.

    (You can still use 2.0 framework that way people don't have to update their .net support)

    Join #kirupa | Click the under my Username | CL | Jeff

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012