0
    If objFSO.GetFile(tempFolder & "\list2.txt").Size > 0 Then 
        contents = objFSO.OpenTextFile(tempFolder & "\list2.txt", 1, False).ReadAll
 Select Case  MsgBox ("Link" & contents & "",vbYesNoCancel+vbExclamation+vbSystemModal,"Wassup?")

This up here is my vbs code. I have list2.txt and I have multiple lines in it between min3 max8 lines. And as you can see I am showing list.txt inside of my MsgBox.

My Question is I want to hide 2nd line inside the MsgBox. I can't delete it because I need it.

So how can I hide line2 and read the other lines?

Rıdvan Çetin
  • 183
  • 5
  • 16

3 Answers3

0

You can't hide parts of the text in a MegBox. You need a copy of your input file's content without line 2. Use a RegExp:

Option Explicit

' a string of 5 lines
Dim s : s = Replace("one two three four five", " ", vbCrLf)
' a RegExp to delete line 2
Dim r : Set r = New RegExp
r.Pattern = "(.+)(\n.+)(\n[\s\S]+)"
' a copy of s without line 2
Dim t : t = r.Replace(s, "$1$3")
WScript.Echo Replace(s, vbCrLf, "\r\n")
WScript.Echo Replace(t, vbCrLf, "\r\n")
WScript.Echo t
MsgBox t

output:

cscript 42231154.vbs
one\r\ntwo\r\nthree\r\nfour\r\nfive
one\r\nthree\r\nfour\r\nfive
one
three
four
five

(I assume vbCrLf EOLs)

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0
Option Explicit 

' Prepare a test buffer
Dim contents
    contents = Join( Array("line 1", "line 2", "line 3", "line 4"), vbCrLf )
    WScript.Echo contents

' Option 1 - Remove second line via regular expression
Dim purgedContents
    With New RegExp
        .Pattern = "[\r\n]+[^\r\n]*"
        purgedContents = .Replace( contents, "" )
    End With 
    WScript.Echo "--------------------------"
    WScript.Echo purgedContents

' Option 2 - Array operation
Dim i
    purgedContents = Split( contents, vbCrLf )
    For i = 1 To UBound( purgedContents ) - 1
        purgedContents(i) = purgedContents( i+1 )
    Next 
    Redim Preserve purgedContents( UBound(purgedContents) - 1 )
    purgedContents = Join( purgedContents, vbCrLf )
    WScript.Echo "--------------------------"
    WScript.Echo purgedContents

' Option 3 - Array 2 - If we don't need to keep empty lines
    purgedContents = Split( contents, vbCrLf )
    purgedContents(1) = ""
    purgedContents = Replace( Join( purgedContents, vbCrLf ), vbCrLf+vbCrLf, vbCrLf )
    WScript.Echo "--------------------------"
    WScript.Echo purgedContents
MC ND
  • 69,615
  • 8
  • 84
  • 126
0

What about something like this:

Dim i
i = 1

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim oFile
Set oFile = objFSO.OpenTextFile(tempFolder & "\list2.txt", 1, False)

Dim contents
If objFSO.GetFile(tempFolder & "\list2.txt").Size > 0 Then
    Do
        ' Collect data for all lines except line 2
        ' -----------------------------------------
        If i <> 2 Then
            contents  = contents & vbNewLine & oFile.ReadLine
        Else
            ' Skip un required line
            ' ----------------------
            oFile.ReadLine
        End If

        i = i + 1
    Loop Until oFile.AtEndOfStream
End If

MsgBox "Link" & contents & "",vbYesNoCancel+vbExclamation+vbSystemModal,"Wassup?"
BoffWx
  • 106
  • 4