Car travel expences

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 767 Views - Last Post: 30 December 2012 - 06:18 AM Rate Topic: -----

#16 soraali20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 24-December 12

Re: Car travel expences

Posted 29 December 2012 - 10:17 AM

Hi I am trying to add amend button in to my program I need to allow the user to cancel a journey that they have claimed for e.g. it is not an allowable claim. Again, I need arrays/records to be able to do this

Dim index As Integer
Dim sngtotal As Single
Dim strdestenation As String
' Determine which product is to be amended
index = lstDestination.SelectedIndex
' Get the new name and price
strdestenation = txtDestination.Text
sngtotal = CSng(txtTotal.Text)
' and store them back in memory
sngtotals(index) = sngtotal
lstDestination.Items(index) = strdestenation
btnamend.Enabled = False
End Sub
Was This Post Helpful? 0
  • +
  • -

#17 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3449
  • View blog
  • Posts: 11,696
  • Joined: 12-December 12

Re: Car travel expences

Posted 29 December 2012 - 10:23 AM

What precisely is the problem you are having with your code and what error message(s) do you receive?

Please wrap your code in CODE tags. Select the code and press the [ CODE ] button (without the spaces).
Was This Post Helpful? 1
  • +
  • -

#18 soraali20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 24-December 12

Re: Car travel expences

Posted 29 December 2012 - 10:47 AM

the error i am getting is Index was outside the bounds of the array.

Dim index As Integer
Dim sngtotal As Single
Dim strdestenation As String
' Determine which product is to be amended
index = lstDestination.SelectedIndex
' Get the new name and price
strdestenation = txtDestination.Text
sngtotal = CSng(txtTotal.Text)
' and store them back in memory
sngtotals(index) = sngtotal
lstDestination.Items(index) = strdestenation
btnamend.Enabled = False



Dim index As Integer
Dim sngtotal As Single
Dim strdestenation As String
' Determine which product is to be amended
index = lstDestination.SelectedIndex
' Get the new name and price
strdestenation = txtDestination.Text
sngtotal = CSng(txtTotal.Text)
' and store them back in memory
sngtotals(index) = sngtotal
lstDestination.Items(index) = strdestenation
btnamend.Enabled = False
End Sub

Was This Post Helpful? 0
  • +
  • -

#19 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3449
  • View blog
  • Posts: 11,696
  • Joined: 12-December 12

Re: Car travel expences

Posted 29 December 2012 - 10:59 AM

Where is your declaration for sngtotals?

Arrays can default to being indexed from 1, whereas the SelectedIndex from a ListBox is indexed from 0. So sngtotals(0) may not exist.
Was This Post Helpful? 1
  • +
  • -

#20 soraali20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 24-December 12

Re: Car travel expences

Posted 29 December 2012 - 07:05 PM

Hello I am doing a quick program and i am tying to use add,amend and delete button but I am having an error when I am trying to delete the records and when I click the amend button it does not update it
"InvalidArgument=Value of '-1' is not valid for 'index'.
Parameter name: index "

Public Class Form1
    ' Global variables are accessible to all event handlers 
    Dim sngPrices(20) As Single
    Dim nProducts As Integer

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        ' Add the product name to the list box... 
        lstProducts.Items.Add(txtProduct.Text)
        ' and the price to the array 
        sngPrices(nProducts) = CSng(txtprice.Text)
        nProducts = nProducts + 1
        txtProduct.Clear()
        txtprice.Clear()
    End Sub

    Private Sub lstProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstProducts.SelectedIndexChanged
        Dim index As Integer
        index = lstProducts.SelectedIndex
        ' Get and display the product details 
        txtProduct.Text = lstProducts.Items(index)
        txtprice.Text = Format(sngPrices(index), "#0.00")
        ' The product can be amended  
        btnAmend.Enabled = True
    End Sub

    Private Sub btnAmend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAmend.Click
        Dim index As Integer
        Dim sngPrice As Single
        Dim strName As String
        ' Determine which product is to be amended 
        index = lstProducts.SelectedIndex
        ' Get the new name and price 
        strName = txtProduct.Text
        sngPrice = CSng(txtprice.Text)
        ' and store them back in memory 
        sngPrices(index) = sngPrice
        lstProducts.Items(index) = strName
        btnAmend.Enabled = False
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        ' Determine which product is to be deleted 

        Dim i, itemNo As Integer
        itemNo = lstProducts.SelectedIndex
        ' Display an error if no product is selected 
        If itemNo = -1 Then
            MsgBox("Please select an item")
            Exit Sub
        End If
        ' Delete the name from the list box 
        lstProducts.Items.RemoveAt(itemNo)
        ' Delete the price from the prices array 
        For i = itemNo To nProducts - 2
            sngPrices(i) = sngPrices(i + 1)
        Next
        nProducts = nProducts - 1
        txtprice.Clear()
        txtProduct.Clear()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Initially we have no products 
        nProducts = 0
        btnAmend.Enabled = False
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#21 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3449
  • View blog
  • Posts: 11,696
  • Joined: 12-December 12

Re: Car travel expences

Posted 30 December 2012 - 06:18 AM

You need to investigate debugging in Visual Studio. Set a breakpoint, examine the variables, step through the code.. You won't get far in VB.Net without this knowledge.

As well as the error message, you should also indicate what line triggered the error.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2