C to VB.Net Conversion Issue

Posted on 2013-06-19
Last Modified: 2013-06-19
Working on a program, I have code that is in C that I need in my program.  I used a converter but having issues..

The problem is this line:

C Code:
  public MainForm()

            Gps = new GpsHandler { TimeOut = 5 }; //Initialize GPS handler
            Gps.NewGpsFix += GpsEventHandler; //Hook up GPS data events to a handler
            FrmGpsSettings = new FrmGpsSettings();
        public static GpsHandler Gps;

Open in new window

It converts into this for VB.Net

Public Sub New()

	Gps = New GpsHandler() With { _
		Key .TimeOut = 5 _
	'Initialize GPS handler
	Gps.NewGpsFix += GpsEventHandler
	'Hook up GPS data events to a handler
	FrmGpsSettings = New FrmGpsSettings()
End Sub
Public Shared Gps As GpsHandler

Open in new window

The error is here:

Gps.NewGpsFix += GpsEventHandler
Argument not specified for parameter 'e' of 'Private Sub GpsEventHandler(sender As Object, e As Ares.SharperGps.GpsHandler.GpsEventArgs)'.

Here is the GpsHandler code.. I do get an error as well on the 'BeginInvoke' line (Expression does not produce a value error).

I can upload the whole source code if needed.

Private Sub GpsEventHandler(sender As Object, e As GpsHandler.GpsEventArgs)

        If InvokeRequired Then
            ' Execute the same method, but this time on the GUI thread
            BeginInvoke(New ThreadStart(Function() GpsEventHandler(sender, e)))
        End If
        tbRawLog.Text += e.Sentence + vbCr & vbLf
        If tbRawLog.Text.Length > 20 * 1024 * 1024 Then
            '20Kb maximum - prevents crash
            tbRawLog.Text = tbRawLog.Text.Substring(10 * 1024 * 1024)
        End If
        'Scroll to bottom
        Select Case e.TypeOfEvent
            Case GpsEventType.GPRMC
                'Recommended minimum specific GPS/Transit data
                If Gps.HasGpsFix Then
                    'Is a GPS fix available?
                    'lbRMCPosition.Text = GPS.GPRMC.Position.ToString("#.000000");
                    lbRMCPosition.Text = Gps.GPRMC.Position.ToString("DMS")
                    lbRMCCourse.Text = Gps.GPRMC.Course.ToString()
                    lbRMCSpeed.Text = Gps.GPRMC.Speed + " mph"
                    lbRMCTimeOfFix.Text = Gps.GPRMC.TimeOfFix.ToString("F")
                    lbRMCMagneticVariation.Text = Gps.GPRMC.MagneticVariation.ToString()
                    StatusBar1.Text = "No fix"
                    lbRMCCourse.Text = "N/A"
                    lbRMCSpeed.Text = "N/A"
                    lbRMCTimeOfFix.Text = Gps.GPRMC.TimeOfFix.ToString()
                End If
                Exit Select
            Case GpsEventType.GPGGA
                'Global Positioning System Fix Data
                If Gps.GPGGA.Position IsNot Nothing Then
                    lbGGAPosition.Text = Gps.GPGGA.Position.ToString("DM")
                    lbGGAPosition.Text = ""
                End If
                lbGGATimeOfFix.Text = Gps.GPGGA.TimeOfFix.Hour + ":" + Gps.GPGGA.TimeOfFix.Minute + ":" + Gps.GPGGA.TimeOfFix.Second
                lbGGAFixQuality.Text = Gps.GPGGA.FixQuality.ToString()
                lbGGANoOfSats.Text = Gps.GPGGA.NoOfSats.ToString()
                lbGGAAltitude.Text = Gps.GPGGA.Altitude & " " & Gps.GPGGA.AltitudeUnits
                lbGGAHDOP.Text = Gps.GPGGA.Dilution.ToString()
                lbGGAGeoidHeight.Text = Gps.GPGGA.HeightOfGeoid.ToString()
                lbGGADGPSupdate.Text = Gps.GPGGA.DGPSUpdate.ToString()
                lbGGADGPSID.Text = Gps.GPGGA.DGPSStationID
                Exit Select
            Case GpsEventType.GPGLL
                'Geographic position, Latitude and Longitude
                lbGLLPosition.Text = Gps.GPGLL.Position.ToString()
                lbGLLTimeOfSolution.Text = (If(Gps.GPGLL.TimeOfSolution.HasValue, Gps.GPGLL.TimeOfSolution.Value.Hours + ":" + Gps.GPGLL.TimeOfSolution.Value.Minutes.ToString() + ":" + Gps.GPGLL.TimeOfSolution.Value.Seconds.ToString(), ""))
                lbGLLDataValid.Text = Gps.GPGLL.DataValid.ToString()
                Exit Select
            Case GpsEventType.GPGSA
                'GPS DOP and active satellites
                If Gps.GPGSA.Mode = "A"c Then
                    lbGSAMode.Text = "Auto"
                ElseIf Gps.GPGSA.Mode = "M"c Then
                    lbGSAMode.Text = "Manual"
                    lbGSAMode.Text = ""
                End If
                lbGSAFixMode.Text = Gps.GPGSA.FixMode.ToString()
                lbGSAPRNs.Text = ""
                If Gps.GPGSA.PRNInSolution.Count > 0 Then
                    For Each prn As String In Gps.GPGSA.PRNInSolution
                        lbGSAPRNs.Text += prn + " "
                    lbGSAPRNs.Text += "none"
                End If
                lbGSAPDOP.Text = Gps.GPGSA.PDOP + " (" + DOPtoWord(Gps.GPGSA.PDOP) + ")"
                lbGSAHDOP.Text = Gps.GPGSA.HDOP + " (" + DOPtoWord(Gps.GPGSA.HDOP) + ")"
                lbGSAVDOP.Text = Gps.GPGSA.VDOP + " (" + DOPtoWord(Gps.GPGSA.VDOP) + ")"
                Exit Select
            Case GpsEventType.GPGSV
                'Satellites in view
                If NMEAtabs.Text = "GPGSV" Then
                    'If NMEAtabs.TabPages(NMEAtabs.SelectedIndex).Text = "GPGSV" Then
                    'Only update this tab when it is active
                End If
                Exit Select
            Case GpsEventType.PGRME
                'Garmin proprietary sentences.
                'lbRMEHorError.Text = Gps.PGRME.EstHorisontalError.ToString()
                'lbRMEVerError.Text = Gps.PGRME.EstVerticalError.ToString()
                'lbRMESphericalError.Text = Gps.PGRME.EstSphericalError.ToString()
                Exit Select
            Case GpsEventType.TimeOut
                'Serialport timeout.
                StatusBar1.Text = "Serialport timeout"
                Exit Select
        End Select

    End Sub

Open in new window

Question by:K-9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 42

Accepted Solution

sedgwick earned 500 total points
ID: 39259405
Public Sub New()

	Gps = New GpsHandler() With { _
		Key .TimeOut = 5 _
	'Initialize GPS handler
	 AddHandler Gps.NewGpsFix, AddressOf GpsEventHandler 

	'Hook up GPS data events to a handler
	FrmGpsSettings = New FrmGpsSettings()
End Sub
Public Shared Gps As GpsHandler

Open in new window


Author Comment

ID: 39259528
Thank you for the quick response!  That cleared that error, what about this one?

BeginInvoke(New ThreadStart(Function() GpsEventHandler(sender, e)))
Expression does not produce a value.

I will be reading up on this, still an amateur with

Author Comment

ID: 39259543
Nevermind, got it!!

BeginInvoke(New ThreadStart(Sub() GpsEventHandler(sender, e)))


Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity sendkey 4 28
Starting to use Git with Visual  Studio Online 1 65
PowerShell: ForEach-Object Export to CSV 4 89
Need Help With GDI+ in VB.Net 8 32
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question