PDA

Click to See Complete Forum and Search --> : Please help. I got some problems with Array Elements.


lumin
Jan 19th, 2000, 07:30 AM
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"


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

Mark Sreeves
Jan 19th, 2000, 08:26 PM
Which line causes the Error?


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

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

lumin
Jan 20th, 2000, 12:10 AM
The line I got an error on is:


txtOwner(iTextbox) = txtOwner(iTextbox) & sFile & vbCrLf


Hope this helps.


-Lumin

MartinLiss
Jan 20th, 2000, 03:42 AM
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?

lumin
Jan 20th, 2000, 04:38 AM
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

Aaron Young
Jan 20th, 2000, 04:43 AM
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

lumin
Jan 21st, 2000, 06:31 AM
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