get error messages or notes persistent

3 posts / 0 new
Last post
CB's picture
CB
Offline
Joined: 10/19/2012 - 04:54
get error messages or notes persistent

if you are testing macros in idea or if a macro is rolled out you maybe want
error messages an things like this persistent.

also if you have messages in your script that should inform the user what is going on
you maybe do not want a showstopper like a msgbox...

so just try something like this:

@brian:
-------
please format the code ;)

main
----

Sub Main

          'declaration
          Dim a As Integer
          Dim b As Integer
                   
          a = 0
          b = 1

          If a <> b Then
         
                    'the information sArg1 and sArg2 will be inserted in the ProtTable
                    sArg1 = "Modul ABC"
                    sArg2 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, ..."         
                   
                    Client.RunIDEAScriptEx "protTable.ISS", sArg1, sArg2, "", ""         
         
          End If
         

End Sub

protTable.iss:
--------------
Sub Main

          'declaration
          Dim sModulText As String
          Dim sDescription As String
          Dim sProtTable  As String
         
          sModulText = ""
          sDescription = ""
          sProtTable = ""
         
          sModulText = arg1
          sDescription = arg2
         
         
          ' does the protTable exists?
          sProtTable = Dir(Client.WorkingDirectory + "ProtTable.imd")
                   
          If iIsBlank(sProtTable) = 1 Then

                    'if it does NOT exists:         

                    '01. create table
                    '-------------
                              Dim NewTable As Table
                              Set NewTable = Client.NewTableDef
         
                              ' create first column:
                                        Dim AddedField As Field
                                        Set AddedField = NewTable.NewField
                                        AddedField.Name = "modul"
                                        AddedField.Type = WI_CHAR_FIELD
                                        AddedField.Length = 500
                              ' add first column.
                                        NewTable.AppendField AddedField

                              ' create second column:
                                        Set AddedField = NewTable.NewField
                                        AddedField.Name = "description"
                                        AddedField.Type = WI_CHAR_FIELD
                                        AddedField.Length = 500                   
                              ' add second column         
                                        NewTable.AppendField AddedField         
                   
                              ' create third column
                                        Set AddedField = NewTable.NewField
                                        AddedField.Name = "timestamp"
                                        AddedField.Type = WI_CHAR_FIELD
                                        AddedField.Length = 500                   
                              ' add third column         
                                        NewTable.AppendField AddedField                   
         
                              ' disable tables write protection
                              NewTable.Protect = False                   
         
                              ' create table
                              Dim db As Database
                              Set db = Client.NewDatabase("ProtTable.IMD", "", NewTable)         

                    '02. insert data into table
                    '--------------------
                              Dim rs As RecordSet
                              Set rs = db.RecordSet

                              ' new data set
                              Dim rec As Record
                              Set rec = rs.NewRecord
                             
                              ' insert data
                              rec.SetCharValue "Modul", sModulText
                              rec.SetCharValue "Description", sDescription
                              rec.SetCharValue "Timestamp", Now()
                              rs.AppendRecord rec

                              ' enable tables write protection
                              NewTable.Protect = True
                             
                              'commit                             
                              db.CommitDatabase

                    '03. table column write protection
                    '---------------------------
                              Set table = db.TableDef
                             
                                        Set field = table.GetField("Modul")
                                        field.Protected = True
                             
                                        Set field = table.GetField("Description")
                                        field.Protected = True
                             
                                        Set field = table.GetField("Timestamp")
                                        field.Protected = True                                                           
                                                           
                    ' memory
                    '--------
                              Set field = Nothing
                              Set table = Nothing                   
                              Set db = Nothing
                              Set AddedField = Nothing
                              Set NewTable = Nothing
         
          Else
         
                    'if table exists
                   
                    '01. table instantiate
                    '----------------
                              Set db = Client.OpenDatabase ("ProtTable.IMD")         
                              Set table = db.TableDef
                   
                              'disable table protection
                              Table.Protect = False         

                    '02. insert additional data
                    '--------------------
                              Dim rs2 As RecordSet
                              Set rs2 = db.RecordSet

                              ' new data set
                              Dim rec2 As Record
                              Set rec2 = rs2.NewRecord
                             
                              ' insert data
                              rec2.SetCharValue "Modul", sModulText
                              rec2.SetCharValue "Description", sDescription
                              rec2.SetCharValue "Timestamp", Now()
                              rs2.AppendRecord rec2

                              ' enable tables write protection
                              Table.Protect = True
                             
                              'commit
                              db.CommitDatabase
                             
                    '03. table column write protection
                    '---------------------------
                              Set field = table.GetField("Modul")
                              field.Protected = True
                             
                              Set field = table.GetField("Description")
                              field.Protected = True
                             
                              Set field = table.GetField("Timestamp")
                              field.Protected = True                                                           
                             
                              db.Close
                                                           
                    ' memory
                    '--------
                              Set field = Nothing
                              Set table = Nothing                   
                              Set db = Nothing
                                                                                         
          End If
         
'refresh
Client.WorkingDirectory = Client.WorkingDirectory
End Sub

cheers,
chris

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

CB, thanks for sharing this script.  This is something that I could find really useful in the future.  What a great way to track errors.  You could probably also use it to track errors such as using this with the On Error function.

CB's picture
CB
Offline
Joined: 10/19/2012 - 04:54

hi brian,

that is right! in combination with the error handler it is also very useful... i combinate it with the on error function most time when i am testing..

but you could use this in many cases... and if the function of this script is not useful you have a nice snippet for create a table and insert data into this table... :-)

cheers,
chris