11.07.2015 Views

101 Tech Tips - Visual Studio Magazine - One-Stop Source Shop

101 Tech Tips - Visual Studio Magazine - One-Stop Source Shop

101 Tech Tips - Visual Studio Magazine - One-Stop Source Shop

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

For even more tricks and tips go towww.vbpj.com or www.vcdj.comVB4/32, VB5, VB6Level: IntermediateCreate Unconventional Windows to Dazzle UsersWhen designing a portion of an application that must grab users’attention quickly—such as your company’s splash screen—youmight want to create a nonrectangular window. This code showsyou how to create a V-shaped window based on nine points:Private Type POINTAPIx As Longy As LongEnd TypePrivate Declare Function SetWindowRgn Lib "user32" _(ByVal hWnd As Long, ByVal hRgn As Long, _ByVal bRedraw As Boolean) As LongPrivate Declare Function CreatePolygonRgn _Lib "gdi32" (ByRef lpPoint As POINTAPI, _ByVal nCount As Long, _ByVal nPolyFillMode As Long) As LongPrivate Sub Form_Load()Dim lhandle As LongDim lpPoint(0 To 8) As POINTAPIlpPoint(0).x = 0lpPoint(0).y = 0lpPoint(1).x = 20lpPoint(1).y = 150lpPoint(2).x = 60lpPoint(2).y = 150lpPoint(3).x = 80lpPoint(3).y = 0lpPoint(4).x = 52lpPoint(4).y = 0lpPoint(5).x = 46lpPoint(5).y = 120lpPoint(6).x = 40lpPoint(6).y = 120lpPoint(7).x = 32lpPoint(7).y = 0lpPoint(8).x = 0lpPoint(8).y = 0lhandle = CreatePolygonRgn(lpPoint(0), 9, 1)Call SetWindowRgn(Me.hWnd, lhandle, True)End SubVB3, VB4, VB5, VB6Level: Beginning—Andrew Holliday, PhoenixClose All Child Forms in <strong>One</strong> ShotIn MDI applications, a user might have two or three or even moreMDI child windows open at any given time. But in applicationswhere you have user log-in and log-out security, you likely want tounload all open forms when the user logs out. To accomplish this,use this small piece of code:Do Until MDIform1.ActiveForm Is NothingUnload MDIform1.ActiveFormLoopIf you need to save any values in any form by default, you caninclude a call to the appropriate Save method in the Unload eventof that form.—Unnikrishnan Thampy, Floral Park, N.Y.VB3, VB4, VB5, VB6Level: BeginningReturn Roman NumeralsThis VB procedure returns decimal numbers (integers) as Romannumerals (a string), ranging from 1 to 4999. Numbers outside thisrange return the same number as a string. The optional parameteriStyle allows two different numerical styles: standard (4 = iv, 9 = ix,and so on) when iStyle = -1, or classical (4 = iiii, 9 = viiii, and so on)when iStyle = -2.The variable x should make the function more efficient, althoughyou might not notice the time saved on a fast machine:Public Function Roman(ByVal n As Integer, _Optional iStyle As Integer = -1) As StringIf n < 1 Or n >= 5000 ThenRoman = CStr(n)Exit FunctionEnd IfIf iStyle -2 Then iStyle = -1Dim sRtn As String, i As Integer, x As IntegerDim r(1 To 13) As String, v(1 To 13) As Integerr(1) = "i": v(1) = 1r(2) = "iv": v(2) = 4r(3) = "v": v(3) = 5r(4) = "ix": v(4) = 9r(5) = "x": v(5) = 10r(6) = "xl": v(6) = 40r(7) = "l": v(7) = 50r(8) = "xc": v(8) = 90r(9) = "c": v(9) = 100r(10) = "cd": v(10) = 400r(11) = "d": v(11) = 500r(12) = "cm": v(12) = 900r(13) = "m": v(13) = 1000x = UBound(v)sRtn = ""DoFor i = x To LBound(v) Step iStyleIf v(i)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!