Solved

C to VB.Net Conversion Issue

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

The problem is this line:

C Code:
--------
  public MainForm()
        {
            InitializeComponent();

            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()
	InitializeComponent()

	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)))
            Return
        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
        tbRawLog.ScrollToCaret()
        '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()
                Else
                    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")
                Else
                    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"
                Else
                    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 + " "
                    Next
                Else
                    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
                    DrawGSV()
                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

0
Comment
Question by:K-9
  • 2
3 Comments
 
LVL 42

Accepted Solution

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

	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

0
 

Author Comment

by:K-9
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 vb.net
0
 

Author Comment

by:K-9
ID: 39259543
Nevermind, got it!!

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

Thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 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