• 0

VB 2010 Homework Question


Question

Hey Everyone -

I am taking an intro class to VB and we are working on the Light Bulb project (some of you may have heard of it). Essentially the way it works is you click on a picture of a light bulb to "turn it on" and you get a message that tell you to turn it off, so you click it again to turn it off and the process restarts. It's setup so that you can change the color of the output text (which I have working) and I also have the concatenation working, but not tied to the light bulb yet.

Unfortunately, the text book for this course is EXTREMELY vague with respect to the project, so if you're stuck; like me, well, you're on your own. I've done some Google searches and I found a blog from someone who did this project, but their code in my opinion is less than stellar, it just doesn't make sense because it appears that some of the methods she used, we haven't learned yet.

Anyway, on to my problem. I have the light bulb working (sort of). When I run the program within VB to debug the program starts with the light off, which is what it's supposed to do, you can click it again and it turns on, which is what it's supposed to do, however, when you click it again to turn it back off, it just disappears completely and you can't get it back without exiting and re-running the project. I know it's something I'm missing in the code (obviously), but what it is that I am missing, I haven't a clue. I've read the chapter backwards and forwards and I'm not seeing what I am missing. I am sure it's mentioned, but probably only in passing or in a very small paragraph. It mentioned concatenation in this manner, I had to figure it out by trial and error.

Is anyone familiar with this project or program? I don't have it with me currently, but I can email it (or attach it to this post) to whomever might be willing to help me out if you need to see the project or code. We haven't gotten into If, then, else statements or anything like that, so I'm pretty sure there is another method to get this working correctly.

Any help anyone can provide would be greatly appreciated.

Thanks!

Link to comment
https://www.neowin.net/forum/topic/1134522-vb-2010-homework-question/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Hey Everyone -

I am taking an intro class to VB and we are working on the Light Bulb project (some of you may have heard of it). Essentially the way it works is you click on a picture of a light bulb to "turn it on" and you get a message that tell you to turn it off, so you click it again to turn it off and the process restarts. It's setup so that you can change the color of the output text (which I have working) and I also have the concatenation working, but not tied to the light bulb yet.

Unfortunately, the text book for this course is EXTREMELY vague with respect to the project, so if you're stuck; like me, well, you're on your own. I've done some Google searches and I found a blog from someone who did this project, but their code in my opinion is less than stellar, it just doesn't make sense because it appears that some of the methods she used, we haven't learned yet.

Anyway, on to my problem. I have the light bulb working (sort of). When I run the program within VB to debug the program starts with the light off, which is what it's supposed to do, you can click it again and it turns on, which is what it's supposed to do, however, when you click it again to turn it back off, it just disappears completely and you can't get it back without exiting and re-running the project. I know it's something I'm missing in the code (obviously), but what it is that I am missing, I haven't a clue. I've read the chapter backwards and forwards and I'm not seeing what I am missing. I am sure it's mentioned, but probably only in passing or in a very small paragraph. It mentioned concatenation in this manner, I had to figure it out by trial and error.

Is anyone familiar with this project or program? I don't have it with me currently, but I can email it (or attach it to this post) to whomever might be willing to help me out if you need to see the project or code. We haven't gotten into If, then, else statements or anything like that, so I'm pretty sure there is another method to get this working correctly.

Any help anyone can provide would be greatly appreciated.

Thanks!

Paste the code!

  • 0

This will give you an infinite loop of on then off


Dim x as integer
x = 1
Do until x = 2 'Notice that the variable never changes
LightBulb.Visiible = Not LightBulb.visible 'Assuming the "Light Bulb" is a control such as a image
MessageBox.Show("Click to change light")
Loop
[/CODE]

  • 0

You sure that code works at all?

Visible is spellt visiible at the beginning (two i's after the s).

Why are you changing the visibility of the control?

Surely you want to change the image it shows instead.

Lastly, forms based applications are event based, and an infinite loop is a bad idea....

  • 0

pes2013 - 10 minutes for you perhaps. Understand that I am a beginner and am just starting out, so some actual help would be appreciated if you can provide it. This class I am taking assumes no prior knowledge of programming. I have very little with the exception of some Access databases that I wrote.

Kalint - I'll paste my code when I get near my computer. I've included the link to the what the project should do below. When you see my code, it is not complete, so you will see some issues with it. But most of the stuff is working with the exception of the light bulb not working as intended and the text not displaying when you click on the bulb. But I haven't programmed that part into it yet.

The way it works is there are two picture boxes one on top of the other. One box shows the bulb off, the other shows it on. So when you click on it repeatedly, it makes it look like it's turning on and off. And then when clicking it a message displays. Basically turning the light off gives a message that tell you to turn it on and vice versa. The problem is when I try to go from on to off, the control disappears completely. As I said, the book is VERY vague in my opinion.

Here is a link to what it does. This is the link I mentioned in my OP. Her code is a little messy, which I am assuming is the result of the website trying to format it in a way that it's not supposed to and because of that I am having trouble picking out the relevant pieces to get this working right. But this is the actual project.

http://www.healthandhometopics.com/2011/07/visual-basic-7-light-bulb-project/

  • 0
The way it works is there are two picture boxes one on top of the other. One box shows the bulb off, the other shows it on. So when you click on it repeatedly, it makes it look like it's turning on and off. And then when clicking it a message displays. Basically turning the light off gives a message that tell you to turn it on and vice versa. The problem is when I try to go from on to off, the control disappears completely. As I said, the book is VERY vague in my opinion.
The issue is probably that the "On" picture box is set to invisible, but the "Off" picture box is not set back to visible, so none of them display.
  • 0

Here is my code. I almost have it. Now I have the light turning on, but it won't turn off and I have the text properly displaying with the light.

' Project: The Clicker

' Programmer: Me

' Date: February 2, 2013

' Description: Allows the user to click on a light bulb and display user specific messaging.

Public

Class MainForm

Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click

' Print the form in the Print Preview window.

PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview

PrintForm1.Print()

End Sub

Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

' End the program.

Me.Close()

End Sub

Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged

' Concatenate user name in the message box.

MessageBox.Text = "Turn the light on, " & NameTextBox.Text

End Sub

Private Sub BlackRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlackRadioButton.CheckedChanged

' Change the text color to black.

MessageBox.ForeColor = Color.Black

End Sub

Private Sub BlueRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlueRadioButton.CheckedChanged

' Change the text color to blue.

MessageBox.ForeColor = Color.Blue

End Sub

Private Sub RedRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedRadioButton.CheckedChanged

' Change the text color to red.

MessageBox.ForeColor = Color.Red

End Sub

Private Sub GreenRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GreenRadioButton.CheckedChanged

' Change the text color to green.

MessageBox.ForeColor = Color.Green

End Sub

Private Sub LightOnPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOnPictureBox.Click

' Turn the light on.

MessageBox.Text = "Turn the light off, " & NameTextBox.Text

LightOffPictureBox.Visible = True

LightOnPictureBox.Focus()

End Sub

Private Sub LightOffPictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LightOffPictureBox.Click

' Turn the light off.

MessageBox.Text = "Turn the light on, " & NameTextBox.Text

LightOnPictureBox.Visible = False

LightOffPictureBox.Focus()

End Sub

End Class

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Close, but it is for any application starting, not just during boot time. In fact, it probably will not improve boot time at all because during a boot, the CPU is already boosting, so a pre-boost wouldn't change anything. I agree that it isn't exciting (especially considering every other OS already does it), but it is a good thing, even if they are just playing catch up.
    • Any so called performance increase will be in milliseconds, which nobody will actually notice in real world usage.
    • All it does is use the CPU more efficiently during boot to speed up boot times. That's it. Yawn....
    • It's not a one or the other kind of thing. Software should run efficiently, and the operating system should appropriately manage the CPU clocks. You could have the best most optimized software on earth, and it will still run faster if the CPU does a better job of boosting as needed. All this is doing is pre-boosting the CPU based on user actions, instead of waiting for the normal detection mechanism to kick in. If the OS knows it is about to need more CPU, why shouldn't it use that knowledge? It's the same idea of downshifting before passing someone, instead of just burying your foot into the peddle and waiting for the transmission to figure out what you want to do.
    • Audacity 3.7.8 by Razvan Serea Audacity is a free, open source digital audio editor and recording application. Edit your sounds using cut, copy, and paste features (with unlimited undo functionality), mix tracks, or apply effects to your recordings. The program also has a built-in amplitude-envelope editor, a customizable spectrogram mode, and a frequency-analysis window for audio-analysis applications. Built-in effects include bass boost, wah wah, and noise removal, and the program also supports VST plug-in effects. You can use Audacity to: Record live audio. Record computer playback on any Windows Vista or later machine. Convert tapes and records into digital recordings or CDs. Edit WAV, AIFF, FLAC, MP2, MP3 or Ogg Vorbis sound files. AC3, M4A/M4R (AAC), WMA and other formats supported using optional libraries. Cut, copy, splice or mix sounds together. Numerous effects including change the speed or pitch of a recording. Write your own plug-in effects with Nyquist. And more! See the complete list of features. Audacity 3.7.8 changelog: #10688 Fixed an exception thrown when pasting into a newly-created track (Thanks, David Bailes (@DavidBailes)!) #10870, #10884, #10775, #10629 Fixed tone generation, waveform-scale setting, SetClip Name parameter, and clip-boundary command names for scripting and macros (Thank you, David Bailes (@DavidBailes)!) #11106 Fixed the loading of presets for the Distortion effect (A million thanks, David Bailes (@DavidBailes)!) #10947 Fixed paste into an empty audio track not preserving the source sample rate (Thanks, Juan Gabriel Colonna (@juancolonna)!) #10776 Allowed AltGr modifier in label and clip name editing (Thanks, Davide Peressoni (@DPDmancul)!) #9938 Added options to choose where silence is truncated (start/middle/end) (Thanks, Noah Rosenfield (@nosenfield)!) #9935 Added Podcast 2.0 chapters JSON export for label tracks (Thanks, Noah Rosenfield (@nosenfield)!) #10103 Improve UI on HiDPI displays on Linux/wxGTK (Thanks, Ivan A. Melnikov (@iv-m)!) #10099 Fixed MixerBoard Mute and Solo button display (Thanks, Ivan A. Melnikov (@iv-m)!) #10681 Fixed multichannel FLAC import #10999 Fixed envelope being broken after joining clips Download: Audacity 64-bit | Standalone ~20.0 MB (Open Source) Download: Audacity 32-bit | Standalone Download: Audacity ARM64 | Standalone View: Audacity Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Year In
      slackerzz earned a badge
      One Year In
    • One Year In
      highriskpaym earned a badge
      One Year In
    • One Month Later
      highriskpaym earned a badge
      One Month Later
    • Week One Done
      highriskpaym earned a badge
      Week One Done
    • Week One Done
      FBSPL earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      500
    2. 2
      PsYcHoKiLLa
      198
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      84
    5. 5
      ATLien_0
      71
  • Tell a friend

    Love Neowin? Tell a friend!