I have a text file containing many lines of numbers seperated by spaces. example:
1234 34332 12
1235 3543 12
I need to read the file into a 2-d array I dont know how to do this becasue of the spaces. I need to replace the spaces in that file with commas, so i can do this. or anyother way that is possible..
5 2924
Use the replace function when you read it in. If you do not know how to read a file in with VB 6.0, the please look up the following on the index tab of vb's help...
FreeFile Function
Open Statement
Input Function
Line Input Function
Close Statement
Replace Function
Split Function
Good Luck
Also look up the split function. Very handy for just what you are doing.
Ah-hmm (clears throat and then whispers) Psstt! Hey NoItAll, look at the line right above my Good Luck :)
DOH!
...he said with an embarrassed red-faced......
Don't forget the ! in front of NoItAll, it is meant, and proven here, as the "not" symbol in my pseudonym...
dawn123,
Recieved your PM... -
Option Explicit
-
-
Private Sub Command1_Click()
-
-
On Error GoTo Command1_ClickError
-
-
Dim FName As String, FNumb As Integer
-
Dim LineContents As String, LineElements() As String
-
Dim LowerBoundsOfArray As Integer, UpperBoundsOfArray As Integer, ForLoopCounter As Integer
-
-
CD.CancelError = True
-
CD.Filter = "Text Files *.txt|*.txt"
-
CD.ShowOpen
-
-
FNumb = FreeFile
-
FName = CD.FileName
-
-
Open FName For Input As #FNumb
-
Do While Not EOF(FNumb)
-
Line Input #FNumb, LineContents
-
LineElements = Split(LineContents, " ")
-
'do work here with information from file LineElements(0), LineElements(1), LineElements(2)
-
'you may also want to use the LBound and UBound Functions...
-
' LowerBoundsOfArray = LBound(LineElements)
-
' UpperBoundsOfArray = UBound(LineElements)
-
' For ForLoopCounter = LowerBoundsOfArray To UpperBoundsOfArray
-
' 'do work here
-
' Next ForLoopCounter
-
Loop
-
Close #FNumb
-
-
Exit Sub
-
Command1_ClickError:
-
-
If Err.Number = 32755 Then Exit Sub 'user pressed cancel
-
-
End Sub
-
Just for starters... Now, as for replacing those space characters with commas, you can either use the replace function as I mentioned and remove the Split Function from my example code, or you can use the Join Function and keep my example split function, however I must note that this would be much slower than use the replace function.
Good Luck
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jamait |
last post by:
Hi all,
I m trying to read in a text file into a datatable...
Not sure on how to split up the information though, regex or substrings...?
sample:
Col1 Col2 ...
|
by: Shane |
last post by:
Hi,
Thanks in advance for the help. I have been to many websites and tried
several solutions to my problem, but have fixed part of it. It's time to
come humbly to the newsgroups for help :-)
...
|
by: KevinD |
last post by:
assumption: I am new to C and old to COBOL
I have been reading a lot (self teaching) but something is not sinking
in with respect to reading a simple file - one record at a time.
Using C, I am...
|
by: EkteGjetost |
last post by:
I would like to first apologize to those of you who read my last post
"desperately need help". As a regular on other forums i can understand how
aggravating it would be to have someone come on who...
|
by: googler |
last post by:
I'm trying to read from an input text file and print it out. I can do
this by reading each character, but I want to implement it in a more
efficient way. So I thought my program should read one...
|
by: jeff M via .NET 247 |
last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
|
by: Tyler |
last post by:
Hello All:
After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the...
|
by: aboxylica |
last post by:
I have a file which contains something like this
>ref|NC_001133|
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACA
CATCCTAACACTACCCTAACACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTT...
|
by: Laharl |
last post by:
My Operating Systems professor has assigned homework that basically boils down to implementing ls -lra, but with a different output format. In other words, list the files and subdirectories (and a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |