Solved

C to VB.Net Conversion Issue

Posted on 2013-06-19
3
210 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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