Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for comdlgcp.vbs

(view source code of comdlgcp.vbs as plain text)

  1. ' A script to demonstrate the Color Picker dialog available in COMDLG32.OCX
  2. ' Written by Rob van der Woude
  3. ' http://www.robvanderwoude.com
  4.  
  5. Option Explicit
  6.  
  7. Dim intColor
  8.  
  9. intColor = ColorPicker( )
  10. If Err Then
  11. 	WScript.Echo "Error: " & Err.Description
  12. Else
  13. 	WScript.Echo "Selected color (RGB): " & RGB( intColor )
  14. End If
  15.  
  16.  
  17. Function ColorPicker( )
  18. 	Dim objDialog
  19. 	' Default value if aborted
  20. 	ColorPicker = 0
  21. 	On Error Resume Next
  22. 	Set objDialog = CreateObject( "MSComDlg.CommonDialog" )
  23. 	If Err Then
  24. 		MsgBox Err.Description & vbCrLf & vbCrLf & "This script requires COMDLG32.OCX." & vbCrLf & vbCrLf & "Please make sure it is installed and registered.", , "COMDLG32 not registered"
  25. 	Else
  26. 		objDialog.ShowColor
  27. 		ColorPicker = CLng( objDialog.Color )
  28. 	End If
  29. 	Set objDialog = Nothing
  30. End Function
  31.  
  32.  
  33. Function RGB( myColor )
  34. 	Dim intTest, strRed, strGreen, strBlue
  35. 	strRed   = CStr( myColor Mod 256 )
  36. 	intTest  = Int( myColor / 256 )
  37. 	strGreen = CStr( intTest Mod 256 )
  38. 	intTest  = Int( intTest / 256 )
  39. 	strBlue  = CStr( intTest Mod 256 )
  40. 	RGB      = strRed & " " & strGreen & " " & strBlue
  41. End Function
  42.  

page last uploaded: 2017-04-06, 13:33