Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Input Ascii Error

darthmoobeydarthmoobey Member Posts: 140
[code]
Public Sub import_payroll()
Dim intx As Integer
Dim inputstring As String
intx = 0

Open "c:ProjectsParyoll 2prdata" For Input As #1
Do While Not EOF(1)
Input #1, inputstring(intx) <--- Here is location of error
string_break (inputstring(intx))
intx = intx + 1
Loop
Close #1

End Sub
[/code]

I have created this code to input an ascii file into a string array. I also created a subroutine called string_break that breaks the string accordingly and sends it to a database for storage. I keep getting this error:
Compile Error: Expected Array, and it points to where I marked on the code.

I am not sure why this error is occuring, please help, if you need to see the code for the string break sub let me know if that will help. Thank you all very much.

The Darthmoob.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : [code]
    : Public Sub import_payroll()
    : Dim intx As Integer
    : Dim inputstring As String
    : intx = 0
    :
    : Open "c:ProjectsParyoll 2prdata" For Input As #1
    : Do While Not EOF(1)
    : Input #1, inputstring(intx) <--- Here is location of error
    : string_break (inputstring(intx))
    : intx = intx + 1
    : Loop
    : Close #1
    :
    : End Sub
    : [/code]
    :
    : I have created this code to input an ascii file into a string array. I also created a subroutine called string_break that breaks the string accordingly and sends it to a database for storage. I keep getting this error:
    : Compile Error: Expected Array, and it points to where I marked on the code.
    :
    : I am not sure why this error is occuring, please help, if you need to see the code for the string break sub let me know if that will help. Thank you all very much.
    :
    : The Darthmoob.
    :

    Pfff... This again. I thought we said that a few times in the original post. Well guess I'll say it again:
    [code]
    Dim inputstring
    'This will result in a Variable called inputstring
    Dim inputstring As String
    'This will result in a string variable called inputstring
    Dim inputstring()
    'This will make an array of Variables
    Dim inputstring() As String
    'Now here's what we need, a [b]dynamic[/b] array of strings

    'Now because the string is a dynamic array you will have to define
    'it's boundries before use.
    ReDim inputstring(intx)

    'Now this is nice and all but it won't fit with our code.
    'In the code we don't know what intx will eventually be and
    'every time you ReDim like this you'll lose the information
    'Guess we're going to have to use another way:
    ReDim [b]Preserve[/b] inputstring(intx)

    'Now we have it almost ready, just need to adapt out code a bit
    'So the final code would be this:

    Public Sub import_payroll()
    Dim intx As Integer
    Dim inputstring() As String

    intx = 0

    Open "c:ProjectsParyoll 2prdata" For Input As #1
    Do While Not EOF(1)
    ReDim Preserve inputstring(intx)
    'Make no mistake: 0 doesn't mean
    'that the array has no elements
    '0 here stands for 0 To 0 which makes 1 element
    Input #1, inputstring(intx)
    string_break (inputstring(intx))
    intx = intx + 1
    Loop
    Close #1

    End Sub
    [/code]

    Maybe it would be a good idea for you to look up some information about arrays.

    Greets...
    Richard

  • darthmoobeydarthmoobey Member Posts: 140
    : : [code]
    : : Public Sub import_payroll()
    : : Dim intx As Integer
    : : Dim inputstring As String
    : : intx = 0
    : :
    : : Open "c:ProjectsParyoll 2prdata" For Input As #1
    : : Do While Not EOF(1)
    : : Input #1, inputstring(intx) <--- Here is location of error
    : : string_break (inputstring(intx))
    : : intx = intx + 1
    : : Loop
    : : Close #1
    : :
    : : End Sub
    : : [/code]
    : :
    : : I have created this code to input an ascii file into a string array. I also created a subroutine called string_break that breaks the string accordingly and sends it to a database for storage. I keep getting this error:
    : : Compile Error: Expected Array, and it points to where I marked on the code.
    : :
    : : I am not sure why this error is occuring, please help, if you need to see the code for the string break sub let me know if that will help. Thank you all very much.
    : :
    : : The Darthmoob.
    : :
    :
    : Pfff... This again. I thought we said that a few times in the original post. Well guess I'll say it again:
    : [code]
    : Dim inputstring
    : 'This will result in a Variable called inputstring
    : Dim inputstring As String
    : 'This will result in a string variable called inputstring
    : Dim inputstring()
    : 'This will make an array of Variables
    : Dim inputstring() As String
    : 'Now here's what we need, a [b]dynamic[/b] array of strings
    :
    : 'Now because the string is a dynamic array you will have to define
    : 'it's boundries before use.
    : ReDim inputstring(intx)
    :
    : 'Now this is nice and all but it won't fit with our code.
    : 'In the code we don't know what intx will eventually be and
    : 'every time you ReDim like this you'll lose the information
    : 'Guess we're going to have to use another way:
    : ReDim [b]Preserve[/b] inputstring(intx)
    :
    : 'Now we have it almost ready, just need to adapt out code a bit
    : 'So the final code would be this:
    :
    : Public Sub import_payroll()
    : Dim intx As Integer
    : Dim inputstring() As String
    :
    : intx = 0
    :
    : Open "c:ProjectsParyoll 2prdata" For Input As #1
    : Do While Not EOF(1)
    : ReDim Preserve inputstring(intx)
    : 'Make no mistake: 0 doesn't mean
    : 'that the array has no elements
    : '0 here stands for 0 To 0 which makes 1 element
    : Input #1, inputstring(intx)
    : string_break (inputstring(intx))
    : intx = intx + 1
    : Loop
    : Close #1
    :
    : End Sub
    : [/code]
    :
    : Maybe it would be a good idea for you to look up some information about arrays.
    :
    : Greets...
    : Richard
    :
    :
    Thank you Richard, perhaps I Will do that. I am sorry if it was a bit too mundane, I apologise. I did not know about ReDim Preserve, I tried with a basic string() caption and got the same message. I will read into this on MSDN library some more. Again, thank you and I apologise.

    the Darthmoob
Sign In or Register to comment.