UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Vbscript Subscript Out Of Range Error    
 
   
cdrum
post Aug 1 2018, 02:46 PM
Post#1



Posts: 9
Joined: 26-April 18



Hey,

Dipping my toe into VBScript, I inherited this code snippet that is supposed to run a macro in our passport client.

The error message tells me my error is at the 'if tray(3)' line, but I can't figure out the problem.

This exact macro worked yesterday with no problems at all, nothing changed except the input data and it doesn't work today.

I did verify that the input data was setup the same way today as it was yesterday.

Not sure where to go from here..

Thanks
Clay

input - the 0's with the dollar sign in front would be an amount, and the 0's at the end would be the account number

CODE
8/1/2018    8/1/2018    American Auto Guardian, Inc    $000.00         VOLUNTARY    000000000
8/1/2018    8/1/2018    American Auto Guardian, Inc    $000.00         VOLUNTARY    000000000


code

CODE
Set ifile = CreateObject("Scripting.FileSystemObject").OpenTextFile("W:\Cash Mgmt Full Team\Cash Mgmt\17-GM\AAGI\AAGI_Macros\AAA_gmf_AAGI_IN.txt",1)


'// Arrays
Dim date(999)
Dim amt(999)
Dim etype(999)
Dim acct(999)


'====================================================================

c= 0

do

    '// reads line
    inline = ifile.ReadLine()

    tray = Split(inline, "    ")

    if tray(3) > 0 then
            'call mmes(tray(1))    '// 1 = eff date
            'call mmes(tray(3))    '// 3 = amount
            'call mmes(tray(5))    '// 5 = type
            'call mmes(tray(6))    '// 6 = account
        date(c) = tray(1)
        amt(c) = tray(3)
        etype(c) = tray(5)
        acct(c) = tray(6)
        if Len(acct(c)) = 9 AND InStr(acct(c), "17") = 1 then
            acct(c) = "0" & acct(c)
        end if
    else
        c = c - 1
    end if
numto = c
c = c + 1
loop until ifile.AtEndOfStream
Go to the top of the page
 
Doug Steele
post Aug 1 2018, 02:50 PM
Post#2


UtterAccess VIP
Posts: 21,856
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Is it possible that there isn't exactly four spaces between each column: that perhaps there's an nonvisible character?

--------------------
Doug Steele, Microsoft Access MVP (2000-2018)
http://www.accessmvp.com/DJSteele/AccessIndex.html
Co-author: Access Solutions: Tips, Tricks, and Secrets from Microsoft Access MVPs, published by Wiley
Co-author: Effective SQL: 61 Specific Ways to Write Better SQL, published by Addison-Wesley Professional
Technical Editor: Access 2010 Bible, Access 2013 Bible, Access 2016 Bible, all published by Wiley
Technical Editor: SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, 4th Edition, published by Addison-Wesley Professional
Go to the top of the page
 
cdrum
post Aug 1 2018, 03:24 PM
Post#3



Posts: 9
Joined: 26-April 18



I thought of that as well, it's actually a tab, and I checked the input, there is one tab in between each column.
Go to the top of the page
 
orange999
post Aug 1 2018, 03:30 PM
Post#4



Posts: 1,826
Joined: 10-February 08
From: Ottawa, Ont, Canada; West Palm Beach, FL


You could try replacing (untested)

CODE
tray = Split(inline, "    ")

with

CODE
tray = Split(inline, vbTab)

--------------------
Good luck with your project!
Go to the top of the page
 
cdrum
post Aug 1 2018, 03:50 PM
Post#5



Posts: 9
Joined: 26-April 18



I appreciate the suggestion, unfortunately that didn't work either.

I've attached a screenshot of the exact error, hope that helps.

Thanks
Clay
Attached File(s)
Attached File  error.pdf ( 8.33K )Number of downloads: 4
 
Go to the top of the page
 
orange999
post Aug 1 2018, 03:59 PM
Post#6



Posts: 1,826
Joined: 10-February 08
From: Ottawa, Ont, Canada; West Palm Beach, FL


What is the code on line 48?

You could post the whole routine so we could see it.

--------------------
Good luck with your project!
Go to the top of the page
 
cdrum
post Aug 2 2018, 06:43 AM
Post#7



Posts: 9
Joined: 26-April 18



if tray(3) > 0 then

is line 48.

The only thing above what I have posted above is message box prompts that make sure you meant to run the process and verify that passport is starting in the correct screen, all of those work perfectly, then when I proceed past the message box the error pops up and the process ends.
This post has been edited by cdrum: Aug 2 2018, 06:44 AM
Go to the top of the page
 
cdrum
post Aug 2 2018, 07:27 AM
Post#8



Posts: 9
Joined: 26-April 18



For some reason (unbeknownst to me) the script works today with the same data from yesterday that was re-pasted in.

I guess there was some issue with the input file, I deleted everything from the input file and re copy/pasted the data in and it worked today.

I also tried that yesterday twice, the VB goblins must have been mad at me yesterday pullhair.gif iconfused.gif

Thank you for all your help.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    21st August 2018 - 08:47 AM