mans.joling

Automation template problem

Discussion created by mans.joling on Jul 22, 2010
Latest reply on Jul 28, 2010 by Andreas.Schaefer

Hi

 

I have this code and I get a error if I want to know the procject.pcb name

Any idea?

 

Public Class FrmGrassValleyOutput
    Dim ProjectName As String
    Dim PrjPath As String
    Dim Gencadfile As String = "Gencad.cad"
    Public app As MGCPCB.ExpeditionPCBApplication
    Public Doc As MGCPCB.Document

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        MGCPCB_Disconnect()

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        MGCPCB_Connect()
            End Sub

    Private Sub MainForm_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        End
    End Sub
    Private Sub btnFulloutput_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFulloutput.Click
        System.Diagnostics.Process.Start("C:\Wdir\Gencad.exe")
        ProjectName = Projectfile(Doc)
        MsgBox(ProjectName)
     End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
        Me.Close()
    End Sub

'=======================================================================================
    Public Function Projectfile(ByVal doc)
        Dim sTmp, sTemp As String
        Dim StartPos, CharCount, MyLen, StrPos As Integer
        sTmp = doc.FullName    <======================I get here a error : NULLreferenceException was unhandled
        StrPos = InStr(sTmp, "\PCB\")
        '    MsgBox(StrPos)
        '    MsgBox(sTmp)
        MyLen = Len(sTmp)
        If MyLen = 43 Then
            StartPos = StrPos + 5
            CharCount = 9
            sTemp = Mid(sTmp, StartPos, CharCount)
            Projectfile = sTemp
            '     MsgBox(sTemp)
        Else
            Projectfile = "Projectfile not found"
        End If
    End Function
End Class

Outcomes