• Welcome to Valhalla Legends Archive.
 

Need help Converting

Started by Imperceptus, October 21, 2004, 05:32 PM

Previous topic - Next topic

Imperceptus

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

Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

Imperceptus

#1
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.
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

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

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
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

TangoFour

Isn't the entire point of .NET not having to convert?

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
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

Don't call them "scripts."  They are not "scripts."  Call them "modules," "classes," "types," or "assemblies."
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Imperceptus

Ok, thanks, noted.  should I refer to types as structures instead?
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

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)

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.