Solved

C to VB.Net Conversion Issue

Posted on 2013-06-19
3
208 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
Comment Utility
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
Comment Utility
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
Comment Utility
Nevermind, got it!!

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

Thanks!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now