How can I add filler into text file?

  • Hi, All...

    I have a q for U...as usual..

    I want to add filler(I mean spaces) into the header text info..How can I do that instead of hitting spacebar? I need to add around 850 spaces into text header info...

    Here is some code U can take a look it..

    /*********************************/

    Const ForReading=1, ForWriting=2, ForAppending=8

    Dim fso, f, ReadDataFile, AppendToHeader,ReadTrailerFile,FinalFile

    Dim dMonth, dDay, dTime,dMin

    Set fso = CreateObject("Scripting.FileSystemObject")

    'Create Text File & Insert Header Info

    Set f = fso.CreateTextFile("c:\testfile.txt", True)

    Select Case Len(Month(Date))

    Case "1"

    dMonth = "0" & Month(Date)

    Case Else

    dMonth = Month(Date)

    End Select

    Select Case Len(Day(Date()))

    Case "1"

    dDay = "0" & Day(date())

    Case Else

    dDay = Day(date())

    End Select

    Select Case Right(Time(), 2)

    Case "AM"

    dTime = "0" & Left(Time(), 1)

    Case Else

    dTime = Left(Time(), 1) + 12

    End Select

    Select Case Len(Replace(Time(), ":", ""))

    Case "8"

    dMin = Mid(Replace(Time(), ":", ""), 2, 4)

    Case "9"

    dMin = Mid(Replace(Time(), ":", ""), 3, 4)

    End Select

    dFiller=Char(849)

    f.WriteLine("STKOPTHDR " & YEAR(DATE( )) & dMonth & dDay & dTime & dMin & " XOP1105" & dFiller)

    f.Close

    /*******************************/

    All teh way bottom in dFiller position, I want to put filler(850 spaces)..

    Any thought

    Thx in advance

    Jay

  • Something like this shoulw work

    DIM dFillStr, xLoop

    FOR xLoop = 1 to 850

    dFillStr= dFillStr & " "

    NEXT

    Once done you will have a variable with 850 whitespaces that you can just plug it.

    Hope this helps.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Mannnn..U are great...

    It works liek charm.. :-)))

    How did U think about this? I was thinking more like putting some charater string instead of looping through..

    Thx

    Jay

  • This is all I do all day, think about ways to do things to fix or improve our existing code. And I have had serveral situations where I needed 0 in the front of a number with a specific total length and this is pretty close to how I do those.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Space(850) works too.

  • left zero pad:

    set @s-2 = replicate('0', @desiredlengh - len(@s)) + @s-2

  • However those are SQL statements not VBScript.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • my bad. vbscript not tsql.

    Space(850) still works in vbscript.

    Replace(character, number) becomes

    Space(Number, character).

  • Ok egg on my face, not seen those before, and they keep coming. I will have to check those out, thanks.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Hey..hey..hey

    U guys are having a ball without me..

    Fill me in.. Kidding..

    U know what.. I really grad that I can participate this discussion and I give my thanks to sqlservercentral and anybody who shares some knowledge with others..

    Thx

    Jay:-)))

  • Well you know you should stay subscribed to your own post and as with any solution the first may work but may not be the best and keeping up with any future post may help you streamline your code.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply