locked
Test Code Options in New Forum Editor RRS feed

  • Question

  • Following is text in a Code Insert Block:

    20 characters long
    all upper case letters                        26
    all lower case letters                        26
    all digits                                    10
    symbols: !@#$%^&*()-_=+`~[{]}\|;:'",<.>/?     41
    12345678901234567890123456789012345678901
             1         2         3         4
                                                 103
    

    Following is VBScript in a Code Insert Block (language VB.NET):

    Const ForReading = 1
    
    ' Specify the file name.
    strFile = "\\MyServer\MyShare\DriveMappings.txt"
    
    ' Open the file for reading.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)
    
    ' Read the file.
    Do Until objFile.AtEndOfStream
        strLine = Trim(objFile.ReadLine)
        If (strLine <> "") Then
            arrValues = Split(strLine, ",")
            If (UBound(arrValues) = 2) Then
                If IsMember(arrValues(0) Then
                    objNetwork.MapNetworkDrive arrValues(1), arrValues(2)
                End If
            End If
        End If
    Loop
    
    ' Clean up.
    objFile.Close

    Following is PowerShell in a Code Insert Block (language PowerShell):

    Get-ChildItem $root | Where-Object {$_.PSIsContainer} | ForEach-Object {
        # get the oldest file for the current directory object
        $oldest = Get-ChildItem $_.FullName -Recurse | Where-Object {-not $_.PSIsContainer} `
            | Sort-Object LastWriteTime | Select-Object LastWriteTime -First 1
    
        If($oldest)
        {
            # oldest object found, set current directory LastWriteTime
            $_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime
            $_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
        }
        Else
        {
            # current directory is empty, directory LastWriteTime is left unchanged
            Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
        }
    }

    Following is the same text as in the first block, but entered using the Insert HTML feature (with CodeToHtml.vbs recently revised):

    20 characters long
    all upper case letters 26
    all lower case letters 26
    all digits 10
    symbols: !@#$%^&*()-_=+`~[{]}\|;:'",<.>/? 41
    12345678901234567890123456789012345678901
             1 2 3 4
                                                 103

    -----

    Following is the same VBScript program, but using Insert HTML (with VbsToHTML.vbs recently revised):

    Const ForReading = 1

    ' Specify the file name.
    strFile = "\\MyServer\MyShare\DriveMappings.txt"

    ' Open the file for reading.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)

    ' Read the file.
    Do Until objFile.AtEndOfStream
        strLine = Trim(objFile.ReadLine)
        If (strLine <> "") Then
            arrValues = Split(strLine, ",")
            If (UBound(arrValues) = 2) Then
                If IsMember(arrValues(0) Then
                    objNetwork.MapNetworkDrive arrValues(1), arrValues(2)
                End If
            End If
        End If
    Loop

    ' Clean up.
    objFile.Close

    -----

    Following is the PowerShell script, using Insert HTML (with PsToHTML.vbs recently revised):

    Get-ChildItem $root | Where-Object {$_.PSIsContainer} | ForEach-Object {
        # get the oldest file for the current directory object
        $oldest = Get-ChildItem $_.FullName -Recurse | Where-Object {-not $_.PSIsContainer} `
            | Sort-Object LastWriteTime | Select-Object LastWriteTime -First 1

        If($oldest)
        {
            # oldest object found, set current directory LastWriteTime
            $_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime
            $_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
        }
        Else
        {
            # current directory is empty, directory LastWriteTime is left unchanged
            Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
        }
    }

    -----

    End of reply.


    Richard Mueller - MVP Directory Services

    Tuesday, February 7, 2012 11:45 PM

All replies

  • Test modified programs to convert code to HTML. First, CodeToHtml.vbs:

    20 characters long
    all upper case letters                        26
    all lower case letters                        26
    all digits                                    10
    symbols: !@#$%^&*()-_=+`~[{]}\|;:'",<.>/?     41
    12345678901234567890123456789012345678901
             1         2         3         4
                                                 103

    -----

    Next, VbsToHtml.vbs:

    Const ForReading = 1

    ' Specify the file name.
    strFile = "\\MyServer\MyShare\DriveMappings.txt"

    ' Open the file for reading.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)

    ' Read the file.
    Do Until objFile.AtEndOfStream
        strLine = Trim(objFile.ReadLine)
        If (strLine <> "") Then
            arrValues = Split(strLine, ",")
            If (UBound(arrValues) = 2) Then
                If IsMember(arrValues(0) Then
                    objNetwork.MapNetworkDrive arrValues(1), arrValues(2)
                End If
            End If
        End If
    Loop

    ' Clean up.
    objFile.Close

    -----

    And finally PsToHtml.vbs:

    Get-ChildItem $root | Where-Object {$_.PSIsContainer} | ForEach-Object {
        # get the oldest file for the current directory object
        $oldest = Get-ChildItem $_.FullName -Recurse | Where-Object {-not $_.PSIsContainer} `
            | Sort-Object LastWriteTime | Select-Object LastWriteTime -First 1

        If($oldest)
        {
            # oldest object found, set current directory LastWriteTime
            $_ | Set-ItemProperty -Name CreationTime -Value $oldest.LastWriteTime
            $_ | Set-ItemProperty -Name LastWriteTime -Value $oldest.LastWriteTime
        }
        Else
        {
            # current directory is empty, directory LastWriteTime is left unchanged
            Write-Warning "Directory '$($_.FullName)' is empty, skiping..."
        }
    }

    -----

    I notice now, after the 02/12/2012 update, that code inserting using the Insert Code Block feature uses a fixed width font. This is a test of the "edit" feature to see if I can enter a reason. I find that I cannot. Wait, now I see I can enter a reason if I tab in the the reason field.


    Richard Mueller - MVP Directory Services


    • Edited by Richard MuellerMVP Tuesday, February 14, 2012 7:13 PM Finally able to enter a reason by tabibing into this field.
    Wednesday, February 8, 2012 4:07 AM
  • PowerShell example using Insert Code Block:

    $data = foreach ($b in (Get-WmiObject Win32_Share)){$b | get-acl -ea SilentlyContinue | `
        select @{n='Share';e={$b.name}},owner,accesstostring}
    $data | ConvertTo-Html | Out-File 'ACLReport.html'
    Invoke-Item 'ACLReport.html'

    Same snippet using Insert HTML and revised PsToHtml.vbs

    $data = foreach ($b in (Get-WmiObject Win32_Share)){$b | get-acl -ea SilentlyContinue | `
        select @{n='Share';e={$b.name}},owner,accesstostring}
    $data | ConvertTo-Html | Out-File 'ACLReport.html'
    Invoke-Item 'ACLReport.html'

    -----



    Richard Mueller - MVP Directory Services

    Friday, February 10, 2012 10:51 PM
  • Code with very long lines to test wrapping vs. scroll bars. First using InsertCodeBlock:

    Option Explicit
    
    Dim strValue, intLen
    Dim arrWords, strVariableWithOneWord, strVariableWithWrappedOutput, strVariableWithContentsOfLine
    
    strValue = "This is a long string for test purposes to see if we can get word wrapping to work properly in this environment in answer to a newsgroup question."
    ' strValue = "This is a short string"
    
    arrWords = Split(strValue, " ")
    
    strVariableWithWrappedOutput = ""
    strVariableWithContentsOfLine = ""
    For Each strVariableWithOneWord In arrWords
        If (Len(strVariableWithContentsOfLine & strVariableWithOneWord) > 30) Then
            If (strVariableWithWrappedOutput = "") Then
                strVariableWithWrappedOutput = strVariableWithContentsOfLine
            Else
                strVariableWithWrappedOutput = strVariableWithWrappedOutput & vbCrLf & strVariableWithContentsOfLine
            End If
            strVariableWithContentsOfLine = ""
        End If
        If (strVariableWithContentsOfLine = "") Then
            strVariableWithContentsOfLine = strVariableWithOneWord
        Else
            strVariableWithContentsOfLine = strVariableWithContentsOfLine & " " & strVariableWithOneWord
        End If
    Next
    
    If (strVariableWithContentsOfLine <> "") Then
        If (strVariableWithWrappedOutput = "") Then
            strVariableWithWrappedOutput = strVariableWithContentsOfLine
        Else
            strVariableWithWrappedOutput = strVariableWithWrappedOutput & vbCrLf & strVariableWithContentsOfLine
        End If
    End If
    
    Wscript.Echo strVariableWithWrappedOutput

    Next, using Insert HTML and VbsToHtml.vbs:

    Option Explicit

    Dim strValue, intLen
    Dim arrWords, strVariableWithOneWord, strVariableWithWrappedOutput, strVariableWithContentsOfLine

    strValue = "This is a long string for test purposes to see if we can get word wrapping to work properly in this environment in answer to a newsgroup question."
    ' strValue = "This is a short string"

    arrWords = Split(strValue, " ")

    strVariableWithWrappedOutput = ""
    strVariableWithContentsOfLine = ""
    For Each strVariableWithOneWord In arrWords
        If (Len(strVariableWithContentsOfLine & strVariableWithOneWord) > 30) Then
            If (strVariableWithWrappedOutput = "") Then
                strVariableWithWrappedOutput = strVariableWithContentsOfLine
            Else
                strVariableWithWrappedOutput = strVariableWithWrappedOutput & vbCrLf & strVariableWithContentsOfLine
            End If
            strVariableWithContentsOfLine = ""
        End If
        If (strVariableWithContentsOfLine = "") Then
            strVariableWithContentsOfLine = strVariableWithOneWord
        Else
            strVariableWithContentsOfLine = strVariableWithContentsOfLine & " " & strVariableWithOneWord
        End If
    Next

    If (strVariableWithContentsOfLine <> "") Then
        If (strVariableWithWrappedOutput = "") Then
            strVariableWithWrappedOutput = strVariableWithContentsOfLine
        Else
            strVariableWithWrappedOutput = strVariableWithWrappedOutput & vbCrLf & strVariableWithContentsOfLine
        End If
    End If

    Wscript.Echo strVariableWithWrappedOutput

    -----



    Richard Mueller - MVP Directory Services

    Sunday, February 12, 2012 9:52 PM
  • I guess longer lines are needed. First, Insert Code Block:

    Option Explicit
    
    Dim strValue, intLen
    Dim arrWords, strVariableWithOneWord, strVariableWithWrappedOutput, strVariableWithContentsOfLine
    
    strValue = "This is a very, very, very long string to force word wrapping (or code editor scroll bars) for test purposes to see if we can get word wrapping to work properly in this environment, in answer to a newsgroup/forum question (and a new forum editor)."
    ' strValue = "This is a short string"
    
    arrWords = Split(strValue, " ")

    Next Insert HTML:

    Option Explicit

    Dim strValue, intLen
    Dim arrWords, strVariableWithOneWord, strVariableWithWrappedOutput, strVariableWithContentsOfLine

    strValue = "This is a very, very, very long string to force word wrapping (or code editor scroll bars) for test purposes to see if we can get word wrapping to work properly in this environment, in answer to a newsgroup/forum question (and a new forum editor)."
    ' strValue = "This is a short string"

    arrWords = Split(strValue, " ")

    -----



    Richard Mueller - MVP Directory Services

    Sunday, February 12, 2012 9:56 PM