Re: vb .net newbie. I need to pass a variable to a form from my menu - How?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



No, I 've been working in Clarion but SoftVelocity is behind in bringing out
their .NET version. It's a GREAT tool but lagging a bit in this regard...
they say it's comming but not sure when it will be gold and I need it now.


I added the code but ran into an error:

StartBehaviourR, Q and S are not declared. I thought the Enum is the
delcaration for them.

Robert

Public Class frmRSQMain

Public Enum StartBehavior

StartBehaviorR

StartBehaviorS

StartBehaviorQ

End Enum

Public Sub New()

' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub

Public Sub New(ByVal behavior As StartBehavior)

I nitializeComponent()

Select Case behavior

Case StartBehaviorR <--------------- Error here

Me.Text = "Rental"

Me.GradientFormHeader1.DetailText = "Add, Modify Rentals..."

lblRSQNumber.Text = "Rental No."

lblRSQDate.Text = "Rental Date"

lblRSQNumber2.Text = "Rental No."

lblRSQStartDate.Text = "Rental Start"

lblSubTotal.Text = "Rental SubTotal"

btnRentalList.Text = "Rental List"

Case StartBehaviorQ <--------------- Error here

Me.Text = "Quote"

Me.GradientFormHeader1.DetailText = "Add, Modify Quote..."

lblRSQNumber.Text = "Quote No."

lblRSQDate.Text = "Quote Date"

lblRSQNumber2.Text = "Quote No."

lblRSQStartDate.Text = "Quote Start"

lblSubTotal.Text = "Quote SubTotal"

btnRentalList.Text = "Quote List"

Case StartBehaviorS <--------------- Error here

Me.Text = "Sales"

Me.GradientFormHeader1.DetailText = "Add, Modify Sales..."

lblRSQNumber.Text = "Sales No."

lblRSQDate.Text = "Sales Date"

lblRSQNumber2.Text = "Sales No."

lblRSQStartDate.Text = "Sales Start"

lblSubTotal.Text = "Sales SubTotal"

btnRentalList.Text = "Sales List"

End Select

End Sub



"rowe_newsgroups" <rowe_email@xxxxxxxxx> wrote in message
news:1183471044.840319.43680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 3, 9:50 am, "Robert Johnson" <johnso...@xxxxxxxxxxxxx> wrote:
Seth, Ok, I see what you are talking about. I sometimes forget that a
form
is just a class also...lol. Remember I said I was a newbie... I have been
working in another language for years but since .NET is where it's at
have
decide to take the leap.
Thanks for being patient with me

Regards,

Robert

"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1183425647.788930.6550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 2, 7:32 pm, "Robert Johnson" <johnso...@xxxxxxxxxxxxx> wrote:
If I understand you you are suggesting, this is to replace my code
that
calls the form? It looks like you are thinking of 3 seperate forms
where
I
am using just one form where I modify lables and fields where
necessary
in
the Load event. I have a If statement in the Load event that will
evaluate
the value of the var passed in if I can figure out how to pass it
in...
lol.
That is what I need to know. Or did I misunderstand you?

Robert

"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1183417330.554721.75030@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 2, 6:29 pm, "Robert Johnson" <johnso...@xxxxxxxxxxxxx> wrote:
Hi all. I have a multi-purpose form that I need to run various code
in
the
load event so I want to send a var string either "R" , "S" or "Q"
that
will
determine what code to run. I'm sure it's simple but I couldn't
find
any
examples in the doc's and books that I own.

Could someone give me an example please. This is a mdi child form.
I want to call it like this OpenRSQ(R) or OpenRSQ(S) etc...

Thanks in advance.

Robert

My code is currently:
Private Sub OpenRSQ()

Dim frmRSQ As New frmRSQMain

frmRSQ.MdiParent = Me

frmRSQ.Show()

End Sub

I would do it with an overloaded constructor (sub new) and use an
enum
to prevent passing incorrect values.

i.e.

Public Class MyForm

' I would highly recommend using more descriptive names
Public Enum StartBehavior
StartBehaviorR
StartBehaviorQ
StartBehaviorS
End Enum

Public Sub New()
' No parameters needed for instantiation
InitializeComponent()
End Sub

Public Sub New(ByVal behavior As StartBehavior)
InitializeComponent()

Select Case behavior
Case StartBehaviorR
' Do Something
Case StartBehaviorQ
' Do Something Else
Case StartBehaviorS
' You know the drill
End Select
End Sub

End Class- Hide quoted text -

- Show quoted text -

No, I'm talking about a singleform. The only difference is that I am
passing the parameter in the form's constructor instead of grabbing it
in the load event. Remember Load in an event, and is listened to by an
event handler who's signature is static, therefore you can't add
another parameter to it. You spoke of passing 3 possible commands (P,
Q, and S) to the form as a string, I replaced that as an enumeration
which is more efficient than using a string, and can be much easier to
maintain. I overloaded the constructor so it would not break your
existing code, but just extend your form class so that if you needed
to pass the extra information you could call the overloaded
constructor that has the enumeration parameter.

Thanks,

Seth Rowe

No problem - I'm guessing you're coming from classic Vb?

Thanks,

Seth Rowe



.



Relevant Pages