Question Converting from C# to VB.NET

mcb

New member
Joined
Mar 2, 2012
Messages
4
Programming Experience
Beginner
Hello,

Can someone please help me with this? Am pretty new in programming. I tried converting a C# code to VB.NET and it gives me this error.


A namespace cannot directly contain members such as fields or methods.

Thanks in Advance



Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms


Namespace UsedCarsSales
Public Partial Class frmSalesRep
Inherits Form
Public Sub New()
InitializeComponent()
End Sub


Public Sub EditSalesRep(salesRepID As Integer)
Try
Dim reader As New CSVReader()
Dim salesRep As SalesRep = reader.GetSalesRep().Where(Function(w) w.SalesRepID = salesRepID).FirstOrDefault()


txtfirstName.Text = salesRep.FirstName
txtLastName.Text = salesRep.LastName
txtID.Text = salesRep.SalesRepID.ToString()
dtStartDate.Value = Convert.ToDateTime(salesRep.StartDate)
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub




End Class
End Namespace
 
Try it with Partial Public Class frmSalesRep rather than the way you have it (although the VS IDE should have changed that for you - did when I just tested it)
 
Hello,

Thanks for your swift response. I changed that but it still gives me the same error. Am so confused at this point
 
Try it with Partial Public Class frmSalesRep rather than the way you have it (although the VS IDE should have changed that for you - did when I just tested it)

I got that working. However do you happen to know why i get this error?


Line 128 :

Public Event CheckedChanged(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.



'
Me.radioButtonVehicleSold.AutoSize = True
Me.radioButtonVehicleSold.Location = New System.Drawing.Point(175, 19)
Me.radioButtonVehicleSold.Name = "radioButtonVehicleSold"
Me.radioButtonVehicleSold.Size = New System.Drawing.Size(81, 17)
Me.radioButtonVehicleSold.TabIndex = 10
Me.radioButtonVehicleSold.TabStop = True
Me.radioButtonVehicleSold.Text = "VehicleSold"
Me.radioButtonVehicleSold.UseVisualStyleBackColor = True
Me.radioButtonVehicleSold.CheckedChanged += New System.EventHandler(AddressOf Me.radioButtonVehicleSold_CheckedChanged)
'
 
Last edited:
Please edit your post and encase your code in [ xcode=vb ] [ /xcode ] tags...


I tried to do that but it still seems same.. i will just shorten the code. Please do you have any idea what the problem is with the code?
 
Back
Top