Dynamic label click event crash, dodgy coding?

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 1617 Views - Last Post: 31 January 2013 - 10:36 AM Rate Topic: -----

#1 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Dynamic label click event crash, dodgy coding?

Posted 19 December 2012 - 02:45 PM

Hi everybody, this is my first post! :D I'm designing a booking system that creates labels in a panel which, when clicked on, will turn red to indicate a booking. I'm getting a crash, and I'm unsure why. It often makes Visual Studio (2010) crash, too! Please help! What's going wrong? :(

     Private Sub Matrix_Display_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim i, j As Integer
        Dim Myfont As New Font("Ariel", 7)
        Dim PCFile As String = CurDir() & "\PCFile.dat"


        Me.Text = "PC Room Layout"

        For i = 0 To 15
            For j = 0 To 6
                Display(i, j) = New Label
                Display(i, j).Name = i & "," & j
                pnlDisplay.Controls.Add(Display(i, j))
                Display(i, j).Width = 45
                Display(i, j).Height = 45
                Display(i, j).FlatStyle = BorderStyle.Fixed3D

                Display(i, j).Left = i * Display(0, 0).Left + 45
                Display(i, j).Top = j * Display(0, 0).Top + 45
                Display(i, j).BackColor = Color.MediumSeaGreen
                Display(i, j).ForeColor = Color.Yellow
                Display(i, j).BorderStyle = BorderStyle.Fixed3D
                Display(i, j).TextAlign = ContentAlignment.MiddleCenter
                Display(i, j).Font = Myfont
                Display(i, j).Text = "Not" & vbNewLine & "Booked"
            Next
        Next

        For i = 1 To 15
            For j = 1 To 5 Step 2
                Display(i, j).Hide()
            Next
        Next
        AddHandler Display(i, j).Click, AddressOf Clicked 


The crash occurs on the final line. Everything up to there works. After this, I have:
     Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
        Me.BackColor = Color.Red

    End Sub 


Many thanks for your help! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic label click event crash, dodgy coding?

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2270
  • View blog
  • Posts: 9,496
  • Joined: 29-May 08

Re: Dynamic label click event crash, dodgy coding?

Posted 19 December 2012 - 03:03 PM

I think that i j don't have the values you think they do.
For i = 1 To 15
  For j = 1 To 5 Step 2
    Display(i, j).Hide()
  Next
Next
' At this point
' i = 16 and j = 7'
   AddHandler Display(i, j) 



You can also reduce the visual complexity and the number of loops.
Private Sub Matrix_Display_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
   Dim i, j As Integer
   Dim Myfont As New Font("Ariel", 7)
   Dim PCFile As String = CurDir() & "\PCFile.dat"


   Me.Text = "PC Room Layout"

   For i = 0 To 15
     For j = 0 To 6
       Dim l As New Label
       Display(i, j) = l
       With l
         .Name ="Matrix_" & i & "_" & j  
         .Width = 45
         .Height = 45
         .FlatStyle = BorderStyle.Fixed3D
         .Left = i * Display(0, 0).Left + 45
         .Top = j * Display(0, 0).Top + 45
         .BackColor = Color.MediumSeaGreen
         .ForeColor = Color.Yellow
         .BorderStyle = BorderStyle.Fixed3D
         .TextAlign = ContentAlignment.MiddleCenter
         .Font = Myfont
         .Text = "Not" & vbNewLine & "Booked"
         .Click, AddressOf Clicked
        End With
        If i>0 AndAlso (j mod 2=1) Then l.Hide()
     
        pnlDisplay.Controls.Add(l)
     Next
   Next




Issue is probably to do with the controls name you giving it. Comma are not allowed and they can not begin with a number.

This post has been edited by AdamSpeight2008: 19 December 2012 - 03:09 PM

Was This Post Helpful? 1
  • +
  • -

#3 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 07:23 AM

Hello again,
I'm currently having issues getting the correct values for i and j coords here

        If myLabel.BackColor = Color.Red Then
            MsgBox("This facility is already booked.")
        Else
            Dim WriteToFile As String = i & "," & j & vbNewLine
            My.Computer.FileSystem.WriteAllText(PCFile, WriteToFile, True)
        End If


I can see why, it's only writing the final coords, but how do I correct it?
Here is where the values are pulled from
  Dim Myfont As New Font("Ariel", 7)

        Me.Text = "PC Room Layout"

        For Me.i = 0 To 15
            For Me.j = 0 To 6
                Display(i, j) = New Label
                Display(i, j).Name = i & "," & j
                pnlDisplay.Controls.Add(Display(i, j))
                Display(i, j).Width = 45
                Display(i, j).Height = 45
                Display(i, j).FlatStyle = BorderStyle.Fixed3D

                Display(i, j).Left = i * Display(0, 0).Left + 45
                Display(i, j).Top = j * Display(0, 0).Top + 45
                Display(i, j).BackColor = Color.MediumSeaGreen
                Display(i, j).ForeColor = Color.Yellow
                Display(i, j).BorderStyle = BorderStyle.Fixed3D
                Display(i, j).TextAlign = ContentAlignment.MiddleCenter
                Display(i, j).Font = Myfont
                Display(i, j).Text = "Not" & vbNewLine & "Booked"
                AddHandler Display(i, j).Click, AddressOf Clicked




                Dim Reader As New System.IO.StreamReader(PCFile) 'My reader is a stream reader which will read the file line by line. 
                Do While Reader.Peek <> -1
                    FileLineText = ""
                    FileLineText = FileLineText & Reader.ReadLine
                    Array = Split(FileLineText, ",")
                    xCoord = Array(0)
                    yCoord = Array(1)
                    If xCoord = i And yCoord = j Then
                        Display(i, j).BackColor = Color.Red
                        Display(i, j).Text = "Booked"
                    End If
                Loop
                Reader.Close()
            Next
        Next


Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 10:28 AM

You really aren't telling us where you are getting the i and j from. You are showing us a disembodied If statement.

Where is that If? Is it in a subroutine? A Function? How do you get to it? How are you passing the i and j values to it?
It obviously isn't embedded in the For loop that creates the labels.
Was This Post Helpful? 0
  • +
  • -

#5 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 11:04 AM

View Postlar3ry, on 10 January 2013 - 10:28 AM, said:

You really aren't telling us where you are getting the i and j from. You are showing us a disembodied If statement.

Where is that If? Is it in a subroutine? A Function? How do you get to it? How are you passing the i and j values to it?
It obviously isn't embedded in the For loop that creates the labels.


Sorry about that, here's the whole subroutine for clicking a label
    Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
        Dim myLabel As Label = DirectCast(sender, Label)






        If myLabel.BackColor = Color.Red Then
            MsgBox("This facility is already booked.")
        Else
            Dim WriteToFile As String = i & "," & j & vbNewLine
            My.Computer.FileSystem.WriteAllText(PCFile, WriteToFile, True)
        End If

        myLabel.BackColor = Color.Red
        myLabel.Text = "Booked"




    End Sub


And here is the sub for the form load
 Dim Myfont As New Font("Ariel", 7)

        Me.Text = "PC Room Layout"

        For Me.i = 0 To 15
            For Me.j = 0 To 6
                Display(i, j) = New Label
                Display(i, j).Name = i & "," & j
                pnlDisplay.Controls.Add(Display(i, j))
                Display(i, j).Width = 45
                Display(i, j).Height = 45
                Display(i, j).FlatStyle = BorderStyle.Fixed3D

                Display(i, j).Left = i * Display(0, 0).Left + 45
                Display(i, j).Top = j * Display(0, 0).Top + 45
                Display(i, j).BackColor = Color.MediumSeaGreen
                Display(i, j).ForeColor = Color.Yellow
                Display(i, j).BorderStyle = BorderStyle.Fixed3D
                Display(i, j).TextAlign = ContentAlignment.MiddleCenter
                Display(i, j).Font = Myfont
                Display(i, j).Text = "Not" & vbNewLine & "Booked"
                AddHandler Display(i, j).Click, AddressOf Clicked




                Dim Reader As New System.IO.StreamReader(PCFile) 'My reader is a stream reader which will read the file line by line. 
                Do While Reader.Peek <> -1
                    FileLineText = ""
                    FileLineText = FileLineText & Reader.ReadLine
                    Array = Split(FileLineText, ",")
                    xCoord = Array(0)
                    yCoord = Array(1)
                    If xCoord = i And yCoord = j Then
                        Display(i, j).BackColor = Color.Red
                        Display(i, j).Text = "Booked"
                    End If
                Loop
                Reader.Close()
            Next
        Next

        For Me.i = 1 To 15
            For Me.j = 1 To 5 Step 2
                Display(i, j).Hide()
            Next
        Next
        Display(0, 3).Hide()


Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 12:18 PM

OK. I don't see where you are getting i and j then.

If they are declared globally (outside any Sub or Function), your Sub will be able to see them, but then you'll have to do something to set their values. The Form_Load Sub uses them, but when the For loops end, i and j will be set to the ending value + 1.

If they are not declared globally, your Clicked Subroutine knows nothing about them at all.

Your labels know about them, though, in that you name them with values from the For loop in the Form_Load Sub. So you could extract the i and j values from there. You could also use the Tag property of the label to specify its i and j values, perhaps with something like specifying i=13 and j=4 by using a Tag value of 13.5

BTW, I don't know if it's causing any problems or not, but the Label.Name fields all start with a number and contain a comma.
Was This Post Helpful? 1
  • +
  • -

#7 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 01:14 PM

[quote name='lar3ry' date='10 January 2013 - 12:18 PM' timestamp='1357845532' post='1780787']
OK. I don't see where you are getting i and j then.

If they are declared globally (outside any Sub or Function), your Sub will be able to see them, but then you'll have to do something to set their values. The Form_Load Sub uses them, but when the For loops end, i and j will be set to the ending value + 1.

If they are not declared globally, your Clicked Subroutine knows nothing about them at all.

Your labels know about them, though, in that you name them with values from the For loop in the Form_Load Sub. So you could extract the i and j values from there. You could also use the Tag property of the label to specify its i and j values, perhaps with something like specifying i=13 and j=4 by using a Tag value of 13.5

BTW, I don't know if it's causing any problems or not, but the Label.Name fields all start with a number and contain a comma.
[/quote

Yes, they are declared globally and as you say, they are end value + 1. Not good :(
Are you suggesting that I make a tag in the loop and give it (for example's purpose) "i,j" as a string, then use a loop in my code for writing to the file to extract from the tag the coordinates?

Also, please could you explain the issues with commas and numbers? Second time I've heard that but no errors, what is the potential issue?

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#8 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 01:49 PM

Sorry for the misquote! :S
Was This Post Helpful? 0
  • +
  • -

#9 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 01:52 PM

View PostGinister, on 10 January 2013 - 02:14 PM, said:

Yes, they are declared globally and as you say, they are end value + 1. Not good :(/>
Are you suggesting that I make a tag in the loop and give it (for example's purpose) "i,j" as a string, then use a loop in my code for writing to the file to extract from the tag the coordinates?

Yes, you can assign a value to the Tag property of each control within the For loop that generates the Labels. Even better than 13.4 or 13,4, you could use "13 4" to more easily extract the values to write to the file.
Something like this:
               Display(i, j).Tag = CStr(i) & "." & Cstr(j)
        'Then when you want to use them as a String,
               Dim iStr as String = rb.Tag.Substring(0, rb.Tag.IndexOf(" "))
               Dim jStr as String = rb.Tag.Substring(rb.Tag.LastIndexOf(" "))
        'Or to use them as Integers
               Dim iInt as Integer = CInt(rb.Tag.Substring(0, rb.Tag.IndexOf(" ")))
               Dim jInt as Integer = CInt(rb.Tag.Substring(rb.Tag.LastIndexOf(" ")))



Quote

Also, please could you explain the issues with commas and numbers? Second time I've heard that but no errors, what is the potential issue?

Well, if you aren't getting errors, it may be alright, but if you try to put a control on a Form with the Form editor, it will tell you that the Names "2Label" or "Lab,el" are invalid property values.

It would be wise to use Option Strict On and Option Explicit On to allow the editor to tell you what it sees as undeclared or of the wrong type.
Was This Post Helpful? 1
  • +
  • -

#10 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 02:11 PM

View Postlar3ry, on 10 January 2013 - 01:52 PM, said:

View PostGinister, on 10 January 2013 - 02:14 PM, said:

Yes, they are declared globally and as you say, they are end value + 1. Not good :(/>/>
Are you suggesting that I make a tag in the loop and give it (for example's purpose) "i,j" as a string, then use a loop in my code for writing to the file to extract from the tag the coordinates?

Yes, you can assign a value to the Tag property of each control within the For loop that generates the Labels. Even better than 13.4 or 13,4, you could use "13 4" to more easily extract the values to write to the file.
Something like this:
               Display(i, j).Tag = CStr(i) & "." & Cstr(j)
        'Then when you want to use them as a String,
               Dim iStr as String = rb.Tag.Substring(0, rb.Tag.IndexOf(" "))
               Dim jStr as String = rb.Tag.Substring(rb.Tag.LastIndexOf(" "))
        'Or to use them as Integers
               Dim iInt as Integer = CInt(rb.Tag.Substring(0, rb.Tag.IndexOf(" ")))
               Dim jInt as Integer = CInt(rb.Tag.Substring(rb.Tag.LastIndexOf(" ")))



Quote

Also, please could you explain the issues with commas and numbers? Second time I've heard that but no errors, what is the potential issue?

Well, if you aren't getting errors, it may be alright, but if you try to put a control on a Form with the Form editor, it will tell you that the Names "2Label" or "Lab,el" are invalid property values.

It would be wise to use Option Strict On and Option Explicit On to allow the editor to tell you what it sees as undeclared or of the wrong type.


Sorry for the many replies, but how do I identify the tag value for the display that has been clicked? Using Display(i, j).Tag = CStr(i) & "." & Cstr(j) will still give me the very final value + 1, no?
Was This Post Helpful? 0
  • +
  • -

#11 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 02:48 PM

Quote

Sorry for the many replies, but how do I identify the tag value for the display that has been clicked? Using Display(i, j).Tag = CStr(i) & "." & Cstr(j) will still give me the very final value + 1, no?

Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
    Dim myLabel As Label = DirectCast(sender, Label)

    If myLabel.BackColor = Color.Red Then
        MsgBox("This facility is already booked.")
    Else
        Dim WriteToFile As String = i & "," & j & vbNewLine
        My.Computer.FileSystem.WriteAllText(PCFile, WriteToFile, True)
    End If

    myLabel.BackColor = Color.Red
    myLabel.Text = "Booked"
End Sub


When you generate the Label, you assign positions, names, colors, etc. At that point you can assign the Tag property as well. When you assign the value to Tag, it will use the current value of i and j, which you have as you are generating the labels.

When you use a label, in the Clicked sub, you can retrieve these values. I was looking at another program when I gave the examples, so this time I'll use your variable name...
       Dim iStr as String = MyLabel.Tag.Substring(0, MyLabel.Tag.IndexOf(" "))
       Dim jStr as String = MyLabel.Tag.Substring(MyLabel.Tag.LastIndexOf(" ")+1)


Then just use iStr and jStr in place of i and j in your WriteAllText line.

This post has been edited by lar3ry: 10 January 2013 - 02:49 PM

Was This Post Helpful? 1
  • +
  • -

#12 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 10 January 2013 - 03:16 PM

View Postlar3ry, on 10 January 2013 - 02:48 PM, said:

Quote

Sorry for the many replies, but how do I identify the tag value for the display that has been clicked? Using Display(i, j).Tag = CStr(i) & "." & Cstr(j) will still give me the very final value + 1, no?

Private Sub Clicked(ByVal sender As Object, ByVal e As EventArgs)
    Dim myLabel As Label = DirectCast(sender, Label)

    If myLabel.BackColor = Color.Red Then
        MsgBox("This facility is already booked.")
    Else
        Dim WriteToFile As String = i & "," & j & vbNewLine
        My.Computer.FileSystem.WriteAllText(PCFile, WriteToFile, True)
    End If

    myLabel.BackColor = Color.Red
    myLabel.Text = "Booked"
End Sub


When you generate the Label, you assign positions, names, colors, etc. At that point you can assign the Tag property as well. When you assign the value to Tag, it will use the current value of i and j, which you have as you are generating the labels.

When you use a label, in the Clicked sub, you can retrieve these values. I was looking at another program when I gave the examples, so this time I'll use your variable name...
       Dim iStr as String = MyLabel.Tag.Substring(0, MyLabel.Tag.IndexOf(" "))
       Dim jStr as String = MyLabel.Tag.Substring(MyLabel.Tag.LastIndexOf(" ")+1)


Then just use iStr and jStr in place of i and j in your WriteAllText line.

Bingo, thanks. You are a saint! :)
Was This Post Helpful? 0
  • +
  • -

#13 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 26 January 2013 - 07:16 AM

Hi again, everybody. I've got to a point where the program works very well apart from one thing: If the user clicks the load room button and does it again for new settings, it only keeps the current room's settings up. Here's the code
 If SecondTime = True Then
                    For Me.i = 0 To 15
                        For Me.j = 0 To 7
                            Display(i, j).Controls.Clear()
                        Next
                    Next
                End If


                For Me.i = 0 To 15
                    For Me.j = 0 To 7
                        Call NewLabel()
                    Next
                Next
                SecondTime = True


Newlabel is as follows
    Private Sub NewLabel()
        Dim FoundWeek, FoundDate, FoundTime, FoundRoom As String


        Display(i, j) = New Label
        Display(i, j).Name = i & "," & j
        pnlDisplay.Controls.Add(Display(i, j))
        Display(i, j).Width = 45
        Display(i, j).Height = 45
        Display(i, j).FlatStyle = BorderStyle.Fixed3D

        Display(i, j).Left = i * Display(0, 0).Left + 45
        Display(i, j).Top = j * Display(0, 0).Top + 45
        Display(i, j).BackColor = Color.MediumSeaGreen
        Display(i, j).ForeColor = Color.Yellow
        Display(i, j).BorderStyle = BorderStyle.Fixed3D
        Display(i, j).TextAlign = ContentAlignment.MiddleCenter
        Display(i, j).Font = Myfont
        Display(i, j).Text = "Not" & vbNewLine & "Booked"

        AddHandler Display(i, j).Click, AddressOf Clicked
        Display(i, j).Tag = i & "," & j

        Dim Reader As New System.IO.StreamReader(PCFile) 'My reader is a stream reader which will read the file line by line. 
        Do While Reader.Peek <> -1
            FileLineText = ""
            FileLineText = Reader.ReadLine
            ReaderArray = Split(FileLineText, ",")
            xCoord = ReaderArray(0)
            yCoord = ReaderArray(1)
            FoundTime = ReaderArray(2)
            FoundDate = ReaderArray(3)
            FoundWeek = ReaderArray(4)
            FoundRoom = ReaderArray(5)
            If xCoord = i And yCoord = j And FoundTime = SelectedTime And FoundDate = SelectedDay And FoundRoom = SelectedRoom And FoundWeek = SelectedWeek Then
                Display(i, j).BackColor = Color.Red
                Display(i, j).Text = "Booked"
            End If
        Loop
        Reader.Close()
    End Sub


My theory is that the array is loading beneath the current array, but I can't be sure. Anybody know what's gone wrong?
Thanks.
Was This Post Helpful? 0
  • +
  • -

#14 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Dynamic label click event crash, dodgy coding?

Posted 26 January 2013 - 12:54 PM

A few observations:

Your NewLabel() subroutine actually creates New Labels, leaving the old ones in place. The new ones replace the old ones in the array. This is not a good situation, though it may not be the cause of your problems.

You are reading in the File EVERY time a new label is created and placed in the array. You would be better off reading the file in once (to another array, perhaps), then looping through the lines once to set the properties of the Labels.

If you have saved the status/properties of the labels, when you call NewLabel for all the new labels, the properties will overwrite the cleared label properties.

How to proceed?

Split out the reading of the file into a separate Sub or Function.

Create a new Sub (perhaps call it "ResetDisplay()" that uses the labels already in the array, changing the properties to whatever you want them to be. Label.Clear does not affect BackColor or Position, for example.
Was This Post Helpful? 1
  • +
  • -

#15 Ginister  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 19-December 12

Re: Dynamic label click event crash, dodgy coding?

Posted 29 January 2013 - 10:47 AM

View Postlar3ry, on 26 January 2013 - 12:54 PM, said:

A few observations:

Your NewLabel() subroutine actually creates New Labels, leaving the old ones in place. The new ones replace the old ones in the array. This is not a good situation, though it may not be the cause of your problems.

You are reading in the File EVERY time a new label is created and placed in the array. You would be better off reading the file in once (to another array, perhaps), then looping through the lines once to set the properties of the Labels.

If you have saved the status/properties of the labels, when you call NewLabel for all the new labels, the properties will overwrite the cleared label properties.

How to proceed?

Split out the reading of the file into a separate Sub or Function.

Create a new Sub (perhaps call it "ResetDisplay()" that uses the labels already in the array, changing the properties to whatever you want them to be. Label.Clear does not affect BackColor or Position, for example.

Hi, thanks for your help, it's all working now. I did just that and made a different sub for the second & higher display load.

I've moved onto the print code but I'm getting the error "Out of memory" when I try and assign a file location to a print screen. I think it's because I have the wrong file type, but I'm not entirely sure.
Here's the code from the print form.

                PrintForm1.PrintFileName = CurDir() & "\Printout.png"
                PrintForm1.Print()


This saves it fine, but I'm doubting that it's png. Here is where it crashes, on the next form where it is trying to print.
        Dim PrintScreen As Image

        PrintScreen = Image.FromFile(CurDir() & "\Printout.png")


Please help, I can't seem to find out how to print it without getting 'Out of memory'. Thanks!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2