Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Imperceptus on October 21, 2004, 05:32 PM

Title: Need help Converting
Post by: Imperceptus on October 21, 2004, 05:32 PM
I am trying to learn how to convert c# to vb.net.   I am currently working on this

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" );
}
}
}


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.
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

Title: Re: Need help Converting
Post by: Imperceptus on October 21, 2004, 05:57 PM
wow add events,  sorry for the needless post, grok said to post solutions.


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


add handler saved the day.
Title: Re: Need help Converting
Post by: Imperceptus on October 22, 2004, 12:46 PM
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

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
Title: Re: Need help Converting
Post by: TangoFour on October 22, 2004, 02:20 PM
Isn't the entire point of .NET not having to convert?
Title: Re: Need help Converting
Post by: Imperceptus on October 22, 2004, 02:26 PM
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
Title: Re: Need help Converting
Post by: MyndFyre on October 23, 2004, 03:52 AM
Don't call them "scripts."  They are not "scripts."  Call them "modules," "classes," "types," or "assemblies."
Title: Re: Need help Converting
Post by: Imperceptus on October 23, 2004, 01:23 PM
Ok, thanks, noted.  should I refer to types as structures instead?
Title: Re: Need help Converting
Post by: TangoFour on October 23, 2004, 01:46 PM
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)
Title: Re: Need help Converting
Post by: MyndFyre on October 23, 2004, 03:23 PM
Quote from: TangoFour on October 23, 2004, 01:46 PM
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)

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.