2 Replies - 986 Views - Last Post: 04 October 2013 - 04:28 PM Rate Topic: -----

#1 toradorw777   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 05-March 13

Problem debugging the code

Posted 04 October 2013 - 04:03 PM

I'm a little stumped here, I know I've done something wrong, but I don't know what. It's probably something very simple, but I'm a little rusty.

What I'm trying to do here is create a program that increases the numbers in the array by a user-entered percentage, and then increase each price by that amount and display the increased prices in the list box.

Here's the error's I'm getting:

  • Number of indices is less than the number of dimensions of the indexed array. Line 34, Column 40
  • Comma, ')', or valid expression continuation expected. Line 35, Column 46


There may be other problems that I'm not aware of, seeing as I haven't run the debug command yet.

Here's my code.

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub increaseButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles increaseButton.Click
        Static prices() As Decimal = {6.75, 12.50, 33.50, 10.00, 9.50, 25.50, 7.65, 8.35, 9.75, 3.50}
        Dim isconverted As Boolean
        Dim input As Decimal
        Dim counter As Integer

        For subscript As Integer = 0 To 9
            newListBox.Items.Add(prices(subscript))
        Next subscript

        isconverted = Decimal.TryParse(newListBox.Text, input)
        newListBox.Items.Clear()
        counter = 0

        For Each price As Decimal In prices

        Next
        If counter < 10 Then
            prices(0) = prices(1) + (prices(2) * (input / 100))
            newListBox.Items.Add(prices().ToString("C2"))
            prices(counter) = prices(counter += 1)
            counter += 1
        End If
    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Problem debugging the code

#2 andrewsw   User is offline

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6561
  • View blog
  • Posts: 26,600
  • Joined: 12-December 12

Re: Problem debugging the code

Posted 04 October 2013 - 04:08 PM

Which are lines 34 and 35 in your posted code - they obviously don't correspond.

You could take my debugging tutorial. Although.. the error messages seem pretty clear, particularly the second one.

This post has been edited by andrewsw: 04 October 2013 - 04:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6561
  • View blog
  • Posts: 26,600
  • Joined: 12-December 12

Re: Problem debugging the code

Posted 04 October 2013 - 04:28 PM

Anyway.. you can't do this (the increment) in VB:

prices(counter) = prices(counter += 1)

(a statement cannot be an expression)

The following statement is incorrect/invalid:

prices().ToString("C2")

A simple approach would be to loop through your prices array, adding them individually to the ListBox. Otherwise, you could investigate the AddRange method.

BTW With Option Strict On you should see lots of blue wavy lines where you have declared this array.

This post has been edited by andrewsw: 04 October 2013 - 04:31 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1