Using Case Select statement for beginners’ user Command Button – Visual Basic

Today I will share it to you another project in visual basic. This project is very easy to do if you know how to use Case Select statement. But if now, in this project you are going to learn using it, just follow the steps and procedures below!

The Case:
Weight (gram) Cost
0 - 50 1.4
51 - 100         2.7
101 - 250         4
251 - 500        7.5
The exceeding weight from 501 – up will be multiplied by 0.020.

In this project you are going to create a FRAME, 3 LABELS, A TEXTBOX, and A COMMAND BUTTON. Just look like the screenshot below. You can create your own if you want but if you want to follow my own work, also you can.

Don’t forget to rename your object in order your program works properly. I hope you know how to rename the object but if not you can go to Prefix Abbreviations for control names for your reference.

After you done creating those object I’ll mentioned and its looks like the screenshot above, you can go now to the coding.

To add the code, 
1. Simply Double Click the CALCULATE Command Button
2. Add the following code:
Dim Weight As Integer

Weight = txtweight

Select Case Weight
    Case Is <= 50
    lblamount = 1.4
    Case Is <= 100
    lblamount = 2.7
    Case Is <= 250
    lblamount = 4
    Case Is <= 500
    lblamount = 7.5
    Case Else
    lblamount = Weight * 0.02
       
End Select

3. After you add the code, test your program by pressing F5 key.
4. Enter an Integer in your Textbox and click Calculate
5. Once your program is working, your program looks like the screenshot below.
6. If you see that the screenshot is looks like with yours, Congratulations! You made it.
I hope it help to those beginners who want to know visual basic using Case Select Statement.
Related Posts Plugin for WordPress, Blogger...

1 comment:


  1. Admin, if not okay please remove!

    Our facebook group “selfless” is spending this month spreading awareness on prostate cancer & research with a custom t-shirt design. Purchase proceeds will go to cancer.org, as listed on the shirt and shirt design.

    www.teespring.com/prostate-cancer-research

    Thanks

    ReplyDelete

Thanks for Commenting us, your comments are highly appreciated!