Hi there,

I'll try to be brief, In short im trying to add together a variable, (name = STRFinValue) within a For loop, I think the syntax should be:

STRTotal = STRFinValue +STRFinValue(f)

But I am very wrong.

Private Sub btnLBTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLBTotal.Click

        Dim STR As String
        Dim Position As Integer
        Dim STRLength As String
        Dim STRValue As Integer
        Dim STRStart As Integer
        Dim STRFinValue As Decimal
        Dim STRToString As String
        Dim STRTotal As Decimal

        For f = 0 To (ListBox1.Items.Count - 1)

            STR = ListBox1.Items.Item(f)   
            Position = InStr(1, STR, "£", 0) 

            If Position > 0 Then

                STRLength = STR.Length.ToString()

                STRStart = (Convert.ToInt32(STRLength)) - ((Convert.ToInt32(STRLength)) - (Convert.ToInt32(Position)))

                STRToString = STR.Substring(STRStart)                  

                STRFinValue = (Convert.ToInt64(STRToString))

                For counter As Integer = 0 To (ListBox1.Items.Count - 1)

                    STRTotal = STRFinValue + +(STRFinValue) 
                    counter = counter + 1


                TextBox1.Text = Convert.ToString(STRTotal)


                MsgBox("Didn’t find £ sign.")
            End If



    End Sub

Please do let me know if I have posted something in the wrong fashion & if I have not explained myself well.

Thanks for your time - is appreciated.

8 Years
Discussion Span
Last Post by lloydy76

Well. This line STRTotal = STRFinValue + +(STRFinValue) basically says that during the iteration STRTotel is always going to be 2 = 1 + 1 .
If you want STRTotal to change then STRFinValue needs to change inside the iteration.
Or do this: STRTotal += (STRFinValue + STRFinValue) .
This will allow STRTotal to "remember" and increase it's current value with STRFinValue + STRFinValue.

Edited by Oxiegen: n/a

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.