LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 779 users online 225476 members 1205 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Memberlist | Dictionary | News | FAQ
Member Spotlight
atla2323
Favs: Movies lotr, never back down, taken, tra...
Mood: Smart
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
7 online / 30 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Adding Reply

Adding Reply
Archived Topic: It will not be bumped to the top of the forum.
Topic Visual basic
Membername   Not a member? Sign Up Free (takes 20 seconds)
Password   Forgotten your password?
Post

Font:   Size:   Color:

FAQ Keyword Search:
Post Options
Favorites Manager
Notify me of new replies to this topic by email
Notify me of new replies to this topic by private message
Original Post
kame Posted at 4:17 pm on June 24, 2004
hey guys

i am writing a program but when i run it the program works and displays what i want once i have entered the info in but as soon as i have entered the info it displays an error. it says its to do with this line "lstDisplay.AddItem names(index) + Str$(marks(index))"

this is all of my code

Option Explicit
Dim position As Integer
Dim names(10) As String
Dim marks(10) As String

Private Sub cmdend_Click()

End

End Sub

Private Sub cmdGo_Click()

names(position) = txtInput
marks(position) = txtmark
position = position + 1
txtPosition = position

If position > 10 Then
 MsgBox "Full", vbCritical
End If

Dim index As Integer

lstDisplay.Clear

For index = 1 To position
 lstDisplay.AddItem names(index) + Str$(marks(index))
Next

End Sub

Private Sub Form_Load()
position = 1
txtPosition = position
End Sub

Replies
ckings6056 Posted at 3:45 am on Dec. 8, 2004
I havent used VB properly for god knows how long!!
mephisto mortis Posted at 5:29 pm on Sep. 3, 2004
only wussies use option explicit, but than again i dunno how to help you (forgot most of my vb) so i guess i am a wussie
imsocrazy Posted at 3:57 pm on July 15, 2004
have you said what poistion is?
sakurag Posted at 8:01 pm on June 24, 2004
I don't know vb very well, but I think there might be a problem with the following lines:

Code:

...
position = position + 1
...

I'm guessing after you enter in a name or something, you increment your position by 1.

Then later you go onto adding items into some sort of list display container.
Code:

For index = 1 To position
lstDisplay.AddItem names(index) + Str$(marks(index))
Next

Now what I think is a problem is as follows.  Because of the way you've implemented your position, it will always be + 1, everytime you get a new name.  Now, I'm not sure, but I'm guessing VB initializes integers to 0.  So say you start at 0 and you add 3 people, your count will be 0[first name] pos+1, 1[second name], pos+1, 2[third name], pos+1.  At the end of this, position = 3.

Now later, you start to add items, and you index from 1 - position, for this case, it's 3.

That means you are indexing
names(1), names(2), and names(3).. well, names(3) doesn't exist.

You might want to try doing your for from 0 -> pos - 1

Or use an iterator.


Note:  IF VB indexes from 1->n and NOT 0->n-1, then you can fix this by incrementing position before you assign the text into the arrays.

All 4 previous replies displayed.