Solved

Convert Short Class Code From C# to VB.NET

Posted on 2007-03-29
3
230 Views
Last Modified: 2010-08-05
Could someone help convert the following code into VB.NET so I can understand and use/extend it.

// Class to hold setting information
public class ClockSetting
{
    private int _someValue;public ClockSetting() { }
    public int SomeValue
    {
        get{ return _someValue; }
        set{ _someValue = value; }
    }
}

// This class inherits from ApplicationSettingsBase.
// The only property being persisted
// is a collection of ClockSetting objects.
// This allows the settings for each clock
// created by the user to be stored and loaded with minimal coding.
public class TimePieceSettings : ApplicationSettingsBase
{
    [UserScopedSetting()]
    public List<ClockSetting> ClockSettings
    {
        get { return (List<ClockSetting>)this["ClockSettings"]; }
        set { this["ClockSettings"] = (List<ClockSetting>)value; }
    }
}
// Loading the settings
_settings = new TimePieceSettings();
foreach (ClockSetting setting in _settings.ClockSettings)
{
    AddClock(setting);
}
//Saving the settings
foreach(Clock clock in _layoutPanel.Controls)
{
    ClockSetting instance = CreateSetting(clock);
    _settings.ClockSettings.Add(instance);
}
_settings.Save();
0
Comment
Question by:endrec
  • 2
3 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 18818091
0
 

Author Comment

by:endrec
ID: 18818272
These converters will not work on the code above.
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 18818568
The only thing the converters didn't like is the Generic Lists because of the < >

Here:

Public Class ClockSetting
    Private Integer _someValue
    Public  Sub New()
    End Sub
    Public Property SomeValue() As Integer
          Get
               Return _someValue
          End Get
          Set (ByVal Value As Integer)
               _someValue = value
          End Set
    End Property
End Class

public class TimePieceSettings Inherits ApplicationSettingsBase
<UserScopedSetting()>
Public Property ClockSettings As List(Of ClockSetting)
Get
Return (List(Of ClockSetting))this("ClockSettings")
End Get
Set (ByVal Value As List(Of ClockSetting))
this("ClockSettings") = value
End Set
End Property
End Class

Dim setting As ClockSetting
For Each setting In _settings.ClockSettings
    AddClock(setting)
Next
'Saving the settings
Dim clock As Clock
For Each clock In _layoutPanel.Controls
    Dim instance As ClockSetting =  CreateSetting(clock)
    _settings.ClockSettings.Add(instance)
Next
_settings.Save()

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to open Excel file 15 44
Get String split 5 33
install app on other machine 13 14
Closing all open child forms. 4 24
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

21 Experts available now in Live!

Get 1:1 Help Now