Question

Thank you to the ones who have tried to help me and I apologize for having...

Thank you to the ones who have tried to help me and I apologize for having to repost this question. I'm having a hard time trying to comprehend coding. I am supposed to code a joke and punchline. The joke is:"why did the chicken cross the road?" And the punchline is: "The hen got on its nerves." Or any answer will do actually. I have two labels and one button to make it run. If anyone can help me understand this in the simplest way, it would be greatly appreciated. What is the simplest way to write this code and understand what to do? Thank you. Oh, I am coding this in Visual Basics.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

IDE requirement for project Visual Studio

Step 1:

Create a new Project

Start Visual Studio and select File->New project. From the new project dialog select Windows Application and name the project chickenroad (or any other name as you like) and click on Ok to create the new project. Once the new project is created, Visual Studio will display a blank form ready for us to design the user interface of the application

Step 2:

Add all the required GUI controls to the Form

For our project,we are going to add three controls to our form:a button and two labels by dragging them into our form from the toolbox.The toolbox is present at the left side of visual studio main windowwhich looks like the one shown below.It contains all the GUI eleements required to build an application.The tools are categorised into groups based on their functionality and purpose

Visual studio toolbox.jpg

To add a label to the form, click on the Label control in the Toolbox, drag it to the center of the Form and release the mouse button. The new label will then appear in the Form.Use the mouse to move the controls around the Form and place in the required position.Similarly add another label to the form.

Next we need to add a button. Grab a Button from the Toolbox and drag and drop it on the Form.Place the button at any convenient place in the form as shown below

Form1 Label1 Label2 Buttonl X

Step 3:

Changing the controls of the properties:

Now after adding the controls to the form,we can see that all the controls placed in the form have their default names like Label1,Label2,Label3..... and Button1,Button2,Button3..... etc.,

In order to customise them,we need to change the properties of the controls with their corresponding property sheet which can be accessed at the bottom right of the visual studio main window.

It provides a facility to alter the properties of a control by changing color,font,text size,text etc., as shown below:

Visual studio properties.jpg

Now , change the label1's text as : "Why did the chicken cross the road ?" and label2's text as "?????" and button's text as "Know Why ???"

Form1 Why did the chicken cross the road? ??? Know why ??? X

Step 4:

Adding an event handler to the button

Now, we come to actual coding part which is very simple and requires only a few lines of code of which most of it was readily generated automatically when we perform an action on the control during the design time.

In order to add click control on the button,simply double click on it to enter the code view of the project where we get navigated to the event handler section of the button which will look like the following:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
                Handles closeButton.Click

    End Sub

Now add a line of code before the End Sub statement for the above code as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
                Handles closeButton.Click
          Label.setText("Because,The hen got on its nerves")
    End Sub

Now save the project

Step 5:

Running the application:

In order to run the application , click on the run(play) button in the visual studio tool bar on the top of the main window.Alternatively you can press F5 key to compile and run the code

After the compilation , a window will appear just like what we have designed earlier as shown below:

Form1 Why did the chicken cross the road? ??? Know why ??? X

Now click on "Know why ??? " button to view the punch line

The screen shot after clicking the button is shown below:

Form1 Why did the chicken cross the road? Becaus e,The hen got on its nerves Know why ??? X

Explanation:

After clicking the botton ,the event will take place by generating an object which will be causing the code in the event handler to run.In our code the label2's earlier value "???" will be changed to "Because,The hen got on its nerves".

Add a comment
Know the answer?
Add Answer to:
Thank you to the ones who have tried to help me and I apologize for having...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT