Results 1 to 21 of 21

Thread: Form_Load()

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Form_Load()

    I have put this code in the Form_Load() event and when I debuged it it counted correct and the code worked fine, however when I get to the .PrintForm method it dos'nt print the row lines or column lines, but if I replace the .printform with frmPrint.Show they do appear.
    I am making the .printform call from another form but I think i'm using it correctly as you can see from below.

    any ideas?
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     picWindow.Left = 0
    4.     picWindow.Width = Me.Width
    5.     picI_Print.Left = 0
    6.     picI_Print.Width = picWindow.Width
    7.  
    8. Dim i As Integer
    9. Dim t As Integer
    10.  
    11. t = 2775
    12. For i = 1 To 54                 ' Add Line Numbers
    13.     t = t + 225                 ' to form
    14.     picI_Print.CurrentX = 0
    15.     picI_Print.CurrentY = t
    16.        picI_Print.Print i
    17.        picI_Print.Line (0, t)-(picI_Print.Width, t) 'Make rows 225 twips apart
    18.    Next
    19.    '''' Make columns
    20.     picI_Print.Line (300, 2400)-(300, picI_Print.Height)
    21.     picI_Print.Line (750, 2400)-(750, picI_Print.Height)
    22.     picI_Print.Line (2100, 2400)-(2100, picI_Print.Height)
    23.     picI_Print.Line (3525, 2400)-(3525, picI_Print.Height)
    24.     picI_Print.Line (4500, 2400)-(4500, picI_Print.Height)
    25. End Sub
    26.  
    27. Private Sub Command4_Click()
    28. Me.Hide
    29. Load frmPrint
    30. frmPrint.PrintForm
    31. End Sub








    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by Hack; Oct 31st, 2005 at 07:52 AM.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Form_Load()

    Can you zip and attach your project? (I can't replicate the problem)

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    That's because you used the Form_Load() event. That event is fired before the form has even completely loaded. Use Form_Activate() instead, which fires after the Form and all of its objects have loaded

    Also be sure to use [Highlight=VB] tags when displaying vb code.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Form_Load()

    Place the code in the form_activate section, as the form isn't loaded in form_load. Form.Show will force the form to be shown in the load event, which is why it works.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Also, what does Form_Load() in your thread title have to do with your problem? A more appropriate thread title for this would be "Rows and Columns not being displayed in form"

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Form_Load()

    tried putting
    VB Code:
    1. picWindow.Left = 0
    2.     picWindow.Width = Me.Width
    3.     picI_Print.Left = 0
    4.     picI_Print.Width = picWindow.Width
    5.  
    6. Dim i As Integer
    7. Dim t As Integer
    8.  
    9. t = 2775
    10. For i = 1 To 54                 ' Add Line Numbers
    11.     t = t + 225                 ' to form
    12.     picI_Print.CurrentX = 0
    13.     picI_Print.CurrentY = t
    14.        picI_Print.Print i
    15.        picI_Print.Line (0, t)-(picI_Print.Width, t) 'Make rows 225 twips apart
    16.    Next
    17.    '''' Make columns
    18.     picI_Print.Line (300, 2400)-(300, picI_Print.Height)
    19.     picI_Print.Line (750, 2400)-(750, picI_Print.Height)
    20.     picI_Print.Line (2100, 2400)-(2100, picI_Print.Height)
    21.     picI_Print.Line (3525, 2400)-(3525, picI_Print.Height)
    22.     picI_Print.Line (4500, 2400)-(4500, picI_Print.Height)
    23. End Sub

    in activate event did'nt work either

    Also I do not want to display this form. I want to be able to print it on paper







    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by Hack; Oct 31st, 2005 at 07:53 AM.

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Why are you using twips? Set the scalemode to 3 and make it pixels. Anyways give me a minute to fix your code.....

    Remember to use those [Highlight=VB] tags too.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Form_Load()

    [QUOTE=Jacob Roman]Why are you using twips? Set the scalemode to 3 and make it pixels.

    because I very new to VB
    Haven't got the whole scalemode thing down yet.
    bty the column lines that are show are put there by me drawing lines not via the code, the lines are there just for reference and will be deleted later on.

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Form_Load()

    I agree with Bruce. Post your project so we can see how you are trying to do this. I thought you wanted to use a form.

  10. #10
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Enjoy

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Activate()
    4.    
    5.     ScaleMode = 3
    6.    
    7.     With picWindow
    8.  
    9.    
    10.         .ScaleMode = 3
    11.         .AutoRedraw = True
    12.         .Left = 0
    13.         .Top = 0
    14.         .Width = Me.Width
    15.         .Height = Me.Height / 2
    16.    
    17.     End With
    18.  
    19.     With picI_Print
    20.    
    21.         .ScaleMode = 3
    22.         .AutoRedraw = True
    23.         .Left = 0
    24.         .Top = Me.ScaleHeight / 2
    25.         .Width = Me.Width
    26.         .Height = Me.Height / 2
    27.        
    28.     End With
    29.  
    30.     'Long is the fastest computing data type, and theres no worry for overflow ;)
    31.  
    32.     Dim i As Long
    33.     Dim t As Single
    34.  
    35.     t = 2.7
    36.    
    37.     For i = 1 To 54 ' Add Line Numbers
    38.  
    39.         t = t + 22.5 ' to form
    40.         picI_Print.CurrentX = 0
    41.         picI_Print.CurrentY = t
    42.         picI_Print.Print i
    43.         picI_Print.Line (0, t)-(picI_Print.Width, t) 'Make rows 225 twips apart
    44.  
    45.     Next i
    46.    
    47.     '''' Make columns
    48.     picI_Print.Line (30, 0)-(30, picI_Print.Height)
    49.     picI_Print.Line (75, 0)-(75, picI_Print.Height)
    50.     picI_Print.Line (210, 0)-(210, picI_Print.Height)
    51.     picI_Print.Line (355, 0)-(352, picI_Print.Height)
    52.     picI_Print.Line (450, 0)-(450, picI_Print.Height)
    53.    
    54. End Sub

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Form_Load()

    hope this works for ya
    the two form that work together
    first is frmVinyl, the user GUI
    second fmrPrint is the printed version(or will be) of frmVinyl

    I will also have another form that will be displayed for a Preview of what is going to be printed.
    the reasoning behind not showing the form is that I can print a full page, not just what you can see. other words not resolution dependit, from what I know the printform method will only print what you can see, hence two forms.

    copy and paste code in still don't print (on paper) row lines and column lines.
    Last edited by crater; Oct 27th, 2005 at 10:45 PM. Reason: reply

  12. #12
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    I see what you are trying to do. I'm not sure if you are aware of this but there's an object in VB that's similar to Excel and Access that looks like what you were trying to simulate. So you just did all that work for nothing, and could have made your life a whole lot easier.

    Quote Originally Posted by crater
    Haven't got the whole scalemode thing down yet.
    Don't worry bout getting down the scalemode. Set it to 3 - Pixels on all of your forms/pictureboxes that you plan on drawing on and you don't have to worry about a thing. Set it and forget it.

  13. #13
    Lively Member
    Join Date
    Sep 2005
    Posts
    82

    Re: Form_Load()

    Crater,

    I don't know why you are using a form to draw lines and then print it on the paper, instead you may use the printer object to do this.
    you can print lines, text, images, use different fonts and colors with printer object
    You can also select your printer for printer object.


    Sanjay

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Form_Load()

    Sorry about the last forms I attached.

    I have created a new project that will show you what I'm trying to do.

    as you can see the form prints on the screen fine but when it goes to print it on paper the rows and columns do not show. Any ideas would be great.

    I understand that the form is not active until it is shown or is activated, but here in this case I can still show it (that would automatically activate it) and it still dose'nt do both print on screen and a copy on paper.
    Last edited by crater; Oct 30th, 2005 at 11:27 PM.

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Form_Load()

    Jacob, Long may be the fastest data type (on 32-bit platforms), but there's no point in hell setting a Long to 2.7 ... it's still an integer you know

  16. #16
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Quote Originally Posted by penagate
    Jacob, Long may be the fastest data type (on 32-bit platforms), but there's no point in hell setting a Long to 2.7 ... it's still an integer you know
    That's why you use Single. It's another 32 bit data type, only for decimals

  17. #17
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Form_Load()

    Indeed... I was simply referring to this:
    Quote Originally Posted by Jacob Roman
    VB Code:
    1. Dim i As Long
    2.     Dim t As Long
    3.  
    4.     t = 2.7

  18. #18
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    I fixed it

  19. #19
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Quote Originally Posted by crater
    Sorry about the last forms I attached.

    I have created a new project that will show you what I'm trying to do.

    as you can see the form prints on the screen fine but when it goes to print it on paper the rows and columns do not show. Any ideas would be great.

    I understand that the form is not active until it is shown or is activated, but here in this case I can still show it (that would automatically activate it) and it still dose'nt do both print on screen and a copy on paper.
    The reason why is because you practically ignored the code I gave you in Post #10. Mine printed flawlessly, yours didn't.

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Re: Form_Load()

    Quote Originally Posted by Jacob Roman
    The reason why is because you practically ignored the code I gave you in Post #10. Mine printed flawlessly, yours didn't.
    not so Jacob I actually copyed and pasted you code into my form and it did'nt work.

    so maybe a screwed something up, so I tried it again and now i get a run-time error 480: Application defined or object defined error.

    when I debug if highlites this line.
    VB Code:
    1. picI_Print.Print i
    So now I'm really lost

    Q1: Your code should be in the frmPrint form? Because the only other code in that form is cmdexit that unloads the form.

    Q2: should I be calling frmPrint VIA .show from frmVinyl? or is there another way to call the activate event in frmPrint?

    Please don't get discouraged, I am very new to VB and just want to learn.

  21. #21
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Form_Load()

    Did you make a new project with only one form, add two pictureboxes, and then do it? Try that and it should work now.

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