iOS Question for next with step -1 problem

Discussion in 'iOS Questions' started by tufanv, Apr 1, 2015.

  1. tufanv

    tufanv Expert Licensed User

    Hello

    I have a strange problem with for next step -1
    Code:

    Dim n As Int =0

    For i=listcevap.Size-1 To (listcevap.Size-TextField1.Text.Length) Step -1

    If listcevap.Get(i) = TextField1.Text.CharAt(n) Then
    listsonuc.Add("1")
    Else
    'Exit
    End If

    next

    Now listcevap.size is 12. and textfield1.text.length is 4
    so for next is between i=11 to 8 step -1

    but during wathcing the logs i see that b4i first gets i=8 than 9 than 10 than 11 instead of first 11 than 10 than 9 than 8 (while geting the values of list )

    What am i doing wrong ? I am about to go mad about this.
     
  2. klaus

    klaus Expert Licensed User

    Strange !
    I tried a simple For i = 11 To 4 Step -1 loop and it works as expected.
    Can you post a small project showing the problem.
     
  3. tufanv

    tufanv Expert Licensed User

    yes sure one moment please
     
  4. tufanv

    tufanv Expert Licensed User

    I tried to create a small project it works perfect on it but in my real project it works as i wrote previously. Interesting, I cant find the problem
     
  5. klaus

    klaus Expert Licensed User

    Add a breakpoint just before the For loop and go through the code step by step.
    You may also put Logs showing the values of listcevap.Size and TextField1.Text.Length.
     
    tufanv likes this.
  6. tufanv

    tufanv Expert Licensed User

    Yes i found the problem. Now the problem is for example textfield1.text.charat(1) = 3
    and listcevap.get(i) = 4
    i cant get the sum this two numbers it says "Error description: Cannot cast: {Type=Char,Rank=0, RemoteObject=True} to number."
    i think b4i sees one as number one as charachter. How can i make it see both of them as numbers so i can get the sum for example ?
     
  7. klaus

    klaus Expert Licensed User

    CharAt(1) returns a Char which you cannot use for arithmetic operations.
    Try to use
    Dim n = textfield1.Text.CharAt(1) As Int
    before calculating the sum.
     
  8. tufanv

    tufanv Expert Licensed User

    Dim y= textfield1.Text.CharAt(n) As Int gives the same error : "Error description: Cannot cast: {Type=Char,Rank=0, RemoteObject=True} to number."
     
  9. tufanv

    tufanv Expert Licensed User

    fixed the problem by :

    dim y as char = listcevap.get(i)

    so i compare two chars and if they are same it is enough for me. Thanks for all help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice