Solved

# how do i make a message box for if there is no numbers to divide (keep getting invalidargument=Value of '1' is not valid for 'index'. Parameter name: index error message)

Posted on 2011-03-16
428 Views
hi
I need to know how to make a message box for if the grades in the listbox equal 0 (meaning no grades have been entered and how to get the message box from poppin up all the time. It either pops up and wont calculate the average of the grades or i get the invalidargument=Value of '1' is not valid for 'index'. Parameter name: index error message. here is what i have:
' initialization phase
Dim total As Integer = 0
Dim gradeCounter As Integer = 0
Dim grade As Integer = 0
Dim average As Double = 0

If IsNumeric(gradesListBox.Text = "" Or 0) = True Then

Else

Do
average = False
End If

averageResultLabel.Text = String.Format("{0:F}", average)
End If
End Sub ' averageButton_Click
End Class ' ClassAverageForm
0
Question by:goldfingerpunk
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 3

LVL 29

Expert Comment

ID: 35153359
try:
0

Author Comment

ID: 35153444
I tried that and now i get this error message : Conversion from string "" to type 'Double' is not valid.
0

LVL 29

Expert Comment

ID: 35153452
On the If statement line?
0

Author Comment

ID: 35153465
well i guess there is two IF statment lines but i tried what you said on the first one. here is what part of my assignment says- Summing the grades in the ListBox. Modify code in the averageButton_ Click event handler so that gradeCounter increments until its equal to the number of grades entered. Use gradesListBox. Items. Count to determine the number of items in the ListBox. The number returned by the Count property will be zero if there are no grades entered. Use an If Then selection statement to avoid division by zero and display a message dialog to the user if there are no grades entered when the user clicks the Average Button.
0

LVL 29

Expert Comment

ID: 35153472
what happens if you change the first If to :
0

LVL 29

Expert Comment

ID: 35153485
Actually what you really need is
0

Author Comment

ID: 35153527
same as first time with your first response and the second time i get count is not a member of systems.windows.forms.listbox
0

LVL 29

Accepted Solution

Paul Jackson earned 500 total points
ID: 35153628
sorry that should be :
0

LVL 86

Expert Comment

ID: 35153743
Can you use a For...Next loop?
``````Private Sub averageButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles averageButton.Click
Else
Dim total As Integer = 0
Dim average As Double = 0

Next

averageResultLabel.Text = String.Format("{0:F}", average)

End If
End Sub
``````

It still technically meets the requirement of making "gradeCounter increment until its equal to the number of grades entered".
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month1 day, 19 hours left to enroll