dcsimg
Results 1 to 7 of 7

Thread: VBA (VB6) Telemetry - Test if this works in vb6

  1. #1

    Thread Starter
    Addicted Member Davor Geci's Avatar
    Join Date
    Sep 2009
    Posts
    198

    Red face VBA (VB6) Telemetry - Test if this works in vb6

    Hey guys,
    I have created a small utility tool for VBA (Excel, Access, Word,.. ) but would like to know if this also works in vb6.

    Are you for a test?

    If it works also in vb6, then it will enable us to, with only 1 line of code, track errors, events, metrics right from vb6 apps with help from Microsoft Azure - Application Insights.

    In one sentence: If you are familiar with Facebook Pixel or Google Analytics, then you know what I’m talking about, this is similar but for your vb6 apps (if it will work).

    Here is a short video how this error tracking works in VBA (Excel):
    https://youtu.be/6MUUXdmTWTY

    And here is the detailed step by step guide how to setup in VBA (Excel):
    https://www.vbatelemetry.com/full-gu...cel-workbooks/

    In theory it should work also in vb6. Only thing that I can see is one code block.

    Code:
    #If VBA7 Then
        Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    #Else
        Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    #End If
    but we can replace this with:
    Code:
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Here is the Excel VBA project. For this to work you also need to download a small client app from my site (it is free), and to setup your free Azure account (If you don't have one). Short steps are explained in the Excel Workbook.

    TrackError Simple Sample.zip

    If you still have vb6 on your machine, I would be very gratefull if you could test it and comment here on anything.

    Thanks, Davor
    My projects:
    Virtual Forms
    VBA Telemetry

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    why would I release a program with error's to track error's ?

    this doesn't make sence

    regards
    Chris

  3. #3

    Thread Starter
    Addicted Member Davor Geci's Avatar
    Join Date
    Sep 2009
    Posts
    198

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    Hehe, Chris
    First, thank you for your comment.

    No,no, let me explain a little bit more.

    Microsoft Azure - Application Insights is used for collecting telemetry data from servers, webpages, .NET applications,...

    Data like Page visits, Errors, Events, Custom Metrics.

    I have created a utility that brings this features to VBA projects (like Excel Workbooks, Access projects, Word documents, Powerpoint presentations, ....) and if we could make it work, also we could use this in vb6.

    So if a developer wants to track his application, for example:

    1. Track a specific Event, for example Workbook Open event, he puts 1 line of code into Workbook_Open event:
    Code:
    Private Sub Workbook_Open()
    
        TrackEvent "WorkbookOpen"
        
    End Sub
    Or if you want to track Workbook_BeforeClose event:
    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        
    
        TrackEvent "WorkbookBeforeClose"
        
        Flush
        
    End Sub
    And if you have installed on your users computer the VBA Telemetry client (for example you include it with your installation package). This VBA Telemetry client sends this data to your Azure portal, and you can see it.

    Name:  Application Insight Events.jpg
Views: 239
Size:  24.2 KB
    Name:  Application Insights Events2_.jpg
Views: 225
Size:  27.8 KB


    2. Track Errors. In your desktop appplication you have your Error Handling routines. If you want to see this errors in real time, exactly when they occur, in your Azure portal then you can insert 1 line of code into your error handler (TrackError) for example:

    Code:
    Error_Handler:
        MsgBox Err.Description, vbCritical
       
        TrackError Err.Description, Err.Number, "CommandButton1_Click"
    If there is the VBA Telemetry client installed on this computer and you put this line of code into your error handler:
    Code:
    TrackError Err.Description, Err.Number, "CommandButton1_Click"
    You will see this error in your Azure portal in real time, exactly when it occurs.

    Name:  ApplicationFrameHost_2017-07-26_20-12-18.jpg
Views: 215
Size:  29.0 KB
    Name:  ApplicationFrameHost_2017-07-26_20-15-49.jpg
Views: 218
Size:  27.5 KB
    Name:  ApplicationFrameHost_2017-07-26_20-17-17.jpg
Views: 222
Size:  28.7 KB
    My projects:
    Virtual Forms
    VBA Telemetry

  4. #4
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    Quote Originally Posted by Davor Geci View Post
    Hehe, Chris
    First, thank you for your comment.

    No,no, let me explain a little bit more.

    Microsoft Azure - Application Insights is used for collecting telemetry data from servers, webpages, .NET applications,...

    Data like Page visits, Errors, Events, Custom Metrics.

    I have created a utility that brings this features to VBA projects (like Excel Workbooks, Access projects, Word documents, Powerpoint presentations, ....) and if we could make it work, also we could use this in vb6.

    So if a developer wants to track his application, for example:

    1. Track a specific Event, for example Workbook Open event, he puts 1 line of code into Workbook_Open event:
    Code:
    Private Sub Workbook_Open()
    
        TrackEvent "WorkbookOpen"
        
    End Sub
    Or if you want to track Workbook_BeforeClose event:
    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        
    
        TrackEvent "WorkbookBeforeClose"
        
        Flush
        
    End Sub
    And if you have installed on your users computer the VBA Telemetry client (for example you include it with your installation package). This VBA Telemetry client sends this data to your Azure portal, and you can see it.

    Name:  Application Insight Events.jpg
Views: 239
Size:  24.2 KB
    Name:  Application Insights Events2_.jpg
Views: 225
Size:  27.8 KB


    2. Track Errors. In your desktop appplication you have your Error Handling routines. If you want to see this errors in real time, exactly when they occur, in your Azure portal then you can insert 1 line of code into your error handler (TrackError) for example:

    Code:
    Error_Handler:
        MsgBox Err.Description, vbCritical
       
        TrackError Err.Description, Err.Number, "CommandButton1_Click"
    If there is the VBA Telemetry client installed on this computer and you put this line of code into your error handler:
    Code:
    TrackError Err.Description, Err.Number, "CommandButton1_Click"
    You will see this error in your Azure portal in real time, exactly when it occurs.

    Name:  ApplicationFrameHost_2017-07-26_20-12-18.jpg
Views: 215
Size:  29.0 KB
    Name:  ApplicationFrameHost_2017-07-26_20-15-49.jpg
Views: 218
Size:  27.5 KB
    Name:  ApplicationFrameHost_2017-07-26_20-17-17.jpg
Views: 222
Size:  28.7 KB
    I don't mean to be rude, I looked at this quite a bit , but I just can't see any benefit in this,
    or I am just missing the Point and can't see it.

    regards
    Chris

  5. #5
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    Quote Originally Posted by ChrisE View Post
    I don't mean to be rude, I looked at this quite a bit , but I just can't see any benefit in this,
    or I am just missing the Point and can't see it.

    regards
    Chris
    Application Metrics. What is used most often, what's a typical workflow, catch crashes and system configurations in real time.
    How long do operations take on most machines. etc. it goes on an on.

    Small apps won't see a benefit.

  6. #6

    Thread Starter
    Addicted Member Davor Geci's Avatar
    Join Date
    Sep 2009
    Posts
    198

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    It's ok Chris you're not rude.

    I will tell you my story why in the first place I created this. (For easier following I added subheaders into this post).

    The story behind VBA Telemetry Client

    I'm in software development business almost for 2 decades now. And in this years I learned that creating a killer application is only the first part of software development. The next very important one is the support.

    Having angry customers is the most painful thing that your company will eventually experience. It is only a matter of time when this will happen.

    And if your software is in the finance segment, and work with other people's money, then an error in your code will not only angry your customer, but it can also cause great problems for both, him and you (No matter how good your EULA is, or how many lawyers you have).

    Error handling is a very important thing in any developers code. Logging the errors to a file, displaying the error message, this are all good approaches. But......

    If we are in serious software development business then we know how a conversation with a user is going to be when he/she is trying to explain what's going on when an error occurs.

    I know, there are programmers that are saying that their code works without errors (Yes of course).

    The Past and the Present

    In the past I have used tons of methods to deal with errors, from logging to a file, taking the auto screenshots, sending auto emails,.....

    But with .NET we have this thing called Application Insights (there are thousands of similar solutions on the Internet, but Microsoft is for now the solution that I prefer). It is a Microsoft Azure cloud application that enables us to track what is going on in our mobile, web, server or client applications.

    Because in the last years my company concentrates on building solutions in VBA, so I wanted to bring this to VBA users.

    Out of the box Application Insights (and the Hockeyapp team) they support many of platforms, but not the VBA and VB6, I contacted with them, and they don't support this platforms.

    The Birth of VBA telemetry client

    So we created a small tool that connects the VBA (or (I hope) VB6) with the Application Insights client located in the .NET framework.

    We call it VBA Telemetry client.

    This is a small dll that enables us to send some data to the Microsoft Azure - Application Insights resource (to the cloud), right from VBA (and/or VB6).

    What does it do

    When you install this small dll (called VBA telemetry client) on your or your users machine you can use the functions that this dll provides.

    There are (for now) 5 main functions or subs that we can use:
    TrackError, TrackEvent, TrackMetric, TrackPageView and Flush

    If we put TrackError into our error handler code, and when this sub is triggered, it sends the error data to our Azure portal. We can see this error data almost in real time in our Applicaton Insights resource in our Azure portal
    TrackError sends the Error number, Error description, and a small description, for example the procedure name.
    Example:
    Code:
    TrackError Err.Description, Err.Number, "CommandButton1_Click"

    If we put TrackEvent, for example at the beginning of our subs, or functions we not only can see how many times the procedure has been triggered and from what user (it sends a lot of data about the user machine by default computername, country, town, IP, OS version, ....), but also when the error is triggered we can follow the full stack or the path before the error has happend.
    Example:
    Code:
    TrackEvent "CommandButton1_Click"

    We can use TrackMetric to, for example, to track the duration of a code block execution, or to pass some metrics with the name and value
    Example:
    Code:
    TrackMetric "Loop1Duration", 100
    The TrackPageView we can use to track the form load events
    Example:
    Code:
    TrackPageView "FormCalculationOpen"
    And at the end there is a Flush function. Because the AI does not send the data immediately, but it stores it in memory and sends them from time to time (from few seconds, to a minute or two). We need to add this Flush before we exit our app so that the VBATelemetry client & Application Insight client can flush (or send) the rest of the data before we exit.

    Help modules

    But to make it even easier for my developers to use this I also created 2 modules.
    One module that holds the variables and one that simplifies the usage and calling the functions.

    modVBATelemetryFunctions

    I have break this into 2 modules to simplify the updates to functions that are stored in modVBATelemetryFunctions.mod
    So when I make some changes to this functions or add new functions or subs, they only need to replace this module.
    Also if you take a look into the subs and functions in this module (modVBATelemetryFunctions.mod) you will see that I initialize the dll everytime from beggining. This is because in VBA the user can switch between Design and runtime mode, and when he do that all the object get destroyed.

    And I use late binding so that if on this machine the client (the dll) is not installed there are no resource errors raised.

    modVBATelemetryVariables

    As I said to to simplify the updates there is this second module.
    Here are variables that we need to setup to be able to use this Application Insights.

    We can have a new resource (new project) in our portal, Application Insights, for every application we want to track.
    To identify the different projects (or resources) in Application Insights, the AI gives us the "Instrumentation Key", we simply copy it from AI to this module. And our app now knows to which AI resource to send the data to.

    There is also the "VBA Telemetry Key"
    As you know we all work to bring food to table for our family.
    So there is a free version of this little dll. So you can use all functions and subs, no time limit.
    Only thing that separates the free from commercial is that sometimes in free version a function is called it pops up a message box where is says that this is a free version.

    So to remove this message box get your VBA Telemetry key. One Telemetry Key for one Instrumentation key, and it is a simbolic one time payment.
    But if you don't bother the message box, you can use it for ever.

    Question
    Is it a little bit clearer now? No problem, if is not just drop the question here.

    Davor
    My projects:
    Virtual Forms
    VBA Telemetry

  7. #7
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,428

    Re: VBA (VB6) Telemetry - Test if this works in vb6

    Thanks DEX and Davor

    now it's more clear

    regards
    Chris

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width