Hi again -
I have a text file that is received on a daily basis and I use VBA to break down each field and add to an existing table. There are 50 fields in the text file (separated by semicolon) and I've had no problem whatsoever in it working. However, there have been 3 new fields (time - ie., 13:47:51) added to the text file and I need to modify my existing code (all fields not shown since it would take up too much space): - strFileName = "C:\Documents and Settings\user\Desktop\sometextfile.txt"
-
-
Set fso = CreateObject("Scripting.FileSystemObject")
-
If (fso.FileExists(strFileName)) Then
-
Else
-
MsgBox "File Not Found"
-
Exit Sub
-
-
Set rst = New ADODB.Recordset
-
rst.ActiveConnection = CurrentProject.Connection
-
rst.Open _
-
Source:="Select * from [test]", _
-
CursorType:=adOpenKeyset, _
-
LockType:=adLockOptimistic, _
-
options:=adCmdText
-
-
Open strFileName For Input As #1
-
-
Do Until EOF(1)
-
Line Input #1, strLineInput
-
strfield(1) = Mid(strLineInput, 1, 12)
-
strfield(2) = Mid(strLineInput, 14, 3) - - and everything in between
-
strfield(50) = Mid(strLineInput, 720, 8) <----last field
-
rst.AddNew
-
rst![F1] = Trim(strfield(1))
-
rst![F2] = Trim(strfield(2))
-
rst![F50] = Trim(strfield(50))
-
rst![DateStamp] = Date
-
rst.Update
-
Loop
-
Close #1
-
rst.Close
-
Set rst = Nothing
It's as simple as adding three (actually 6) more lines (parse the fields): - strfield(51) = Mid(strLineInput, 729, 8)
-
strfield(52) = Mid(strLineInput, 738, 8)
-
strfield(53) = Mid(strLineInput, 747, 8)
And updating the table - rst![F51] = Trim(strfield(51))
-
rst![F52] = Trim(strfield(52))
-
rst![F53] = Trim(strfield(53))
The fields were added to the table as F51 - Date/Time - format is Long Time - etc.
I get the Subscript out of Range on strfield(53) = Mid(strLineInput, 747, 8). I've even changed the start position to 738 an length to 8 (same as 52) and still get the error.
I sure don't want to have to do something different since this was working before. Anyone have any ideas as to why it won't bring in that last field?
Any help is much appreciated.
5 3243
I don't see strField dimmed anywhere. However, here's what I think the problem is, your array might be 50 elements big, but the index starts, by default, at 0 and ends at 49. So the first element of the array is strField(0) not strField(1). And the last element is strField(49) not strField(50).
But, isn't there a command to import a delimited text file? Why write code for each field?
I don't see strField dimmed anywhere. However, here's what I think the problem is, your array might be 50 elements big, but the index starts, by default, at 0 and ends at 49. So the first element of the array is strField(0) not strField(1). And the last element is strField(49) not strField(50).
But, isn't there a command to import a delimited text file? Why write code for each field?
Thanks Rabbit!!! - strfield was dimmed but it was strfield(52)...I changed it to 53 and all is fine!! I didn't do the import command because even though the field length is 25 - - the actual field imported could be 17...wanted to trim the spaces upon import.
Thanks so much!!!!
Thanks Rabbit!!! - strfield was dimmed but it was strfield(52)...I changed it to 53 and all is fine!! I didn't do the import command because even though the field length is 25 - - the actual field imported could be 17...wanted to trim the spaces upon import.
Thanks so much!!!!
Not a problem. But that's weird, you're trying to access index 50, which is under 52 so there shouldn't have been a problem.
Not a problem. But that's weird, you're trying to access index 50, which is under 52 so there shouldn't have been a problem.
Index 50 is where the original code stopped - I had to add 51-53 in order to get the additional 3 fields in there and it stopped at 53 (cause i had it dimmed at 52)...which I didn't look at before you mentioned it. Ya'll are amazing - - I have been trying to figure it out since this morning and even though ya'll can't "see" the code, the extra pair of eyes help out tremendously! Thanks!
Not a problem, good luck.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: andy.rich |
last post by:
I am getting the following error and I do not know why. Can anyone
help?
--------------------------------------------------------
this is what appears on the screen...
|
by: Richard Delorme |
last post by:
The n869 draft says:
J.2 Undefined behavior
The behavior is undefined in the following
circumstances:
-- An array subscript is out of range, even if an object
is ...
|
by: VB Programmer |
last post by:
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for
version 6....
I need help for something that should be simple. I keep getting a
"subscript out of range" error and...
|
by: Pedro Graca |
last post by:
I run into a strange warning (for me) today (I was trying to improve
the score of the UVA #10018 Programming Challenge).
$ gcc -W -Wall -std=c89 -pedantic -O2 10018-clc.c -o 10018-clc...
|
by: wennerd |
last post by:
I am getting a Subscript out of range after executing the following command
Set oRstPick = connTemp.Execute(sSQL)
It is a simple query:
sSQL = "SELECT idCategory, categoryDesc, idParentCategory...
|
by: josh |
last post by:
Hi I've a dubt!
when we have overloaded functions the compiler chooses the right
being based on the argument lists...but when we have two subscript
overloaded functions it resolves them being...
|
by: Andy |
last post by:
Hi all,
I started developing a little app on my Mac using XCode some month
ago. The app is running fine on my mac like a sharm. Now I am nearly
ready and yesterday I moved the whole source code...
|
by: subramanian100in |
last post by:
For vector and deque, the 'at( )' member function throws out_of_range
exception if the argument to the 'at( )' function is not in range. But
the subscript operator does not throw this exception...
|
by: Han |
last post by:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756
...
|
by: brandon01 |
last post by:
Keep getting "subscript out of range" any idea why? This function is looped btw.. Thx...
Private Sub getBday()
bDay = List1.List(nextBday)
bDayArr = Split(bDay, " - ")
Text1.Text =...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |