Results 1 to 10 of 10

Thread: Line numbers

  1. #1
    Join Date
    May 2003
    Location
    UK
    Posts
    28

    Unanswered: Line numbers

    I have a database where i would like to put line numbers in the code to use in error handling.

    Does anyone know how i can go about doing this?
    How is it that the compiler distinguishes between the code and the line number?

    Thanks

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Line numbers

    Originally posted by Mara
    I have a database where i would like to put line numbers in the code to use in error handling.

    Does anyone know how i can go about doing this?
    How is it that the compiler distinguishes between the code and the line number?

    Thanks
    We're not in GW BASIC any more ....

  3. #3
    Join Date
    May 2003
    Location
    UK
    Posts
    28

    Re: Line numbers

    Originally posted by M Owen
    We're not in GW BASIC any more ....
    Ive seen seen it done in VB and an wondering why it cant be done in VBA
    Im going to show my ignorance now and ask what is GW Basic?

  4. #4
    Join Date
    Jun 2003
    Location
    Belgium
    Posts
    133
    Useable in VBA :
    instead of line numbers, you can name different parts of your code. Something like this :

    Part1:
    code
    code
    code
    code

    Part2:
    code
    code
    If ..... Then GoTo Part1
    If ..... Then GoTo EndCode

    Part3:
    code
    code

    EndCode:
    Exit Sub
    Last edited by Herman; 01-30-04 at 05:00.

  5. #5
    Join Date
    May 2003
    Location
    UK
    Posts
    28
    Originally posted by Herman
    Useable in VBA :
    instead of line numbers, you can name different parts of your code. Something like this :

    Part1:
    code
    code
    code
    code

    Part2:
    code
    code
    If ..... Then GoTo Part1
    If ..... Then GoTo EndCode

    Part3:
    code
    code

    EndCode:
    Exit Sub
    Currently im using a similar format, something like:

    function abc
    on error goto ErrCode
    abc=false

    strErr="code a"
    code...
    strErr="code b"
    code...

    ExitCode:
    abc=true
    Exit Function

    ErrCode:
    errorhandler("function abc", strErr)
    exit Function
    end function

    I just wanted to provide greater detail than is given by using error strings and didnt want to have to set this variable for every line of functional code

    Thanks though
    Last edited by Mara; 01-30-04 at 05:13.

  6. #6
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Just a note:
       A good programmer who never use GOTO line number

  7. #7
    Join Date
    May 2003
    Location
    UK
    Posts
    28
    I just want line numbers to tell me exactly which line the error occured,
    and yes goto line number isnt the best but

    'on error goto errcode '

    shouldnt count

  8. #8
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    If you just want to know where the error occurs, just remark the ON Error statement, and the program run will stop at the line, where the error occures and make a yellow line.

  9. #9
    Join Date
    May 2003
    Location
    UK
    Posts
    28
    Thanks, this will be helpfull when debugging in development.

    The core problem im trying to solve is that i have some databases that are rather complex and not entirely stable.

    Occasionaly different data conditions cause errors in unexpeced parts of the application, in the live environment. As the databases are secured and users have no access to the backend/code they are presented with a error message telling them the function and error message, this allows me to save a bit of time finding the problem.

    If i could include the line number in the message that they get it would save me even more time when faced with a problem

    Any suggestions please

  10. #10
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    In your function, when you do error handling, put a statement telling you that the error occured in tht function. Example


    Function CSQLDate(varDate As Variant) As String
    'This funktion changes any given date format to a string that used in the SQL-Statment,

     On Error GoTo CSQLDate_Error

      If IsDate(varDate) Then
        CSQLDate = "#" & Month(varDate) & "/" & Day(varDate) & "/" & Year(varDate) & "#"
       Else
        CSQLDate = ""
       End If

    CSQLDate_Exit:
       Exit Function

    CSQLDate_Error:
       'MsgBox "Fehler bei Datumskonvertierung: " & Error$, vbOKOnly + vbInformation, "CSQLDate"
       MsgBox "Error " & Err.number & " in an Date conversion function: " & vbNewLine & " " & Err.number & " " & Err.Description & vbNewLine & "Called from: " & vbNewLine & vbNewLine & _
    "CSQLDate ([" & varDate & "])", vbOKOnly + vbInformation, "CSQLDate (.)"


       Resume CSQLDate_Exit
    End Function



    Hope this would help you.
    Form more info look up the ERR object and its methods and properties such as Err.source and Err.Rais

    Good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •