0

I have made an application to add monthly usages of coffee to a listbox using an array. I have a button which opens up an InputBox to enter the monthly usages. I then click a button to display the usages in a listbox. Howerver, I only want users to be able to add numbers to the listbox so when a user clicks enters a non-numeric value or enters nothing at all and clicks OK, a MsgBox appears. I have tried many different ways but none seem to work. Please help!

Public Class frmCostaLot
Dim MonthlyUsages(11) As Single
Private Sub lstUsageAmount_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstUsageAmount.SelectedIndexChanged

End Sub

Private Sub btnEnterUsages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterUsages.Click
    Dim usages As Integer
    For usages = 0 To 11
        MonthlyUsages(usages) += InputBox("Please enter a monthly usage value")
    Next
End Sub

Private Sub btnShowUsages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowUsages.Click
    Dim usages As Integer
    For usages = 0 To 11
        lstUsageAmount.Items.Add(MonthlyUsages(usages))
    Next

End Sub

Edited by LFCDay123: It was wrong

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by ChrisPadgham
0

What ways have you tried? It helps is to know everything otherwise we'll just tell you to try the same stuff over and over...

Did you try testing the value entered in the keypress event?

0

You can use the isnumeric function

do 
   MonthUsage = InputBox("Please enter a monthly usage value")
   if not isnumeric(MonthUsage) then msgbox "Please enter numbers only"
until isNumeric(MonthUsage)
MonthlyUsages(usages) += val(MonthUsage)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.