Results 1 to 7 of 7

Thread: Please help. I got some problems with Array Elements.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143

    Post

    Please help me with this problem.

    Some How I can't get this code to work.
    It works great when I only use 1 Array Element Group but when I use 2 I get a runtime error 340 and a message that says: "Control Array Element '1' Doesent exist"

    Code:
    Public iNumOfOperator As Integer
    Public iNumOfOwner As Integer
    
    
    Private Sub Form_Load()
    iNumOfOwner = 1
    iNumOfOperator = 9
    
    
    Dim sFile As String
    Dim iTextbox As Integer
    On Error GoTo NoFile
    With cdbLoadSave
    .DialogTitle = "Open User Configuration.."
    .Filter = "Usr File (.Usr)|*.usr"
    .CancelError = True
    .ShowOpen
    sFile = .FileName
    End With
    On Error GoTo 0
    Open sFile For Input As 1
    While Not EOF(1)
    Line Input #1, sFile
    
    If Left(sFile, 6) = "[Owner" Then
    iTextbox = Val(Trim(Mid(sFile, 7, InStr(sFile, "]") - 1)))
    txtOwner(iTextbox) = ""
    Else
    txtOwner(iTextbox) = txtOwner(iTextbox) & sFile & vbCrLf
    End If
    
    If Left(sFile, 9) = "[Operator" Then
    iTextbox = Val(Trim(Mid(sFile, 10, InStr(sFile, "]") - 1)))
    txtOperator(iTextbox) = ""
    Else
    txtOperator(iTextbox) = txtOperator(iTextbox) & sFile & vbCrLf
    End If
    
    Wend
    Close 1
    NoFile:
    
    End Sub
    If you can Help me that would be great.

    Thanks anyway.


    -Lumin

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    Which line causes the Error?


    ------------------
    Mark Sreeves
    Analyst Programmer

    Mark.Sreeves@Softlab.co.uk
    A BMW Group Company

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143

    Post

    The line I got an error on is:

    Code:
    txtOwner(iTextbox) = txtOwner(iTextbox) & sFile & vbCrLf
    Hope this helps.


    -Lumin

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    Go to your form and look at the properties for txtOwner. The code assumes that there is a txtOwner control with an Index property of 1. Is there?

    ------------------
    Marty
    Can you buy an entire chess set in a pawn shop?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143

    Post

    I have only 1 txtOwner Texbox since the program is made to only server 1 owner.
    I can't see if this should do any difference.

    I just added 3 more textboxses to see if it made any diferences, the only thing that showed up was that Array element '4' was missing. So im back where I started.

    but if you got any sugjestions please post em.


    -Lumin

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    The Code is Reading in an Index Number from the Opened File, Check the File to See what the highest Index Number is, that is how many Textboxes you Require.

    As you are using a Textbox Control Array, you need to make sure you have enough Controls in the Array to Match the Index you retrieve from the file each time.

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    ajyoung@pressenter.com


  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143

    Post

    Thanks for all the re-plys I have recived.

    I finaly managded to find the bug myself, it was realy easy for me to find since I wrote the code

    I just asume that I forgot it.
    man I hate when that happends.


    Anyway I wish to thanks evryone who have re-played with some comments or suggjestions.


    -Lumin

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