I am a high school student living in Korea.
I came here because I had a problem while making a simple quiz program.
If the s value goes down below 0, I want to end the program.
So I wrote the code as shown in the photo, but the message "'break' outside loop" keeps popping up.
Should I use something other than 'break' to solve this problem?
I want to know what the problem is.
Related
I have code stuck.
It might be in an infinite loop.
Not sure.
Is there a way to break the program to stop at the current line of code that it is running on?
I'd like to avoid shutting down excel because I want to be able to catch where in the loop it is, and by going into the code, I will be able to tell how much processing was done. I would like to break into the code, if possible.
It is stuck on hour glass.
Ctrl+Break doesn't seem to work
Seems like the running code has hijacked all the quota that cpu is giving to excel.
If there is nothing I can do now, is there something in the future I can do to where I can more easily break into the code?
I'm thinking that an intermittent wait within a loop might be a feasible solution.
In the future, include a DoEvents inside the loop. It will run a little slower, but you will be able to use Ctrl+Break to stop it from running.
Create a progress dialog when entering the loop and include a Cancel button. Within your loop check for the Cancel signal/event. This also gives you some flexibility on how you react to the Cancel - you could stop the loop and display key information in a new dialog box (for example).
Basic steps to achieve what I have described (not necessarily the most elegant or the most re-useable, but simple enough for those of lesser experience):
create a modeless (not modal) Form with either suitable labels or a progressbar item (for
visual effect). Include a public property (Boolean) for Cancel (e.g.
boolCancel)
Place a button on form and onClick set boolCancel = True
In your main code, show the form just before your problem loop.
while in your loop you can update some label or progress bar on the
form so that you have a visual indication of whether the loop is
doing something of value or if it is now simply spinning its wheels.
How you do this depends on what your loop is doing.
Also while in your loop check your boolCancel value. If true then
display any state information you want and break from the loop.
If your loop ends normally, hide/unload the progress dialog.
So I'm relatively new to access and havent worked much in VBA. Im currently designing a project database for users at our office to submit ideas to.
I have a submission form and a few of the fields are required. In the code, I have it looking like this:
If IsNull(SchoolName) Then
DoCmd.OpenForm "MissingInfoForm"
Else
AssignmentStatus = "Unassigned"
LastEditedBy = apicGetUserName()
DoCmd.Save
MsgBox "Submission Accepted"
DoCmd.GoToRecord , , acNewRec
(I literally just threw this together. I normally just use macros when doing things, but I feel this issue will require use of VBA.)
The problem I'm facing is that when the user has failed to put anything into the field SchoolName, it will show the MissingInfoForm and revert back to the submission form but Access still saves and creates a new record with all blank fields (or partially completed, I need it to not save at all if the field SchoolName is blank). This is an issue because there is a hub form that lists all the entries and I cannot have a bunch of blank submissions there.
I tried making sure that the form's Close function doesnt save it but it continues to do so.
Ive looked quite a bit online for some help and I've found examples in the form of "A Better Mouse Trap" and the Me.Undo command, however I am unable to correctly implement these in the way I'd like.
Can someone lend me some assistance? Im a fairly big noob to this stuff and could use some guidance.. this project database is expected to be done by this Friday (2 days from now).
I'm a little stumped here. I'm diving deeper into designing ribbons for MS Word 2010, and I came across something new: populating comboboxes on the fly. In the image below, you can see...
...that I'm a dude who likes music while he works, just like any other dude. Problem is my list of playlists changes from time to time, so I don't want to hard-code that list into my ribbon's combobox. I can easily hard-code it, but I want this thing to be dynamic. And so, in my ribbon code:
<comboBox id="cmbPLaylist" label="Playlist" getItemLabel="Document_Open">
<item id="none" label="None"/>
</comboBox>
I have left only one item, "none," which is fine if I want the music player to launch with no playlist loaded. But what if I want a playlist to automatically load?
First, from my Google and book research, I've determined that I need to have a getItemLabel callback to populate the control. Is this the right way to go? But how do I run that automatically when my Normal.dotm loads? I'm having problems running this thing in the Document_Open event, and I've been reading online that I'm not alone.
My problem is a bit threefold: first, I'm really new at using these predefined callbacks like getEnabled, getItemLabel, etc. The callback territory is a very new territory for me. Second, I've never used a combobox in a ribbon before. Three, I've never dynamically populated a combobox in a ribbon before. I might be trying to bite off more than I can chew at once, but can anyone point me in the right direction?
My code so far, inserted into my Normal.dotm Document_Open event, is such:
Private Sub Document_Open(control As IRibbonControl, ByRef label)
Dim ListOfPlaylists() As String
ListOfPlaylists = GetPlaylists()
ListOfPlaylists(UBound(ListOfPlaylists)) = "Random"
End Sub
After this, I'm stumped. As you can see, I'm not sure how to tell MS Word, "Hey, MS Word, insert this value into the combobox list!"
Maybe it's my newbness at this whole thing, but when I Google for an answer, I'm not seeing it in the code. So any help is appreciated. Thanks!
I actually did some fiddling and almost stumbled on the answer. I put this in my code and it seems to work just fine now:
Sub drpPlaylists_getItemCount(Control As IRibbonControl, ByRef drpPlaylists_itemCount)
drpPlaylists_itemCount = UBound(ReadDirectoryContents(MusicDirectory, "*.m3u"))
End Sub
I guess this gets launched every time the ribbon has to reload itself. But it's solved for now. Still have some things to study up on on when these callbacks get called, but I'll figure this out. Thanks for the help!
I created an application with Access (2013) with VBA. This application crawls a website and inserts some records into database. But it takes too much time.
My solution is to make load bars for waiting. But currently I use the event Form_Current(); and when I set the load bar's value (it's my function) setBarLoadValue (25) Nothing is displayed on the screen. Why ? Because my function run yet.
My question is: How I can manage the event to simulate a load bar in real time ? (Don't want to wait till the end of function to see 100%).
The following link has a beautifully designed Progress status bar. http://www.access-programmers.co.uk/forums/showthread.php?t=265537
The author of the code has provided a Class where you have a Form that acts as a Meter and you basically set the values. It could be real time enough, have a look. I use it in my application and works great.
Finally I found an solution !
Solution
Step1
You must enter this code in your code
DoCmd.SelectObject acForm, Me.Name
Me.Repaint
DoEvents
With this code, you display immediately the form
Step 2
Now, when you want to display something, you must just do that: DoEvents.
When you use DoEvents the form refresh and you can display the new state of the progress bar.
Note: This solution work with Access 2013. Maybe it's not supported with other version.
I'm writing a space invaders style game in Visual Basic for my HSC Software Design project. As part of that, I am using the following line of code to detect whether an enemy hit the player's ship.
If ship.Bounds.IntersectsWith(enemy(i).Bounds) And enemy(i).Visible = True And ship.Visible = True Then
This code is located within a For loop that runs for each enemy. I use that loop to move the enemies as well as check shots and stuff. This For loop runs within a Timer set to a 1 millisecond delay.
I am receiving a NullReferenceException error on this line, and it says Object reference not set to an instance of an object. I know that means one of either enemy(i) or ship isn't set to an object instance or something, because I've already closed the form. Here's the interesting bit:
Firstly, I received this error when this form wasn't even loaded. During the time the application was running, this form was never opened.
Secondly, even if it was running, it occurred quite a while after I stopped the timer with Timer2.Stop(). I checked through my code and there is no way possible that this code should try to execute.
I'm so confused right now, what is going on?