Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2022, 04:28 PM
Guessed's Avatar
Guessed Guessed is offline Reading basic .txt file fails, how can it be? Windows 10 Reading basic .txt file fails, how can it be? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default


Here is a concept to read the text into an array of arrays.
Source: Function was based on the stellar work of Bob77 on StackOverflow - vb6 - Array and Split commands to create a 2 dimensional array - Stack Overflow
Code:
Sub TEST_Get_Properties()
  Dim hf As Integer, sFN As String, lines As String
  Dim myArray As Variant, iRow As Integer, iCol As Integer
  sFN = "C:\Users\" & Environ("UserName") & "\615e8498df6dc933e3baf8732fe5ecf38f4a62b5.txt"
  ' Load core content using data txt file
  hf = FreeFile
  Open sFN For Input As #hf
    lines = Input$(LOF(hf), #hf)
  Close #hf
  myArray = SplitSplit(lines)
  For iRow = 0 To UBound(myArray)
    For iCol = 0 To UBound(myArray(iRow))
      Debug.Print "Row:" & iRow, "Col:" & iCol, myArray(iRow)(iCol)
    Next
  Next
End Sub

Private Function SplitSplit(ByRef Delimited As String, Optional sDiv1 As String = vbLf, Optional sDiv2 As String = " ++ ") As Variant
  Dim Rows() As String, AryOfArys As Variant, I As Long
  Rows = Split(Delimited, sDiv1)
  ReDim AryOfArys(UBound(Rows))
  For I = 0 To UBound(Rows)
    AryOfArys(I) = Split(Rows(I), sDiv2)
  Next
  SplitSplit = AryOfArys
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 09-15-2022 at 11:35 PM.
Reply With Quote
  #2  
Old 09-19-2022, 01:49 AM
TheBigBoss TheBigBoss is offline Reading basic .txt file fails, how can it be? Windows 7 32bit Reading basic .txt file fails, how can it be? Office 2010 32bit
Advanced Beginner
Reading basic .txt file fails, how can it be?
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

I now recall why I run .txt file in a new Word.application
My .txt files have special characters, including non western (Arabic, Chinese) and I got issues reading .txt files

I tried to implement the method here - Solving the Unicode, UTF8, UTF16 and Text Files conundrum in VBA - Francesco Foti's weblog - which read text file as binary and convert special characters but I failed to even run it. Too bad as the code works for all platform (Windows, MAC). Other common method I have found is ADOB.stream with Charset = "utf-8".

Txt files seem to be problematic, I am wondering if I am not better consider using .docx instead.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
The “spelling and grammar” check fails to work as the number of words in the file exceeds a certain Jamal NUMAN Word 3 09-24-2019 10:45 AM
Reading basic .txt file fails, how can it be? Need plugin for reading+converting *.pdf file into *.doc pstein Word 1 05-24-2015 07:05 AM
Reading pane on TOP? hehunt Outlook 0 04-10-2014 06:34 AM
Reading basic .txt file fails, how can it be? How to save a PPT file in 'Reading View' to be opened always in 'Reading View' ItzVickey PowerPoint 2 08-08-2012 09:23 AM
Reading basic .txt file fails, how can it be? Word Basic 2003 to Word Basic 2007 Incompatibility Mark1110 Word VBA 1 12-29-2010 11:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft