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) 
Then

            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

                Next

                TextBox1.Text = Convert.ToString(STRTotal)

                

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

            

        Next


    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.

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 6 Years Ago by Oxiegen: n/a

This article has been dead for over six months. Start a new discussion instead.