Results 1 to 4 of 4

Thread: problem with function[SOLVED]

  1. #1

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172

    problem with function[SOLVED]

    I've got this code in an module:
    VB Code:
    1. Public Function GetScreenPixels(Optional Dimension As Integer, Optional MinusForm As Form)
    2.  
    3. If Not MinusForm Is Nothing Then 'Get maximum position for form
    4.  
    5.     If Dimension = 1 Then 'Y
    6.         GetScreenPixels = (Screen.Height - MinusForm.Height) / Screen.TwipsPerPixelY
    7.     Else 'X
    8.         GetScreenPixels = (Screen.Width - MinusForm.Width) / Screen.TwipsPerPixelX
    9.     End If
    10.  
    11. Else 'Get screen size in pixels
    12.  
    13.     If Dimension = 1 Then 'Y
    14.         GetScreenPixels = Screen.Height / Screen.TwipsPerPixelY
    15.     Else 'X
    16.         GetScreenPixels = Screen.Width / Screen.TwipsPerPixelX
    17.     End If
    18.    
    19. End If
    20.  
    21. End Function

    The function is for returning the users screen width and height in pixels. however, when i use this code to call it;
    VB Code:
    1. Private Sub txtPosX_LostFocus()
    2. On Error GoTo Error
    3.  
    4. 'Allow form to edit values
    5. If auto_change = True Then Exit Sub
    6.  
    7. If txtPosX.Text > GetScreenPixels(0) Then
    8.     MsgBox ("Outside screen!")
    9.     txtPosX.Text = GetScreenPixels(0, frmMain)
    10. End If
    11.  
    12. Exit Sub
    13.  
    14. Error:
    15. MsgBox ("Only numbers are allowed as window positions!")
    16. txtPosX.Text = 0
    17.  
    18. End Sub
    19.  
    20. Private Sub txtPosY_LostFocus()
    21. On Error GoTo Error
    22.  
    23. 'Allow form to edit values
    24. If auto_change = True Then Exit Sub
    25.  
    26. If txtPosY.Text > GetScreenPixels(1) Then
    27.     MsgBox ("Outside screen!")
    28.     txtPosY.Text = GetScreenPixels(1, frmMain)
    29. End If
    30.  
    31. Exit Sub
    32.  
    33. Error:
    34. MsgBox ("Only numbers are allowed as window positions!")
    35. txtPosY.Text = 0
    36.  
    37. End Sub
    It doesn't work. My resolotion is 1280x1024. When changing the txtPosX text to a number which is more than 1, i get "Outside screen!". changing txtPosY doesn't work either, only numbers below 1 are accepted.

    Does anyone have a solution to this?
    Last edited by vigge89; May 3rd, 2004 at 10:59 AM.


  2. #2

  3. #3

  4. #4

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    great, i tried "Int(txtPosX)" before, but i wasn't sure that it did that

    thanks!


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