Form does not run

mak2gd

Member
Joined
Jul 9, 2005
Messages
15
Location
Hartford, USA
Programming Experience
5-10
Form does not run (Resolved)

Hi,
I have this program as a windows application.

This is the form and the controles on it:


'*******************************************
Public
Class frmCalc
Inherits System.Windows.Forms.Form

Dim ValueOne AsLong

Dim ValueTwo AsLong

Dim Sign AsString

PrivateSub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click

If Sign = "" Then

ValueOne = ValueOne & 2

Else

ValueTwo = ValueTwo & 2

EndIf

EndSub

PrivateSub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click

Sign = "-"

EndSub

PrivateSub btnZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZero.Click

If Sign = "" Then

ValueOne = ValueOne & 0

Else

ValueTwo = ValueTwo & 0

EndIf

EndSub

PrivateSub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

txtValues.Text = ""

EndSub

PrivateSub btnNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNine.Click

If Sign = "" Then

ValueOne = ValueOne & 9

Else

ValueTwo = ValueTwo & 9

EndIf

EndSub

PrivateSub frmCalc_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load

EndSub

PrivateSub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

Sign = "/"

EndSub

PrivateSub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click

EndSub

PrivateSub btnEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEight.Click

If Sign = "" Then

ValueOne = ValueOne & 8

Else

ValueTwo = ValueTwo & 8

EndIf

EndSub

PrivateSub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click

Sign = "*"

EndSub

PrivateSub btnSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeven.Click

If Sign = "" Then

ValueOne = ValueOne & 7

Else

ValueTwo = ValueTwo & 7

EndIf

EndSub

PrivateSub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click

If Sign = "" Then

ValueOne = ValueOne & 1

Else

ValueTwo = ValueTwo & 1

EndIf

EndSub

PrivateSub btnFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFour.Click

If Sign = "" Then

ValueOne = ValueOne & 4

Else

ValueTwo = ValueTwo & 4

EndIf

EndSub

PrivateSub btnThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThree.Click

If Sign = "" Then

ValueOne = ValueOne & 3

Else

ValueTwo = ValueTwo & 3

EndIf

EndSub

PrivateSub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click

Sign = "+"

EndSub

PrivateSub btnFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFive.Click

If Sign = "" Then

ValueOne = ValueOne & 5

Else

ValueTwo = ValueTwo & 5

EndIf

EndSub

PrivateSub btnSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSix.Click

If Sign = "" Then

ValueOne = ValueOne & 6

Else

ValueTwo = ValueTwo & 6

EndIf

EndSub

PrivateSub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click

End

EndSub

PrivateSub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click

txtValues.Text = Operate(Sign, ValueOne, ValueTwo)

EndSub

End
Class




'***********************************************************
'This is the Module

Module Module1

Sub Main()

EndSub

PublicFunction Operate(ByVal op AsString, ByVal a AsDouble, ByVal b AsDouble) AsDouble

SelectCase op

Case "+"

Return a + b

Case "-"

Return a - b

Case "*"

Return a * b

Case "/"

Return a / b

EndSelect

EndFunction

End
Module


'**********************************************
When I click run, the form starts and stops very quickly. A picture of the form is attached.
Can you please help.
Thanks
 

Attachments

  • FormCalc.jpg
    FormCalc.jpg
    21 KB · Views: 39
Last edited:
You need to be a bit careful with your terminology. A form doesn't start and stop. Do you mean that when you run your application it starts and exits without ever displaying the form? If that is the case, I'd say that it's because you have set Sub Main to be the startup object but you have no code in the procedure. When you run the application the Main procedure is called , but there is no code in it to execute so it completes and the program exits. I'd suggest you do away with that module altogether. Just set your form to be the startup object and make the Operate function a private member of the form.

For future reference, please do not include the auto-generated code unless there is a specific need to do so. Also, please use the appropriate button in the editor to enclose you code in
VB.NET:
 tags.  This will make your code easier to read and increase the likelyhood of people helping you.  Personally, I would not normally take the time to read the amount of code you have posted.  It was only because the problem was easy to spot that I answered.

Keep on coding.
 
Your assumption is correct. Thank you for the advise and sorry about the boat load of code that I posted. I did select all and did not verify the post. Your suggestion worked great. It seems like I have other issues but this one is resolved.

Thanks again.
 
Glad to help. If you have other questions, do start new threads to ask them. Let me offer a few bits of advice here, though.

First of all, I'd go to the project properties and set Option Strict to On. This forces you to make any conversions explicit. It means writing a very little more code, but it means that you are aware of every place that a conversion is occurring and you can fix the ones that need it and allow the ones that should be. I mention this because you are passing two Long variables to a function that has Double arguments. Not a big deal, especially for an app like this, but it's best to get into good habits now before it is a big deal.

I'd also tend to create an enumerated type for your operators rather than using a string. You have only a few predefined values, which is the ideal situation for an enumeration. Do a help search to find out how.
 
Back
Top