Valhalla Legends Forums Archive | .NET Platform | Need help Converting

AuthorMessageTime
Imperceptus
I am trying to learn how to convert c# to vb.net.  I am currently working on this
[code]
using System;
using Server.Network;


namespace Server.Misc
{
public class LoginStats
{
public static void Initialize()
{
// Register our event handler
EventSink.Login += new LoginEventHandler( EventSink_Login );
}

private static void EventSink_Login( LoginEventArgs args )
{
int userCount = NetState.Instances.Count;
int itemCount = World.Items.Count;
int mobileCount = World.Mobiles.Count;
int spellCount = Spells.SpellRegistry.Count;

Mobile m = args.Mobile;

m.SendMessage( "Welcome, {0}! There {1} currently {2} user{3} online, with {4} item{5} and {6} mobile{7} in the world.",
args.Mobile.Name,
userCount == 1 ? "is" : "are",
userCount, userCount == 1 ? "" : "s",
itemCount, itemCount == 1 ? "" : "s",
mobileCount, mobileCount == 1 ? "" : "s" );
}
}
}
[/code]

This is what I have come down to it in vb.net,  can anyone push me more in the right direction?  I am mainly having trouble with the event.
[code]Option Explicit

imports System
imports server.network
imports Microsoft.VisualBasic

namespace server.misc

Public Class LoginStats

Public Event Login(LoginEventHandler)

Public Sub New()
RaiseEvent Login(EventSink.Login)
End Sub

Private Sub EventSink_Login( Args as LoginEventArgs)

Dim usercount as integer : usercount = Netstate.Instances.Count
Dim itemcount as integer : itemcount = World.Items.Count
Dim mobilecount as integer :mobilecount = World.Mobiles.Count
Dim M as Mobile
Dim spellcount as integer : spellcount = Spells.SpellRegistry.Count
Dim fArray(3) as object
M = args.Mobile


Farray(0) = IiF(usercount =1, "is" ,"are")
Farray(1) = IiF(usercount = 1, "" ,"s")
Farray(2) = IiF(itemcount =1, "", "s")
Farray(3) = IiF(mobilecount =1, "", "s")
M.sendMessage("Welcome, " & args.mobile.name & "! There " & fArray(1) & " currently " & usercount & " user" & farray(1) & " online, with " & itemcount & " item" & farray(2) & " and " & mobilecount & " mobile" & farray(3) & " in the world.")

End Sub
End Class
End NameSpace
[/code]
October 21, 2004, 10:32 PM
Imperceptus
wow add events,  sorry for the needless post, grok said to post solutions.

[code]
Option Explicit

imports System
imports server.network
imports Microsoft.VisualBasic

namespace server.misc

Public Class LoginStats

Public Event LoginEventHandler(EventSink_Login)

Public Sub New()
AddHandler EventSink.Login, AddressOf EventSink_Login

End Sub

Private Sub EventSink_Login( Args as LoginEventArgs)

Dim usercount as integer : usercount = Netstate.Instances.Count
Dim itemcount as integer : itemcount = World.Items.Count
Dim mobilecount as integer :mobilecount = World.Mobiles.Count
Dim M as Mobile
Dim spellcount as integer : spellcount = Spells.SpellRegistry.Count
Dim fArray(3) as object
M = args.Mobile


Farray(0) = IiF(usercount =1, "is" ,"are")
Farray(1) = IiF(usercount = 1, "" ,"s")
Farray(2) = IiF(itemcount =1, "", "s")
Farray(3) = IiF(mobilecount =1, "", "s")
M.sendMessage("Welcome, " & args.mobile.name & "! There " & fArray(1) & " currently " & usercount & " user" & farray(1) & " online, with " & itemcount & " item" & farray(2) & " and " & mobilecount & " mobile" & farray(3) & " in the world.")

End Sub
End Class
End NameSpace
[/code]

add handler saved the day.
October 21, 2004, 10:57 PM
Imperceptus
Final Revision.

For some reason, Sub New didnt work like I read it would.  Instead Public Shared Sub Initialize()  was used.  Public Sub Initialize() will fail on most 1.1 framework from what I have seen.

here what works
[code]
Imports System
Imports Server.Network
Imports Microsoft.VisualBasic


Namespace Server.Misc
 
  Public Class LoginStats
     
      Public Shared Sub Initialize()
        ' Register our event handler
        AddHandler EventSink.Login, AddressOf EventSink_Login
      End Sub 'Initialize
     
     
      Private Shared Sub EventSink_Login(args As LoginEventArgs)
        Dim userCount As Integer = NetState.Instances.Count
        Dim itemCount As Integer = World.Items.Count
        Dim mobileCount As Integer = World.Mobiles.Count
        Dim spellCount As Integer = Spells.SpellRegistry.Count
       
        Dim m As Mobile = args.Mobile
       
        m.SendMessage("Welcome to Ytenie, {0}! There {1} currently {2} user{3} online, with {4} item{5} and {6} mobile{7} in the world.", args.Mobile.Name, IIf(userCount = 1, "is", "are"), userCount, IIf(userCount = 1, "", "s"), itemCount, IIf(itemCount = 1, "", "s"), mobileCount, IIf(mobileCount = 1, "", "s"))
      End Sub
  End Class
End Namespace
[/code]
October 22, 2004, 5:46 PM
TangoFour
Isn't the entire point of .NET not having to convert?
October 22, 2004, 7:20 PM
Imperceptus
yup, but there is a problem in that with what I am doing.  Run UO loads the c# before the vb.net, so if i want to use vb.net and reference the c# no problem, but if i want to use c# to reference vb.net it will not becuase of the load order.  That is why I am converting some of the scripts.  LoginStats.CS was the original cs file.  It has no other c# files that depend on its output, so I could freely change it.  and have it reference other things that happen on login that I will write in vb.net
October 22, 2004, 7:26 PM
Myndfyr
Don't call them "scripts."  They are not "scripts."  Call them "modules," "classes," "types," or "assemblies."
October 23, 2004, 8:52 AM
Imperceptus
Ok, thanks, noted.  should I refer to types as structures instead?
October 23, 2004, 6:23 PM
TangoFour
An integer is a type but not a structure, so no (by standard terminology, not sure about .NET, most I ever did with .NET was load Visual Studio)
October 23, 2004, 6:46 PM
Myndfyr
[quote author=TangoFour link=topic=9270.msg85801#msg85801 date=1098557193]
An integer is a type but not a structure, so no (by standard terminology, not sure about .NET, most I ever did with .NET was load Visual Studio)
[/quote]

Uh, actually, an integer is both a type and a structure.  An integer is a value type, which means that when it is used as a parameter its value is copied and passed via the stack, as opposed to a reference type (a class), which means that when it is used as a parameter, the reference to the object is passed via the stack.
October 23, 2004, 8:23 PM

Search