Results 1 to 3 of 3

Thread: Error: expected As

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    This is my first shot at a simple array and the use of an InputBox. VB doesn't like the code in the Inputbox line and I get the error - expected As. I've tried all ways to correct this line... (code below)what have I done wrong?

    GRAHAM

    Private Sub Form_Load()

    Dim I As Integer
    Dim Name(3) As String

    For I = 1 To 3

    Name(1) = InputBox("Enter names", "Array Demo", "insert here")
    Next I

    'just print names on form
    For I = 1 To 3
    Print "Name is"; Name(I)
    Next I

    End Sub

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    The problem is Name is a reserved VB command For Renaming Files/Folders, ie.
    Code:
    Name "C:\This.txt" As "C:\That.txt"
    Try this:
    Code:
    Private Sub Form_Load()
        Dim I As Integer
        Dim sName(3) As String
        
        For I = 1 To 3
            sName(I) = InputBox("Enter names", "Array Demo", "insert here")
        Next I
        
        Show
        'just print names on form
        For I = 1 To 3
            Print "Name is "; sName(I)
        Next I
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    CWMBRAN,WALES,UK
    Posts
    146
    Thanks Aaron

    Doh! I should have spotted that

    GRAHAM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width