LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 721 users online 158057 members 1917 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Video | Dictionary | News | FAQ
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
3 online / 71 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

Visual basic
Help me
Replies: 4Last Post Dec. 8, 2004 3:45am by ckings6056
Single page for this topic Email Print Favorite
( kame )


Personal Assistant
Reply
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

-------
i am super, you are super, we might as well call ourselves invincible. visit www.dbz-galore.com (shut down due to .... ask me and ull find out )


4:17 pm on June 24, 2004 | Joined Mar. 2004 | 17 Days Active
Join to learn more about kame United Kingdom | Male | 76 Posts | 229 Points
sakurag


Dairy Product Addict

Ad Free
Reply
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.


-------
I've got spurs that jingle jangle jingle.
As I go riding merrily along.
And they sing, "Oh, ain't you glad you're single?"
And that song ain't so very far from wrong.


8:01 pm on June 24, 2004 | Joined Oct. 2002 | 460 Days Active
Join to learn more about sakurag Washington, United States | Straight Male | 1892 Posts | 8074 Points
imsocrazy


Quality Control Engineer
Reply
have you said what poistion is?

3:57 pm on July 15, 2004 | Joined July 2004 | 59 Days Active
Join to learn more about imsocrazy United Kingdom | 133 Posts | 735 Points
mephisto mortis


Enlightened One
Reply
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

-------
Lifes a bitch.  If it were a slut it'd be too easy.

5:29 pm on Sep. 3, 2004 | Joined June 2004 | 969 Days Active
Join to learn more about mephisto mortis New York, United States | Straight Male | 5856 Posts | 16175 Points
ckings6056


Dairy Product Addict

Patron
Reply
I havent used VB properly for god knows how long!!

-------
Upto my neck and i'm breathing without you,
upto my eyes and i'm seeing without you,
upto my heart and i'm still bleeding without you!!!

3:45 am on Dec. 8, 2004 | Joined Mar. 2003 | 252 Days Active
Join to learn more about ckings6056 United States | Straight Male | 2757 Posts | 15377 Points
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic