One of my stupid questions....

Discussion in 'Questions (Windows Mobile)' started by Cableguy, Jan 26, 2008.

  1. Cableguy

    Cableguy Expert Licensed User

    Hi guys, it's been a while since i've ben active in the forum, code wise....
    I'm stuck in a problem... I'm reading an ini file and have an eror label called "erro", wich gets called if there is any proble accesing the file...But how ca I call the errorlabel upon a condition?

    This is my code...
    Yes, I know i'm readding teh file 3 times before i use the data...
    it's my way of doing things...bare with me on this one..

    Code:
    Sub LoadINI
    ErrorLabel(erro)
    FileOpen(c,
    "LusiGES.ini",cRead)
    a=FileRead(c)
    a=FileRead(c)
    a=FileRead(c)
    Nome=StrRemove(a,
    0,5)
    'Here I want to test if the resulting string is equal to a known string (my own name), if not, then should be considered an invalid ini file, and jump to the error label.
    If Nome<>"Paulo Sérgio Gomes" Then ' then what??? 

    FileClose(c)
    Erro:
    Msgbox("Não foi possivel ler" & crlf & "o ficheiro LusiGes.ini","Erro de Leitura.",cMsgBoxOK,cMsgBoxExclamation)

    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You could use
    Code:
    If ... Then Goto Erro
     
  3. Cableguy

    Cableguy Expert Licensed User

    I tryied that, it errors sayin the the variable erro is used before assigned a value..
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I've tested it with this code and it doesn't give any error:
    Code:
    Sub LoadINI
    ErrorLabel(erro)
    FileOpen(c,
    "LusiGES.ini",cRead)
    a=FileRead(c)
    a=FileRead(c)
    a=FileRead(c)
    Nome=StrRemove(a,
    0,5)
    'Here I want to test if the resulting string is equal to a known string (my own name), if not, then should be considered an invalid ini file, and jump to the error label.
    If Nome<>"Paulo Sérgio Gomes" Then Goto Erro' then what??? 

    FileClose(c)
    Return
    Erro:
    Msgbox("Não foi possivel ler" & crlf & "o ficheiro LusiGes.ini","Erro de Leitura.",cMsgBoxOK,cMsgBoxExclamation)

    End Sub
     
  5. Cableguy

    Cableguy Expert Licensed User

    Sorry EREL, i'm too rusted....
    I was typing "go to" instead of goto....it's working now...
    Just one more "Stupid" question, to exit the sub before the error label gets executed.., I just tipe "exit", right?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Not so stupid. More of a common mistake.
    You should add Return before the error label.
     
  7. Cableguy

    Cableguy Expert Licensed User

    I know it probably woul be a lot worse, mistake wise, but woudn't it be more logical an "ExitSub" keyword?
     
  8. agraham

    agraham Expert Licensed User

    Don't forget that Subs can return values so that "Return var" is quite logical.
     
Loading...