Results 1 to 10 of 115

Thread: Notes tests, text files, manipulation of text files in Excel and with Excel VBA CSV stuff

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,451
    Rep Power
    10
    Dec 2020-11-29

    If I make text file with nothing in it and then after look at the text file with the following macro ..._
    Code:
    ' A virgin text file
    Sub AVirginTextFile()
    ' 1    Make a virgin text file
    Dim FileNum2 As Long: Let FileNum2 = FreeFile(0)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
    Dim PathAndFileName2 As String
     Let PathAndFileName2 = ThisWorkbook.Path & "\" & "NoText.txt"  ' CHANGE path TO SUIT
     Open PathAndFileName2 For Output As #FileNum2
    Dim NoText As String
     Print #FileNum2, NoText ' write out entire text file, the file is made if not there
     Close #FileNum2
    ' 2a)  Get the text file as a long single string
    Dim FileNum As Long: Let FileNum = FreeFile(1)                                    ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
    Dim PathAndFileName As String, TotalFile As String
     Let PathAndFileName = ThisWorkbook.Path & Application.PathSeparator & "NoText.txt"   '                                                               CHANGE TO SUIT                                                                                                         From vixer zyxw1234  : http://www.eileenslounge.com/viewtopic.php?f=30&t=34629     DF.txt https://app.box.com/s/gw941dh9v8sqhvzin3lo9rfc67fjsbic
    Open PathAndFileName For Binary As #FileNum 'Open Route to data. Binary is a fundamental type data input...
     Let TotalFile = Space(LOF(FileNum)) '....and wot receives it has to be a string of exactly the right length
    Get #FileNum, , TotalFile                                               'Debug.Print TotalFile
    Close #FileNum
     Call WtchaGot_Unic_NotMuchIfYaChoppedItOff(TotalFile)
    End Sub
    _... then I will see nothing at all in Notepad, and from my WotchaGot function it will tell me that I have
    vbCr & vbLf

    If I Let NoText = "x" , and repeat the experiment, I see in notepad .._
    Code:
    x
    _.. and my function tells me that I have
    "x" & vbCr & vbLf

    Here are some more experiments, and the results:
    Let NoText = "x" & vbCr & "x"
    "x" & vbCr & "x" & vbCr & vbLf
    Code:
    xx
    Let NoText = "x" & vbLf & "x"
    "x" & vbLf & "x" & vbCr & vbLf
    Code:
    xx
    Let NoText = "x" & vbCr & vbLf & "x"
    "x" & vbCr & vbLf & "x" & vbCr & vbLf
    Code:
    x
    x
    Let NoText = "x" & vbLf & vbCr & "x"
    "x" & vbLf & vbCr & "x" & vbCr & vbLf
    Code:
    xx
    If I repeat the experiment using extension .csv instead of .txt everywhere in my macro, then the results are identical.
    So it appears that notepad only recognises the pair vbCr & vbLf as a new line

    ( Note: if I open any of the files ( .txt or .csv ) in Excel , using any default settings, then for the case of the vbLf or the vbCr or the pair vbCr & vbLf then Excel always seems to add a line and I see
    _____ Workbook: NoText.txt ( Using Excel 2007 32 bit )
    Row\Col
    A
    1
    x
    2
    x
    Worksheet: NoText
    _____ Workbook: NoText.csv ( Using Excel 2007 32 bit )
    Row\Col
    A
    1
    x
    2
    x
    Worksheet: NoText

    For the case of using vbLf & vbCr, using the default settings opening in Excel the .txt file also gives the same result, but strangely for the .csv file we see an extra line
    _____ Workbook: NoText.csv ( Using Excel 2007 32 bit )
    Row\Col
    A
    1
    x
    2
    3
    x
    Worksheet: NoText
    Last edited by DocAElstein; 11-29-2020 at 01:15 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Replies: 109
    Last Post: 03-29-2024, 07:01 PM
  2. Replies: 4
    Last Post: 01-30-2022, 04:05 PM
  3. Replies: 29
    Last Post: 06-09-2020, 06:00 PM
  4. Notes tests. Excel VBA Folder File Search
    By DocAElstein in forum Test Area
    Replies: 39
    Last Post: 03-20-2018, 04:09 PM
  5. Collate Data from csv files to excel sheet
    By dhiraj.ch185 in forum Excel Help
    Replies: 16
    Last Post: 03-06-2012, 07:37 PM

Posting Permissions

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