Results 1 to 15 of 15

Thread: (2010 Pro) Simple program troubles, can't find useful info to fix...

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    (2010 Pro) Simple program troubles, can't find useful info to fix...

    First of all, if this is in the wrong place, mods please relocate as necessary.

    Okay so I'm making a program (if you look at "Programming in Visual Basic 2010, Julia Case Bradley and Anita C. Millspaugh, published by McGraw Hill, this particular program "The Switcher" is on page 98/99, programming exercise 2.1) for a school assignment, and everything shows green in my code. When I debug, everything works. However, after loading the print preview it kicks back to the code page and gives me an access violation. It highlights PrintForm1.Print() and throws a yellow arrow up next to it. Images below (sorry if they size badly, I'm on a pretty high resolution) as well as the exception information. Since this program is small, I've scrapped it and rewritten from scratch already, after spending hours troubleshooting and searching for answers which haven't really helped.


    Name:  SwitcherCodeGreen.JPG
Views: 750
Size:  239.6 KB

    Here, the code shows all green, no errors, warnings, or messages

    Name:  SwitcherPrinting.JPG
Views: 1016
Size:  223.2 KB

    Here it's generating the print preview, you can see it's already pulling up the code and highlighting "PrintForm1" - I don't know it this is important, but I've verified that the naming matches up and that I'm using the PrintForm button like the assignment says. I've tried setting the PrintForm to "PrintToPrinter" as well as "PrintToPreview" but I don't know anything about its other settings, and certainly not enough to play with it.

    Name:  switcherscreengrab.JPG
Views: 597
Size:  317.6 KB

    And here is the exception that comes up, along with the detail (there's more if I click the plus boxes, but it takes up too much space to get a screenshot with it displayed. It mentions System.Drawing, but I don't see anything called "System.Drawing" anywhere to even consider troubleshooting it.

    Here is the exception detail that copied to the clipboard :

    System.AccessViolationException was unhandled
    Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Source=System.Drawing
    StackTrace:
    at System.Drawing.SafeNativeMethods.Gdip.GdipDrawRectangleI(HandleRef graphics, HandleRef pen, Int32 x, Int32 y, Int32 width, Int32 height)
    at System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
    at System.Drawing.Graphics.DrawRectangle(Pen pen, Rectangle rect)
    at System.Windows.Forms.UpDownBase.OnPaint(PaintEventArgs e)
    at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
    at System.Windows.Forms.Control.WmPaint(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.UpDownBase.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.RunDialog(Form form)
    at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
    at System.Windows.Forms.Form.ShowDialog()
    at Microsoft.VisualBasic.PowerPacks.Printing.PrintForm.PrintDispatcher(Boolean in_ClientOnly)
    at Microsoft.VisualBasic.PowerPacks.Printing.PrintForm.Print(Form form, PrintOption printOption)
    at Microsoft.VisualBasic.PowerPacks.Printing.PrintForm.Print()
    at P1_McBrideK.SwitcherForm.PrintButton_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\my documents\visual studio 2010\Projects\P1_McBrideK1\P1_McBrideK1\SwitcherForm.vb:line 43
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at P1_McBrideK.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    try setting your target cpu to x86:

    Project-->Properties-->Compile-->Advanced Compile Options-->Target CPU

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    went in to change, it's already set to x86

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    *bump* any other ideas out there?

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    It's impossible for me to read any code from your screen shots (why not crop your images, the error is hardly in the task bar There is no reason to have a full screen screen shot). Can you just post the offending code?
    Last edited by Joacim Andersson; Feb 4th, 2013 at 09:46 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    If it will help, I will post the code tomorrow when I get to a real computer (I'm on my phone) but in the meantime, respectfully, I suggest trying "ctrl+" or view/zoom as you will be able to see the code in my screenshots. As I said, though... it shows all green. My apologies for not cropping out the start bar, though... I was just trying to show everyone exactly what I could see.

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    Here is the code in its entirety, including the pseudocode. If I ever get it to work, I will rearrange its order a little for flow, even though that's really just for aesthetics and not functionality.

    Public Class SwitcherForm

    Private Sub SwitcherForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ' Place cursor in name text box do user can enter name.
    NameTextBox.Focus()

    ' Ensure light image displayed is the "off" image.
    PictureBox2.SendToBack()
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    ' Tell user to shut off the light.
    MessageLabel.Text = "Turn off the light, " & NameTextBox.Text

    ' Display the light "on" image.
    PictureBox1.SendToBack()
    End Sub

    Private Sub BlackRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
    ' Change "Turn the light on/off" message font color to black.
    MessageLabel.ForeColor = Color.Black
    End Sub

    Private Sub BlueRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
    ' Change "Turn the light on/off" message font color to blue.
    MessageLabel.ForeColor = Color.Blue
    End Sub

    Private Sub RedRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
    ' Change "Turn the light on/off" message font color to red.
    MessageLabel.ForeColor = Color.Red
    End Sub

    Private Sub GreenRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
    ' Change "Turn the light on/off" message font color to green.
    MessageLabel.ForeColor = Color.Green
    End Sub

    Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
    ' Display print preview dialog 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
    ' Exit the program.
    Me.Close()
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    ' Tell user to turn on the light.
    MessageLabel.Text = "Turn on the light, " & NameTextBox.Text

    ' Display the light "off" image.
    PictureBox2.SendToBack()
    End Sub
    End Class

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    The problem, I suspect, is that you have a number of stacked picture boxes which means that the print document drawing attempts to create two objects in the same place (and the same memory space) causing corruption. The effect you require should be created in a single picture box using a change of image.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  9. #9
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    What happens if you just try to print it instead of preview for the action?

    I only mention it because I see that "UpDownBase" and the preview screen has one that represents the pages of the document, which leads me to believe it is the actual preview dialog box having issues painting itself.

    I tried dun's suggestion, but I don't have any issues either way. Regular form, several stacked pictureboxes, several stacked pictureboxes with the Image property set, etc...

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    Quote Originally Posted by wakawaka View Post
    What happens if you just try to print it instead of preview for the action?

    I only mention it because I see that "UpDownBase" and the preview screen has one that represents the pages of the document, which leads me to believe it is the actual preview dialog box having issues painting itself.

    I tried dun's suggestion, but I don't have any issues either way. Regular form, several stacked pictureboxes, several stacked pictureboxes with the Image property set, etc...
    I set the code as "PrintToPrinter" and changed the PrintForm1 properties PrintAction characteristic to "PrintToPrinter" as well, it prints. The problem is I need it to go to preview for the assignment. The assignment guidelines said two image boxes, so I'm not sure I'm allowed to do it in one. Also, since you were able to do it, I thought maybe it was due to the fact that the images boxes are identical in size and location, so I made one slightly larger to give them different borders... still fails. I wonder what you did differently from me to allow yours to work?

    Quote Originally Posted by dunfiddlin View Post
    The problem, I suspect, is that you have a number of stacked picture boxes which means that the print document drawing attempts to create two objects in the same place (and the same memory space) causing corruption. The effect you require should be created in a single picture box using a change of image.
    How can I do it with one picture box, just in case the professor will allow me to do it that way? One thing I should mention is that the images had to be imported to the boxes, and it didn't create resource files. I tried creating a resource file, but when I put the image in, the colors invert and the extremely small image refuses to resize - I'm obviously doing something wrong, but being as I'm new to this, I have no idea what.

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    Ok, a little worrying that that's how you've been told to do it, unless you're being protected from bitmaps for some reason I can't fathom? I'm not sure why the resource file didn't work though. Where are the images coming from and in what format? There are several other different ways to store a collection of images but I think the ImageList component would be particularly suitable for this. Simply add all the images to the image list, choose the size and colourdepth required and then change the picture by index or name, eg.

    PictureBox1.Image = ImageList1.Images(0)
    PictureBox1.Image = ImageList1.Images("Off.bmp")
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    I tried that, and it shows the lightoff image to start, then I click and it switches, but I can't switch it back - still playing with it but I should make sure of something - I'm absolutely not allowed to use an if/then statement, will this method require one?

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    So my professor took a look at my program using his laptop after class (I brought the project in on a thumb drive) and it worked fine as I posted it. Looks like I'll bee running diagnostics on my hardware tomorrow, I'm guessing its my ram. Thanks for the support, everyone! I'll post diagnostic results soon as I can.

  14. #14

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    11

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    After a long run of memtest, there is nothing wrong with the ram... also, the hard drive is fine. Not sure what the problem is, anybody know where/what the gremlin is?

  15. #15
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: (2010 Pro) Simple program troubles, can't find useful info to fix...

    Just a shot in the dark, try re-installing the framework version that the application is using.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width