VB6 - Property let, Event and '\' - c# how?

chuawenching

Regular
Joined
Jul 26, 2003
Messages
66
Hi there.

I had 3 questions to ask.

1)

Public Event ButtonClicked(MessageBoxNumber As Integer, OKButton As Boolean, CancelButton As Boolean, ExitButton As Boolean)

--> how to code this in c#? If not mistaken, if they used the keyword WithEvent i will use delegates and events. But now is the keyword event! Any sample codes base on top?

2)

Public Property Let MessageBoxPrompt(MessageBoxNumber As Integer, ByVal vData As String)
MBox(MessageBoxNumber).Prompt = vData
End Property

MBox is a type of MessageBox

--> oh okay, i know c# got get and set, but there is no let. And can i assign property with arguments like MessageBoxNumber as integer, etc...

3) in vb6, you had in operator '\' for division integer, how can i achieve this in c#?

Any help, please?

Thanks.

Regards,
Chua Wen Ching :p
 
For 1, do you want to know how to declare the event, raise the event, hook the event, or all three?

For 3, all division by integers is, by default, rounded down (just like \). If you do division by anything other than integers, you convert the result to an Int (System.Convert.ToInt32() for example), which will round down automatically (I believe). What kind of math are you trying and what are you getting vs. what you expect?

-Nerseus
 
i expect integers...

yeah for the 1st one, how to do all those three...

for number 2, is it possible to show me some codes...

i try to code it...

but got problem..

once i do this...

the types explained above of MessageBox, i declare as Struct

MessageBox == SmallWindow.. something like that

Code
====
private struct SmallWindowType
{
public string Prompt;
public string Title;
public float X1;
public float Y1;
public float BoxWidth;
public float BoxHeight;
public float BorderColor;
public float BoxColor;
public float TextColor;
public float TitleColor;
public bool OKButton;
public bool CancelButton;
public float ButtonColor;
public float ButtonBorderColor;
public float ButtonTextColor;
public bool Clicked;
public bool Grabbed;
public float TmpX;
public float TmpY;
}

....

private SmallWindowType[] SM = new SmallWindowType[10];

public string SmallWindowPrompt(int SmallWindowNumber, string vData)
{
get
{
return this.SM[SmallWindowNumber];
}
set
{
SM[SmallWindowNumber] = vData;
}
}


When i tried to code the set thing, there is compilation errors.. it expects a semicolon behind get and set. I think my method declaration got problems.

Until now i seen property, they normall:

private Font Haha
{
get{}
set{}
}

and NOT

private string haha(int a, int b)
{
get {}
set {}
}

Any help?

For the third one, do you mean i use back '/' but convert the results into integer?

Thanks.

Regards,
Chua Wen Ching :p
 
So where will i place this:

ByVal vData As String ?

should it be in

public string SmallWindowPrompt(int SmallWindowNumber, string vData) -> ???

Thanks.

Regards,
Chua Wen Ching :p
 
Hmm.. ok...

but isn't missing of string vData, does it not affect my outcome of my project...

hmm.. maybe i am not good in property...

mind you tell me, why i should i ignore it!

Thanks.. thanks a lot.

Regards,
Chua Wen Ching :p
 
under C# all property set functions get an implicit parameter just called value, this will be whatever data is assigned to the property.

edit - typo
 
Last edited:
Have you read the help for the events? You have to declare an event interface (what the function, or the handler of the event, will look like) first, then raise the event in code. To hook an event, you need to add an event handler. If you've ever added an event to a control (like a Button's Click event), you can see the syntax by looking at the automatically generated code (look for "+=" in code).

I'd read up on events, delegates and such before you worry about coding events.

-Nerseus
 
Back
Top