Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Environment routines (VB/VBA (used Word97SR2))

    I'm going to post a series of about a dozen VB/VBA functions. They are a rewrite of my original INI file routines.

    A few months ago, Paddock, famous for fielding queries, prompted a discussion on long (>255 char) environment strings, and at that point I abandoned my use of the PrivateProfileString functions in favour of doing my own file data extraction - I decided to read the entire file into memory and work out for myself where the sections and keys lay, the better to deal with long value strings.

    Time passes and I find myself staring at VB6 project files (*.VBP). In case you haven't seen one, here's an example:

    <pre>
    Type=OleDll
    Reference=*G{00020430-0000-0000-C000-000000000046}#2.0#0#C:WINDOWSSYSTEMstdole2.tlb#OLE Automation
    Class=WinDevice; WinDevice.cls
    Startup="(None)"
    HelpFile=""
    ...(snip)...
    MaxNumberOfThreads=1
    ThreadingModel=1
    RemoveUnusedControlInfo=0
    DebugStartupOption=0

    [MS Transaction Server]
    AutoRefresh=1
    </pre>


    Looks very much like an INI file, doesn't it?

    There's the abscence of a leading section header, but. I would need to be able to cope with null section names, as well as non-existent section names.


    Consider also a CONFIG.SYS file:
    <pre>

    [menu]
    menuitem=CD, Start computer with CD-ROM support.
    menuitem=NOCD, Start computer without CD-ROM support.
    menuitem=HELP, View the Help file.
    menudefault=CD,30
    menucolor=7,0

    [CD]
    device=himem.sys /testmemff
    device=oakcdrom.sys /D:mscd001
    device=btdosm.sys
    device=flashpt.sys
    device=btcdrom.sys /D:mscd001
    device=aspi2dos.sys
    device=aspi8dos.sys
    device=aspi4dos.sys
    device=aspi8u2.sys
    device=aspicd.sys /D:mscd001

    [NOCD]
    device=himem.sys /testmemff

    <img src=/S/help.gif border=0 alt=help width=23 height=15>
    device=himem.sys /testmemff

    [COMMON]
    files=10
    buffers=10
    dos=high,umb
    stacks=9,256
    devicehigh=ramdrive.sys /E 2048
    lastdrive=z

    </pre>



    Hmmm! makes you think, eh?


    Last but not least (and don't try this at home, kids)

    <pre>
    [Paths]
    WinDir=C:WINDOWS
    WinBootDir=C:WINDOWS
    HostWinBootDrv=C

    [Options]
    BootMulti=1
    BootGUI=1
    DoubleBuffer=1
    AutoScan=1
    WinVer=4.10.2222
    ;
    ;The following lines are required for compatibility with other programs.
    ;Do not remove them (MSDOS.SYS needs to be >1024 bytes).
    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxa
    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxb
    ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxc
    </pre>




    So, these new Environment routines (they aren't INI routines any more) ought to be able to deal with a host of automated tasks.

    If you're a WordVBA programmer, you ought now be able to develop a little application that can rip through 2,000 VBP files and standardise the descriptions, versions, or collect data on what DLL and other objects are required for completion.

    If you're a Windows programmer, you ought to be able toi chip away at an unprotected copy of MSDos.SYS to your little heart's content.

    Or you can just write WordVBA application faster, with INI files and you can assure your users that you don't mess with the registry files at all, at all!

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    This general-purpose routine simplifies the WordVBA developer's task of using files.

    If you don't supply a file name, we will use the application name (in my examples strcApplication="Envir").

    If you don't supply an extent, we'll append ".INI".

    If you don't supply a path, we'll use the template application's path.

    As with nearly all my functions, you can drag the commented test section past the end of the function, decomment the test and run it, to see how it all works.



    <pre>Public Function strBuildEnvFile(strFile As String) As String
    ' Procedure : strBuildEnvFile
    ' Description: Build a useable absolute file name with path and extent.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: string.
    ' Returns: STRING.
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By the calls shown below.
    ' Posted
    Dim strResult As String
    strResult = strFile
    ' If null, use the global constant strcApplication
    If strResult = "" Then
    strResult = strcApplication
    Else
    End If
    ' If no extent, use .INI
    ' Win9x introduces multiple periods in file/folder names
    ' We test for a period in the rightmost 4 characters of the name
    If InStr(1, String$(4, " ") & Right$(strResult, 4), ".") > 0 Then ' found a period
    Else
    strResult = strResult & ".INI"
    End If
    ' If no path, use the template path.
    ' We test for a separator or a colon in the name
    If InStr(1, strResult, Application.PathSeparator) > 0 Then ' found a slash
    Else
    If InStr(1, strResult, ":") > 0 Then ' found a colon
    Else
    strResult = MacroContainer.Path & Application.PathSeparator & strResult
    End If
    End If
    ' Return the result
    strBuildEnvFile = strResult
    'Sub TESTstrBuildEnvFile()
    'MsgBox strBuildEnvFile("")
    'MsgBox strBuildEnvFile("eraseme")
    'MsgBox strBuildEnvFile("eraseme.ini")
    'MsgBox strBuildEnvFile("eraseme.txt")
    'MsgBox strBuildEnvFile("c:temperaseme.txt")
    'MsgBox strBuildEnvFile("a")
    'MsgBox strBuildEnvFile("c:eraseme")
    'MsgBox strBuildEnvFile("c:eraseme.ini")
    'MsgBox strBuildEnvFile("c:eraseme.txt")
    'End Sub
    End Function
    </pre>


  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    Given a file name (you may want to make use of StrBuildEnvFile), this function returns the contents of that file as a string result.



    <pre>Public Function strGetFileData(strFile As String) As String
    ' Procedure : strGetFileData
    ' Description: Get a file of Environment data.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: String file name.
    ' Returns: STRING.
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By the calls shown below.
    ' Posted
    ' The strGetFileData asks if the value is there.
    ' If so, return the value,
    ' The returned string will be AT LEAST a CR/LF character

    ' Build a useable absolute file name with path and extent
    Dim strFullFile As String
    strFullFile = strBuildEnvFile(strFile)

    ' Open the file, get the data.
    Dim intFile As Integer
    intFile = FreeFile
    Open strFullFile For Binary As #intFile
    Dim lngLengthFile As Long
    lngLengthFile = LOF(intFile)
    Dim strFileData As String
    strFileData = String$(lngLengthFile, " ") ' create buffer for GET routine
    Get #intFile, 1, strFileData

    ' If the returned string is empty, there was no environment data; make some
    If Len(strFileData) = 0 Then
    strFileData = vbCrLf
    Else
    If Left$(strFileData, Len(vbCrLf)) = vbCrLf Then
    Else
    strFileData = vbCrLf & strFileData
    End If
    End If

    ' Close the file
    Close intFile

    ' Make sure that the string is terminated by at least one vbCRLF
    If Right$(strFileData, 2) <> vbCrLf Then
    strFileData = strFileData & vbCrLf
    Else
    End If
    strGetFileData = strFileData

    'Sub TESTstrGetEnv()
    '' MsgBox strGetEnv("", "", "1", "a")
    ' Dim strFileData As String
    ' strFileData = strGetFileData("frogram filesinstallshieldprogramfuncwiz.ini", "", "1", "a")
    ' Dim l1 As Long, l2 As Long, l3 As Long
    ' MsgBox strGetSectionData(strFileData, "FuncWiz - Category - Batch file", l1, l2, l3)
    ' MsgBox strGetSectionData(strFileData, "greaves", l1, l2, l3)
    '
    'End Sub

    End Function
    </pre>


  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    Given a file name (you may want to make use of StrBuildEnvFile), this function returns the contents of that file as a string result.

    I haven't tested this for the maximum length of file string that can be received.


    <pre>Public Function strGetFileData(strFile As String) As String
    ' Procedure : strGetFileData
    ' Description: Get a file of Environment data.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: String file name.
    ' Returns: STRING.
    ' Assumes: Nothing
    ' Side Effects: None.
    ' Tested: By the calls shown below.
    ' Posted
    ' The strGetFileData asks if the value is there.
    ' If so, return the value,
    ' The returned string will be AT LEAST a CR/LF character

    ' Build a useable absolute file name with path and extent
    Dim strFullFile As String
    strFullFile = strBuildEnvFile(strFile)

    ' Open the file, get the data.
    Dim intFile As Integer
    intFile = FreeFile
    Open strFullFile For Binary As #intFile
    Dim lngLengthFile As Long
    lngLengthFile = LOF(intFile)
    Dim strFileData As String
    strFileData = String$(lngLengthFile, " ") ' create buffer for GET routine
    Get #intFile, 1, strFileData

    ' If the returned string is empty, there was no environment data; make some
    If Len(strFileData) = 0 Then
    strFileData = vbCrLf
    Else
    If Left$(strFileData, Len(vbCrLf)) = vbCrLf Then
    Else
    strFileData = vbCrLf & strFileData
    End If
    End If

    ' Close the file
    Close intFile

    ' Make sure that the string is terminated by at least one vbCRLF
    If Right$(strFileData, 2) <> vbCrLf Then
    strFileData = strFileData & vbCrLf
    Else
    End If
    strGetFileData = strFileData

    'Sub TESTstrGetEnv()
    '' MsgBox strGetEnv("", "", "1", "a")
    ' Dim strFileData As String
    ' strFileData = strGetFileData("frogram filesinstallshieldprogramfuncwiz.ini", "", "1", "a")
    ' Dim l1 As Long, l2 As Long, l3 As Long
    ' MsgBox strGetSectionData(strFileData, "FuncWiz - Category - Batch file", l1, l2, l3)
    ' MsgBox strGetSectionData(strFileData, "greaves", l1, l2, l3)
    '
    'End Sub

    End Function
    </pre>


  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    (Feb 2nd 2002: The routines which follow are already in the process of being superseded by CLASS examples. I'll continue the posts for those who don't like/don't want to play with classes. All the code will appear in a downloadable template at the end of the series of postings)



    This is a slave function; it will be called repeatedly by the strGetSectionData function (later!).

    Repeated calls to strGetNextSection chew along a string of file data, looking for the ubiquitous "[section name]" strings.

    If the section is not found, the three pointers that define the section are set to zero.


    <pre>Public Function strGetNextSection(strFileData, lngStart As Long, _
    lngSectionHeaderStart As Long, lngSectionHeaderEnd As Long, lngSectionEnd As Long) As String
    ' Given a string and a starting position
    ' determine the 3 pointers for the next section
    ' return the found section name.

    ' We define a section by:
    ' 1) the pointer to the "[" of the section header
    ' 2) the pointer to the "]" of the section header
    ' 3) The pointer to the character preceding the next section header

    ' A section is a string bounded at the left-hand end by a vbCRLF&"[",
    ' with a "]"&vbCRLF without an intervening vbCRLF
    ' and bounded at the right-hand end by the next vbCRLF&"[" or the end of string

    ' It is the responsibility of the calling procedure to ensure that the data string is
    ' terminated by at least one vbCRLF,

    ' Default result is "not found", all three pointers set to zero.
    ' Zero is an impossible location in a string; the first character for MID$ is character 1.
    lngSectionHeaderStart = 0
    lngSectionHeaderEnd = lngSectionHeaderStart
    lngSectionEnd = lngSectionHeaderStart

    ' Default result is "no name found", which may mean an unamed section.
    strGetNextSection = ""

    ' Look for the next vbCRLF&"["
    lngSectionHeaderStart = InStr(lngStart, strFileData, strcSectionHeaderStart)
    If lngSectionHeaderStart = 0 Then ' Not Found; no more section headers
    lngSectionHeaderEnd = lngSectionHeaderStart
    lngSectionEnd = lngSectionHeaderStart
    Else
    lngSectionHeaderStart = lngSectionHeaderStart + 2

    ' Look for the next "]"&vbcrlf
    lngSectionHeaderEnd = InStr(lngSectionHeaderStart, strFileData, strcSectionHeaderEnd)
    If lngSectionHeaderEnd = 0 Then ' Not found; no more section headers
    lngSectionHeaderStart = lngSectionHeaderEnd
    lngSectionEnd = lngSectionHeaderStart
    Else

    ' Was there an intervening vbCRLF, in which case this was not a genuine header
    If InStr(lngSectionHeaderStart, Mid$(strFileData, lngSectionHeaderEnd, _
    lngSectionHeaderEnd - lngSectionHeaderStart - 1), vbCrLf) > 0 Then

    ' Yes there was. We choose not to cope with this in the current version.
    lngSectionHeaderStart = 0
    lngSectionHeaderEnd = lngSectionHeaderStart
    lngSectionEnd = lngSectionHeaderStart
    Else

    ' Look for the next vbCRLF&"[" after the section header
    lngSectionEnd = InStr(lngSectionHeaderEnd, strFileData, strcSectionHeaderStart)
    If lngSectionEnd = 0 Then ' Not Found; use the end-of-string address
    lngSectionEnd = Len(strFileData)
    strGetNextSection = Mid$(strFileData, lngSectionHeaderStart + 1, _
    lngSectionHeaderEnd - lngSectionHeaderStart - 1)
    Else
    lngSectionEnd = lngSectionEnd - 1
    strGetNextSection = Mid$(strFileData, lngSectionHeaderStart + 1, _
    lngSectionHeaderEnd - lngSectionHeaderStart - 1)
    End If
    End If
    End If
    'Sub TESTstrGetNextSection()
    'Dim lng1 As Long, lng2 As Long, lng3 As Long, lng4 As Long
    'Dim strFileData As String
    '
    '' FIRST SET OF TESTS
    '
    '' Use this string for the basic "empty" test
    'strFileData = " " & vbCrLf
    'lng1 = 1
    'MsgBox strGetNextSection(strFileData, lng1, lng2, lng3, lng4)
    'MsgBox lng1 & " " & lng2 & " " & lng3 & " " & lng4
    '
    '' SECOND SET OF TESTS
    '
    '' Use this string for the elementary "find fist section" test
    'strFileData = vbCrLf & "[a]" & vbCrLf & "kjk" & vbCrLf & "[b]" & vbCrLf
    'lng1 = 1
    'MsgBox strGetNextSection(strFileData, lng1, lng2, lng3, lng4)
    'MsgBox lng1 & " " & lng2 & " " & lng3 & " " & lng4
    '
    '' THIRD SET OF TESTS
    '
    '' Use this string for repeated calls to the routine
    'strFileData = vbCrLf & "[a]" & vbCrLf & "123" & vbCrLf & "[b]" &_
    vbCrLf & "456" & vbCrLf & "[c]" & vbCrLf
    'lng1 = 1
    '' First call, locate section "a"
    'MsgBox strGetNextSection(strFileData, lng1, lng2, lng3, lng4)
    'MsgBox lng1 & " " & lng2 & " " & lng3 & " " & lng4
    '' Now advance the starting position and look for section "b"
    'lng1 = lng4 + 1
    'MsgBox strGetNextSection(strFileData, lng1, lng2, lng3, lng4)
    'MsgBox lng1 & " " & lng2 & " " & lng3 & " " & lng4
    '' Now advance the starting position and look for the next section, if any.
    'lng1 = lng4 + 1
    'MsgBox strGetNextSection(strFileData, lng1, lng2, lng3, lng4)
    'MsgBox lng1 & " " & lng2 & " " & lng3 & " " & lng4
    'End Sub
    '
    End If
    End Function

    </pre>


  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    This function attempts to locate the substring data of a section within a string of file data.

    Remember that an environment file is a string of data. The file is a series of sections, each section is a string of data (hiya Brooke!)



    <pre>Public Function strGetSectionData(strFileData As String, strSectionName As String,_
    lngSectionHeaderStart As Long, lngSectionHeaderEnd As Long, lngSectionEnd As Long) As String
    ' Given a string and a (possily null) section name
    ' determine the 3 pointers for the named section
    ' return the section string.

    ' If the section name is null, return the string BEFORE the first section header.
    ' In this case, the section string starts at character position "1".

    ' 2002/1/25 better:
    ' If the section is not found, return pointers of zero (L1=L2=L3=zero)

    ' The caller then makes the decision:
    ' If name is null, build section at head of file
    ' If name is not null, build section at tail of file.

    If strSectionName = "" Then
    Dim strResult As String
    strResult = strGetNextSection(strFileData, 1, lngSectionHeaderStart, _
    lngSectionHeaderEnd, lngSectionEnd)
    If strResult = "" Then ' No section header; use entire string
    strResult = strFileData
    lngSectionHeaderStart = 1
    lngSectionHeaderEnd = Len(strFileData)
    lngSectionEnd = Len(strFileData)
    Else
    lngSectionEnd = lngSectionHeaderStart - 1
    lngSectionHeaderStart = 1
    lngSectionHeaderEnd = lngSectionHeaderStart
    End If
    Else

    ' If the section name is NOT NULL, loop along the string, looking for the section

    Dim strName As String
    Dim lng1 As Long
    lng1 = 1
    strName = strGetNextSection(strFileData, lng1, lngSectionHeaderStart, _
    lngSectionHeaderEnd, lngSectionEnd)
    Do While strName <> ""
    If strName = strSectionName Then ' We have found the section
    strResult = Mid$(strFileData, lngSectionHeaderStart, _
    lngSectionEnd - lngSectionHeaderStart + 1)
    Exit Do
    Else
    lng1 = lngSectionEnd + 1
    strName = strGetNextSection(strFileData, lng1, lngSectionHeaderStart, _
    lngSectionHeaderEnd, lngSectionEnd)
    End If
    Loop
    End If

    ' If the section name was not found, we will have to fabricate it ourselves back in the calling module

    If strSectionName <> "" And strName = "" Then ' named section was not found
    strName = ""
    lngSectionHeaderStart = 0
    lngSectionEnd = lngSectionHeaderStart
    lngSectionHeaderEnd = lngSectionHeaderStart
    Else
    strGetSectionData = strName
    End If

    'strGetSectionData = "liyghlyg"
    'Sub TESTstrGetSectionData()
    'Dim lng1 As Long, lng2 As Long, lng3 As Long, lng4 As Long
    'Dim strFileData As String
    'Dim strSectionName As String
    '
    '' Use this string for repeated calls to the routine
    'strFileData = vbCrLf & "[a]" & vbCrLf & "1" & vbCrLf _
    & "[b]" & vbCrLf & "456" & vbCrLf & "[c]" & vbCrLf
    'strSectionName = "d"
    '
    'MsgBox strGetSectionData(strFileData, strSectionName, lng1, lng2, lng3)
    'End Sub
    End Function
    </pre>


  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    By this point, if we have extracted a substring (of the file) in the form of a string of section data, we ought to be able to extrcat a smaller substring representing a key (the key identifier, the equals sign, and the key value).



    <pre>Public Function strGetKeyData(strSectionData As String, strKeyname As String,_
    lngStartKeyName As Long, lngStartKeyData As Long, lngEndKeyData As Long) As String
    ' Given a string and a non-null key name, return the value of that key.

    ' A key identifier is a vbCRLF followed by an identifier, followed by an equal sign.

    ' A key value is the string following a key identifier and terminated by a vbCRLF

    ' Method: Find all occurrences of cbCRLF & key-name
    ' Trim the remainder.
    ' If the leftmost char is "="
    ' Then the remainder up to the next vbCRLF or (end-of-string) is the key value.

    Dim lngStart As Long ' current starting position for the next search
    lngStart = 1
    Dim lngPos As Long ' Position of the current essay
    lngPos = InStr(lngStart, strSectionData, vbCrLf & strKeyname)
    Do While lngPos > 0
    lngStartKeyName = lngPos + 2

    ' lngPos represents an occurrence of the leading part of the key name
    ' Is it followed by an equals sign

    lngPos = lngPos + 2 + Len(strKeyname)
    While Mid$(strSectionData, lngPos, 1) = " "
    lngPos = lngPos + 1
    Wend
    If Mid$(strSectionData, lngPos, 1) = "=" Then ' we have found the key name
    lngStartKeyData = lngPos + 1
    lngEndKeyData = InStr(lngPos, strSectionData, vbCrLf) + 1
    If lngEndKeyData = 1 Then
    lngEndKeyData = Len(strSectionData)
    Else
    End If
    Exit Do
    Else
    End If
    lngPos = InStr(lngPos, strSectionData, vbCrLf & strKeyname)
    Loop

    ' Generate the found name as a string result

    If lngStartKeyName > 0 Then
    strGetKeyData = Mid$(strSectionData, lngStartKeyName, _
    lngStartKeyData - lngStartKeyName - 1)
    Else
    strGetKeyData = ""
    End If
    'Sub TESTstrGetKeyData()
    '
    ' ' Obtain the string data from that file
    ' Dim strFileData As String
    ' strFileData = strGetFileData("c:windowsnetdet.ini")
    '
    ' ' Obtain the section data
    ' Dim lngStartSectionName As Long, lngStartSectionData As Long, _
    lngEndSectionData As Long
    ' Dim strSectionData As String
    ' Call strGetSectionData(strFileData, "IPXMONO", lngStartSectionName, _
    lngStartSectionData, lngEndSectionData)
    ' strSectionData = Mid$(strFileData, lngStartSectionName, lngEndSectionData_
    - lngStartSectionName + 1)
    '
    ' Dim lngStartKeyName As Long, lngStartKeyData As Long, _
    lngEndKeyData As Long
    ' MsgBox strGetKeyData(strSectionData, "detection0", lngStartKeyName, _
    lngStartKeyData, lngEndKeyData)
    ' If lngStartKeyName > 0 Then
    ' MsgBox Mid$(strSectionData, lngStartKeyName, lngEndKeyData _
    - lngStartKeyName + 1)
    ' Else
    ' End If
    'End Sub
    End Function

    </pre>


  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    This is a no-brainer. It is a cover function for the generation of a key string (identifier, equals, value)


    <pre>Public Function strCreateKeyString(strKeyname As String, strKeyValue As String) As String
    strCreateKeyString = strKeyname & strcKeySeparator & strKeyValue & vbCrLf
    'Sub TESTstrCreateKeyString()
    'MsgBox strCreateKeyString("1", "$")
    'End Sub
    End Function
    </pre>


  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    This is close to a no-brainer, and could be a general-purpose routine for a string-replacement library.

    Given an original string, pointers to a string to be replaced, and a new string, splice the new string into the place of the old string.


    <pre>Public Function strReBuildSectionString(strSectionData As String, lngStartKeyName As Long,_
    lngStartKeyData As Long, lngEndKeyData As Long, strKeyData As String) As String
    Dim strResult As String
    strResult = Left$(strSectionData, lngStartKeyName - 1)
    strResult = strResult & strKeyData
    strResult = strResult & Right$(strSectionData, Len(strSectionData) - lngEndKeyData)
    strReBuildSectionString = strResult
    'Sub TESTstrReBuildSectionString()
    'MsgBox strReBuildSectionString("1234567890", 2, 5, 8, "@#$")
    'End Sub
    End Function
    </pre>


  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Environment routines (VB/VBA (used Word97SR2))

    Or you could upgrade to Office 2000 or XP and simply use the Replace() function. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    >Or you could upgrade

    What?!!! And lose my status as the cheapest cheepin' chicken this side of the fence?


    Charlotte , Thanks for the response.

    Since my Word macros started with recorded commands from Word6, I still forget, in Word97/VBA, to see if there is an in-built function to do what I want. My origins (OK, so I'm no chicken!) also steer me towards doing everything myself, even holding up the cards so's I can read the holes.

    Thanks also. Someone is reading this stuff. Sad to relate I feel it's a bit of a waste of time, because after I'd made the second posting, I rewrote everything as class objects, so the functions posted here (about 10 in total) are largely out of date now.

    Are you interested in a CLASSy version of these routines?

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Environment routines (VB/VBA (used Word97SR2))

    I rarely use Word as a platform, and I try to use the latest built-ins rather than finding workarounds, but thanks for the offer. If I ever need some Word classes, I'll knock on your door. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

  13. #13
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    At least you are not scared to do it yourself!

    And Charlotte isn't the olny one reading it!

    I take it that most of the code can be ported and used as is in Access 2000 or Excel 2000?

    And I would be interested in seeing the new CLASSy versions of this as well!

    James

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    >At least you are not scared to do it yourself!

    Scared? I've not been scared since I thought I'd broken the $250,000 ($AUS1967) PDP-6 computer. Turned out it just needed to be re-booted, but i was really ignorant back then .....


    >And Charlotte isn't the olny one reading it!

    This is good news for Charlotte, as well as for me (grin)



    > I take it that most of the code can be ported and used as is in Access 2000 or Excel 2000?

    It ought all be portable, not only to other Office Aps, but to VB6, as well. Except that I still refer to "Documents" in my DoQKill routine (and have since rewritten it anyway) the whole things is document independant.

    My plan was to release and test these routines, then produce a VB6 version and hence a DLL so that users could obtain the DLL and do wonderful things with INI and INI-like files (VBP, SYS etc)

    Since then my experience with classes has caused me to re-write the stuff, so I'll probably finish this series of about 12 posts, then pause and release the Class-version in toto as a Word97.template, that any Lounger can use, and build the VB6 versions with the attendant DLL.

    It was always my intention, the foray into Word97/VBA, to use it as a stepping-stone to VB6. I got side-tracked along the way.



    Yesterday I gave my testbed the name of a VBP and it dutifully produced a tree-structure of modules which needed to be re-compiled because of a change in the original VBP code (attached)
    Attached Files Attached Files

  15. #15
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Environment routines (VB/VBA (used Word97SR2))

    If you think this looks like "strReBuildSectionString" you're right. There's not much difference between the two.

    Both functions are aimed at splicing a new value into an existing string.



    <pre>Public Function strReBuildFileString(strFileData As String, lngStartSectionName As Long,_
    lngStartSectionData As Long, lngEndSectionData As Long, strSectionData As String) As String
    Dim strResult As String
    If lngStartSectionName = 0 Then ' Create the section
    strResult = strFileData & strSectionData
    Else
    strResult = Left$(strFileData, lngStartSectionName - 1) ' replaced 2002/1/27
    strResult = strResult & strSectionData
    strResult = strResult & Right$(strFileData, Len(strFileData) - lngEndSectionData)
    End If
    strReBuildFileString = strResult
    'Sub TESTstrReBuildFileString()
    'MsgBox strReBuildFileString("1234567890", 2, 5, 8, "@#$")
    'End Sub
    End Function
    </pre>


Page 1 of 2 12 LastLast

Posting Permissions

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