VB5 ªì¯Å¥Í ¦Ñ©Ç½d¨Ò(¤Q)

¦^­º­¶


¤ÀÃþ

¼ÐÃD

¤j·N

§@ªÌ

¤é´Á

ª«¥ó¶°¦X ¥Î TypeOf §PÂ_¾Þ§@«ü©w«¬ºA¤§ Control ¡@ ¦Ñ©Ç 1999/5/18
ª«¥ó³B²z CheckBox.Value ªºª¬ºA­È ¡@ ¦Ñ©Ç 1999/7/5
¹Ï§Î³B²z ²©ö²Î­p¹Ïªí¼ÒÀÀ Scale ¤èªkªº¨Ï¥Î ¦Ñ©Ç 1999/5/21
¹Ï§Î³B²z ¨Ï¹Ï¤ùÅÜ·t»PÅÜ«G PaintPicture OpCode °Ñ¼Æªº®ÄªG ¦Ñ©Ç 1999/5/30
¹Ï§Î³B²z Åý¹Ï¤ùÀH¾÷¥X²{ ¡@ ¦Ñ©Ç 1999/6/1
¹Ï§Î³B²z ¨ú±o¹ÏÀɸê°T Picture ª«¥óªº¨Ï¥Î ¦Ñ©Ç 1999/7/8
µøµ¡¬É­± ¦p¦ó±oª¾ MDIForm ªº¤lªí³æ³£¤w Cancel ·í Forms.Count=1 ¦Ñ©Ç 1999/5/26
ÀÉ®× I/O ¥Î Print # ¿é¥X¤£¥[ vbCRLF µ²§Àªº¦r¦ê [;] ²Å¸¹ªº§®¥Î æ£æ£ 1999/5/30
ÀÉ®× I/O ²©öÀɮ׫O¥þ½s½X¸Ñ½X½d¨Ò ­t­t±o¥¿ªº Xor ¹Bºâ§®¥Î ¦Ñ©Ç 1999/6/14
¨ç¼Æ³B²z ¦Û»s MsgBox ¹ï¸Ü®Ø ¤½¥Î¼Ò²Õ(Module) ªº§Q¥Î ¦Ñ©Ç 2000/5/17

VB5 ªì¯Å¥Í½d¨Ò¨Ï¥Î»¡©ú


  1. ¥»½d¨ÒÅwªï«DÀç§Q©Ê­Ó¤H¤Î²Õ´Âà¸ü¨Ï¥Î¡AÀç§Q¤§§Q¥Î½Ð¥ý¼x±o¥»¤H¤§¦P·N¡A¨Ó«Hµù©ú¨Ï¥Î¤è¦¡¤Î¦^ÂЦa§}¡C
  2. ¥»½d¨Ò©Ò¦³ªºµ{¦¡½X½d¨Ò¡A¬ÒÄݤQ¤À°ò¥»ªº VB »yªk¡A¦pªG±z¬O­Ó VB User ¡AÅwªïª½±µ¤Þ¥Î©Î§ï¼g¨Ï¥Î¦b§Aªºµ{¦¡¤¤ ¡A¥»¤H¤£¥D±iµÛ§@Åv¡A¦]¬°¡A¨S¿ìªk¬d¹À¡C
  3. ¦pªG§A¬O­Ó VB ªì¾ÇªÌ¡A¤S¦³ÂI½a½a(©M¦Ñ©Ç¤@¼Ë)¡A»°§Ö§â¥»­¶¥t¦s·sÀɨì§A¦Û¤vªººÏºÐ¡AÂ÷½u«áºCºC¬Ý¡A¤]¥i¥H Copy µ¹ªB¤Í³á(¤£¥i¥H¦¬¿ú)¡C
  4. ¥»½d¨Ò³£¬O¦Ñ©Ç´X­Ó¤ë¨Ó¦b tw.bbs.comp.language °Q½×¸s²Õ¤¤¦^µªª©¤Í°ÝÃDªº¦X¿è¡A¦]¬°¬O°w¹ï°ÝÃD¸Ñ¨M¡A©Ò¥H¨Ã¨S¦³¥þ­±Æ[©Àªº¸Ñ»¡¡A¤£¾A¦X§@¬°¤Jªù¤å³¹¡A¦ý¦pªG§AŪ¤F¤Jªù®Ñ¡A©Î¬O¤W¤F¦Ñ®vªº½Ò¡A¤ß¤¤¤´¤£¬Æ©ú¥Õªº¸Ü¡A´N¥i¥H¨Ó³o§ä§ä¦³¨S¦³§A­nªºµª®×¡A¦]¬°³o³£¬O§O¤H°Ý¹Lªº°ÝÃD¡C

¦^¯Á¤Þ


¥Î TypeOf §PÂ_¾Þ§@«ü©w«¬ºA¤§ Control


Shinji ¼¶¼g©ó¤å³¹

¦³¤@µ{¦¡¤º¦³ 50 ­Ó textbox ¨Ñ user ¿é¤J¼Æ¦r,¦p¦ó¥i¥Hª¾¹D 50 ­Ó¼Æ¦r¤¤¨º­Ó³Ì¤j¨º­Ó³Ì¤p©O?50­Ó¨º»ò¦h,­ø¦n¥s§Ú¤@­Ó¤@­Ó¤ñ¸û§r!

¦Ñ©Çµª¡G

  1. ¨Ï¥Î For...Next °j°é¾Þ§@ Controls ¶°¦Xª«¥ó¡C
  2. ¥Î If TypeOf...Is... §PÂ_¦¡«ü©w¨Ï¥Î TextBox¡C
  3. ½d¨Ò¦p¤U¡G
    Option Explicit

    Private Sub Command1_Click()
    Dim I As Long
    Dim Max As Double, Min As Double

        For I = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(I) Is TextBox Then
                Max = Val(Me.Controls(I).Text)
                Min = Val(Me.Controls(I).Text)
                Exit For
            End If
        Next

        For I = 0 To Me.Controls.Count - 1
            If TypeOf Me.Controls(I) Is TextBox Then
                If Max < Val(Me.Controls(I).Text) Then
                    Max = Val(Me.Controls(I).Text)
                End If

                If Min > Val(Me.Controls(I).Text) Then
                    Min = Val(Me.Controls(I).Text)
                End If
            End If
        Next

        Debug.Print "Max Is:" & Max
        Debug.Print "Min Is:" & Min
    End Sub

¦^¯Á¤Þ


²©ö²Î­p¹Ïªí¼ÒÀÀ


VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5535
ClientLeft = 60
ClientTop = 345
ClientWidth = 7395
LinkTopic = "Form1"
ScaleHeight = 5535
ScaleWidth = 7395
StartUpPosition = 3 '¨t²Î¹w³]­È
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 4800
TabIndex = 5
Top = 4080
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 4800
TabIndex = 4
Top = 3240
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Index = 2
Left = 5160
TabIndex = 3
Top = 1920
Width = 1575
End
Begin VB.TextBox Text1
Height = 495
Index = 1
Left = 5160
TabIndex = 2
Top = 1200
Width = 1575
End
Begin VB.TextBox Text1
Height = 495
Index = 0
Left = 5160
TabIndex = 1
Top = 480
Width = 1575
End
Begin VB.PictureBox Picture1
BackColor = &H80000009&
Height = 4935
Left = 360
ScaleHeight = 4875
ScaleWidth = 3195
TabIndex = 0
Top = 360
Width = 3255
End
Begin VB.Label Label1
Caption = "²Ä¤T¦¸¦¨ÁZ"
Height = 375
Index = 2
Left = 3960
TabIndex = 8
Top = 2040
Width = 975
End
Begin VB.Label Label1
Caption = "²Ä¤G¦¸¦¨ÁZ"
Height = 375
Index = 1
Left = 3960
TabIndex = 7
Top = 1320
Width = 975
End
Begin VB.Label Label1
Caption = "²Ä¤@¦¸¦¨ÁZ"
Height = 375
Index = 0
Left = 3960
TabIndex = 6
Top = 480
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'¥»½d¨Ò¦b§Q¥Î PictureBox ¦Û­q®y¼Ð¤èªk¡A»s§@²³æªº Chart ¥\¯à¡C
Option Explicit

Private Sub Command1_Click()
Dim I As Long

Picture1.Cls
'°õ¦æµe®æ½u¦Û­q¨ç¼Æ
GridDraw

Picture1.DrawWidth = 3
For I = 0 To 1
'¨Ì TextBox ¿é¤J¼Æ­È¡Aµe X,Y §é½u
Picture1.Line (3 + (I) * 2, Val(Text1(I).Text))- _
(3 + (I + 1) * 2, Val(Text1(I + 1).Text)) _
, QBColor(Int(Rnd * 16))
Next

Picture1.DrawWidth = 1

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()

Command1.Caption = "ø¦¨ÁZ¦±½u"
Command2.Caption = "µ²§ô"

'¦Û­q®y¼Ð¨è«×¡AX ¶b 0~8¡AY ¶b 100~-20¡C
Picture1.Scale (0, 100)-(8, -20)

Randomize
End Sub

Private Sub Picture1_Paint()
GridDraw
End Sub

Private Sub GridDraw()
Dim I As Long

'µe X ¶b
Picture1.Line (1, 0)-(8, 0)
'µe Y ¶b
Picture1.Line (1, 100)-(1, 0)

'µe X ¶b¨è«×
For I = 0 To 2
Picture1.CurrentX = 2 + I * 2
Picture1.CurrentY = -5

Picture1.Print "²Ä" & CStr(I + 1) & "¦¸"
Next

'µe Y ¶b¨è«×
For I = 0 To 9
Picture1.CurrentX = 0
Picture1.CurrentY = (I + 1) * 10

Picture1.Print CStr((I + 1) * 10)
Next
End Sub

¦^¯Á¤Þ


¦p¦ó±oª¾ MDIForm ªº¤lªí³æ³£¤w Cancel


¤p±j¥§ ¼¶¼g©ó¤å³¹

½Ð°Ý§Ú­n«ç»òª¾¹DMDIForm ªºchild form ¤w¸g¥þ³Qcancel ¤F©O???

¦Ñ©Çµª¡G

·í Forms.Count=1 ¡Aªí¥Ü©Ò¦³ ChildForm ³£³Q Cancel¡C

¦^¯Á¤Þ


¥Î Print # ¿é¥X¤£¥[ vbCRLF µ²§Àªº¦r¦ê


(¤j¤jªº²´·ú....) ¦b programming ª©´£¨ì

¬°¤°»ò Print # ªº¿é¥XÁ`¬O·|¦bÀÉ®×¥½ºÝ¥[¤JCR©MLF ³Â·Ðª¾¹Dªº¤Hmail¤@¤U....ÁÂÁÂ!!

æ£æ£µª¡G

¤£­n cr+lf ´N¥[ ";"¡APrint #hFileHandle, Var ´N¤£·|¦³¤À¬q²Å¸¹¡C

¦Ñ©Ç¸É¡G

Private Sub Command1_Click()
Dim Var As String
Dim FileHandle As Integer
    FileHandle = FreeFile
    Open "c:\temp\test.txt" For Output As #FileHandle

    Var = "a"
    Print #FileHandle, Var;
    Var = "b"
    Print #FileHandle, Var;
    Var = "c"
    Print #FileHandle, Var;

    Close #FileHandle
End Sub

¦^¯Á¤Þ


¨Ï¹Ï¤ùÅÜ·t»PÅÜ«G


'½d¨Ò¥\¯à¡G¥Î¶Â¥Õ®æ½u¹Ï·í¾B¸n¹Ï¡A¨Ïµe­±©ú·t¤Æ¡C
'¨Ï¥Î±±¥ó¡GPicture1,Picture2¡BCommand1,Command2,Command3
Option Explicit

Private Sub Command1_Click()
    Picture1.Cls
    '¥Î vbSrcAnd ªº¤èªk¶K¾B¸n¹Ï¡A·|¨Ï¾B¸n¹Ï¶Â¦â³¡¥÷³Q¾B»\¡A¦ý¾B¸n¹Ï¥Õ¦â
    '³¡¥÷«hºû«ù­ì¹Ï¼Ë¡C¤]´N¬OÅý³Q¶K¤Wªº¹Ï¤@¥bªº¹Ï¯ÀÅܦ¨¶Â¦â¡A
    '¹F¦¨·t¤U¨Óªº®ÄªG
    Picture1.PaintPicture Picture2.Image, 0, 0, , , , , , , vbSrcAnd
End Sub

Private Sub Command2_Click()
    Picture1.Cls
    '¥Î vbSrcPaint ªº¤èªk¶K¾B¸n¹Ï¡A·|¨Ï¾B¸n¹Ï¶Â¦â³¡¥÷¤£§ïÅÜ¡A¦ý¾B¸n¹Ï¥Õ¦â
    '³¡¥÷«h³Q¾B»\¡C¤]´N¬OÅý³Q¶K¤Wªº¹Ï¤@¥bªº¹Ï¯ÀÅܦ¨¥Õ¦â¡A
    '¹F¦¨«G°_¨Óªº®ÄªG
    Picture1.PaintPicture Picture2.Image, 0, 0, , , , , , , vbSrcPaint
End Sub

Private Sub Command3_Click()
    Picture1.Cls
End Sub

Private Sub Form_Load()
Dim I As Long
    Command1.Caption = "ÅÜ·t"
    Command2.Caption = "ÅÜ«G"
    Command3.Caption = "¦^´_"

    Picture1.AutoSize = True

    '´£¨Ñ¶Â¥Õ®æ½u¹Ï¤§¥Î¡A¤£¶·Åã¥Ü¡C
    Picture2.Visible = False

    Picture1.Picture = LoadPicture("d:\image\03.jpg")

    'Scale §ï¦¨¹Ï¯À¥H§Q¹º½u
    Picture2.ScaleMode = 3
    '§ï¦¨¥Õ©³¶Â½u
    Picture2.BackColor = RGB(255, 255, 255)
    Picture2.ForeColor = RGB(0, 0, 0)
    With Picture2
        .Width = Picture1.Width
        .Height = Picture1.Height
    End With

    Picture2.AutoRedraw = True
    'µeª½½u
    For I = 0 To Picture2.ScaleWidth - 1 Step 2
        Picture2.Line (I, 0)-(I, Picture2.ScaleHeight)
    Next
    'µe¾î½u
    For I = 0 To Picture2.ScaleHeight - 1 Step 2
        Picture2.Line (I, 0)-(I, Picture2.ScaleWidth)
    Next
    Picture2.AutoRedraw = False
End Sub

¦^¯Á¤Þ


Åý¹Ï¤ùÀH¾÷¥X²{


¤£·|´åªaªº³½ ¼¶¼g©ó¤å³¹

§Ú·Q½Ð°Ý¤@¤U..¦p¦ó§Q¥Îvb¤¤ªº¹Ï¤ù±±¨î°}¦C..Åý¹Ï¤ù¯àÀH¾÷¥X²{..

¦Ñ©Çµª¡G

Dim Pic(2) As Picture

Set Pic(0)=LoadPicture("a.bmp")
Set Pic(1)=LoadPicture("b.bmp")
Set Pic(2)=LoadPicture("c.bmp")

Randomize

Set Image1.Pictrue=Pic(Int(Rnd*3))

¦^¯Á¤Þ


²©öÀɮ׫O¥þ½s½X¸Ñ½X½d¨Ò


¦n¤jªºÃú ¼¶¼g©ó¤å³¹

§Ú¼g¤F¤@­Ó³q°T¿ýªºµ{¦¡,§â©Ò¦³¸ê®Æ¦s¤J"DATA.DAT"ÀÉ,¦ý¥Î"WordPad"§Y¥i¬Ý¨ì·í¤¤ªº¸ê®Æ,½Ð°Ý¥i¥H±N¸ê®ÆÂন¶Ã½X©Î¨ä¥¦«¬¦¡¦A¦s¤JÀɮפ¤¹F¨ì«O±Kªº®ÄªG¶Ü ?

¦Ñ©Çµª¡G

'½d¨Ò¥\¯à¡G±N¤å¦rÀÉ®×­«½s½X¡A¥H¹F¦¨Àɮ׫O¥þªº®ÄªG¡C
'°ò¥»¹B§@­ì²z¡G
'1.«O¥þ±K½X¤£¬O¥Ñµ{¦¡¹Bºâ²£¥Í¡A¦Ó¬O®³¥ô·N¤@±i¹Ï¤ù·í±K½X¡A¤]´N¬OÁa¨Ï§O¤HÀò±o
'¥»½d¨Òªº Source Code ¡A¦pªG¤£ª¾¹D§A¥Îªº¬O¨º±i¹Ï¤ù¡A±K½XÁÙ¬O¸Ñ¤£¥X¨Ó¡C
'2.¥Ñ©ó¹Ï¤ù¬O¦b³]­p¶¥¬q´N³]©w¦b PictureBox ªº Picture ÄÝ©ÊùØ¡A©Ò¥HµwºÐ¤¤¤£·|
¦³
'¸Ó¹Ï¤ùªºÀɮסC
'°õ¦æ¥»½d¨Ò½Ð©óªí³æ¤W¥¬¸m CommonDialog1¡BCommand1,2¡BText1 µ¥±±¨î¶µ¡A¨Ã¦b
'³]­p¶¥¬qÅý Picture1.AutoSize=True «á³]©w¤@¤j¤p¾A¤¤ªº¹Ï§Î¡C
Option Explicit
'±N¹Ï¤ùÀɸê®Æ¸ü¤J¹Bºâ¤§°}¦C
Dim SecretBuff() As Byte

Private Sub Command1_Click()
Dim FileHandle As Integer
'¤å¦rÀɸê®Æªº¦s©ñ°}¦C
Dim DataBuff() As Byte
    Text1.Text = ""
    CommonDialog1.filename = ""
    CommonDialog1.ShowOpen

    If CommonDialog1.filename = "" Then
        Exit Sub
    End If

    '¸ü¤J¥[±K«áªº¤å¦rÀÉ
    FileHandle = FreeFile
    Open CommonDialog1.filename For Binary As #FileHandle
    ReDim DataBuff(LOF(FileHandle) - 1)
    Get #FileHandle, , DataBuff
    Close #FileHandle

    '±N¥[±K¤å¦rÀÉ°e¨ì<<¸Ñ±K¦Û­q¨ç¼Æ>>¤¤¸Ñ±K
    Text1.Text = ChangeToShowType(DataBuff, SecretBuff)
End Sub

Private Sub Command2_Click()
Dim FileHandle As Integer
Dim DataBuff() As Byte
    CommonDialog1.filename = ""
    CommonDialog1.ShowSave

    If CommonDialog1.filename = "" Then
        Exit Sub
    End If

    '±N¤å¦rÀÉ°e¨ì<<¥[±K¦Û­q¨ç¼Æ>>¤¤¥[±K
    ChangeToSecretType DataBuff, SecretBuff, Text1.Text

    Kill CommonDialog1.filename
    '±N¥[±K¹L«áªº¦ì¤¸²Õ°}¦C¦sÀÉ
    FileHandle = FreeFile
    Open CommonDialog1.filename For Binary As #FileHandle
    Put #FileHandle, , DataBuff
    Close #FileHandle

    '¨Ï¦sÀɯ墯à
    Command2.Enabled = False
End Sub
Private Sub Form_Load()
Dim FileHandle As Integer
    Command1.Caption = "¶}±ÒÀÉ®×"
    Command2.Caption = "Àx¦sÀÉ®×"
    Command2.Enabled = False

    CommonDialog1.Filter = "Special Data(*.Dat)|*.dat|¥þ³¡ÀÉ®×(*.*)|*.*"

    '¤£Åã¥Ü±K½X¹Ï¤ù
    Picture1.Visible = False
    '±N±K½X¹Ï¤ù¦s¦¨¼È¦sÀÉ
    SavePicture Picture1.Picture, App.Path & "\~" & App.Title & ".tmp"

    '±N¹Ï¤ùÀɸü¤J±K½X°}¦C
    FileHandle = FreeFile
    Open App.Path & "\~" & App.Title & ".tmp" For Binary As #FileHandle
    ReDim SecretBuff(LOF(FileHandle) - 1)
    Get #FileHandle, , SecretBuff
    Close #FileHandle

    '§R°£±K½X¹Ï¤ù¼È¦sÀÉ
    Kill App.Path & "\~" & App.Title & ".tmp"
End Sub
Private Sub Text1_Change()
    '¶}±Ò¦sÀÉ¥\¯à
    Command2.Enabled = True
End Sub
'¸Ñ±K¦Û­q¨ç¼Æ
'°Ñ¼Æ»¡©ú¡G
'1.ChangeBuff():­n³Q¸Ñ±KªºÀÉ®×°}¦C
'2.MixBuff():±K½X°}¦C
Private Function ChangeToShowType(ByRef ChangeBuff() As Byte, _
        ByRef MixBuff() As Byte) As String
Dim RetString As String
'´`Àô¥[ªø±K½X°}¦Cªø«×ªº°}¦C
Dim AddBuff() As Byte
Dim I As Long
    '³]©w±K½X¥[ªø°}¦C»P³Q¸Ñ±KªºÀÉ®×°}¦Cµ¥ªø
    ReDim AddBuff(UBound(ChangeBuff))

    '¦pªG³Q¸Ñ±KªºÀÉ®×°}¦C¸û±K½X°}¦Cªø¡A¨º»ò¦¹¬qµ{¦¡¥i¥H±N±K½X°}¦C´`Àô­«ÂСC
    For I = 0 To UBound(AddBuff)
        AddBuff(I) = MixBuff(I Mod (UBound(MixBuff) + 1))
    Next

    '±N³Q¸Ñ±KªºÀÉ®×°}¦C»P±K½X°}¦Cªº¦U¤¸¯À³v¤@°µ Xor ¹Bºâ¡A
    '¥HÁÙ­ì¦sÀɮɪº­«½s½X¡C
    For I = 0 To UBound(ChangeBuff)
        ChangeBuff(I) = ChangeBuff(I) Xor AddBuff(I)
    Next

    '±N¦r¦ê§ï¦¨ VB ¾A¥Îªº UniCode ®æ¦¡¡C
    RetString = StrConv(ChangeBuff, vbUnicode)
    ChangeToShowType = RetString
End Function
'¥[±K¦Û­q¨ç¼Æ
'°Ñ¼Æ»¡©ú¡G
'1.ChangeBuff():­n³Q¥[±KªºÀÉ®×°}¦C
'2.MixBuff():±K½X°}¦C
Private Sub ChangeToSecretType(ByRef ChangeBuff() As Byte, _
        ByRef MixBuff() As Byte, ByVal ChangeString As String)
Dim AddBuff() As Byte
Dim I As Long
    ''±N¦r¦ê§ï¦¨ Windows ¨t²Îµn°Oªº¦r¦ê®æ¦¡¡C
    ChangeBuff = StrConv(ChangeString, vbFromUnicode)

    ReDim AddBuff(UBound(ChangeBuff))
    For I = 0 To UBound(AddBuff)
        AddBuff(I) = MixBuff(I Mod (UBound(MixBuff) + 1))
    Next

    '±N³Q¥[±KªºÀÉ®×°}¦C»P±K½X°}¦Cªº¦U¤¸¯À³v¤@°µ Xor ¹Bºâ¡A
    '¥H§Q¦s¦¨Àɮ׮ɦ³«O¥þªº®ÄªG¡C
    For I = 0 To UBound(ChangeBuff)
        ChangeBuff(I) = ChangeBuff(I) Xor AddBuff(I)
    Next
End Sub

¦^¯Á¤Þ


CheckBox.Value ªºª¬ºA­È


  1. CheckBox.Value=vbChecked (1,®Ö¨ú)
  2. CheckBox.Valuevb=vbUnchecked (0,¥¼®Ö¨ú)
  3. CheckBox.Valuevb=vbGrayed (2,¥¼¨M©w)

¦^¯Á¤Þ


¨ú±o¹ÏÀɸê°T


'´ú¸Õ¥»½d¨Ò½Ð©óªí³æ¥¬¸m Command1¡BCommandDialog1
Option Explicit

Private Sub Command1_Click()
'vbPicTypeNone 0 Picture ª«¥óªº¹Ï¥Ü«¬ºA
'vbPicTypeBitmap 1 Picture ª«¥óªºÂI°}¹Ï«¬ºA
'vbPicTypeMetafile 2 Picture ª«¥óªº¤¤Ä~ÀÉ ( Metafile ) «¬ºA
'vbPicTypeIcon 3 Picture ª«¥óªº¹Ï¥Ü«¬ºA
'vbPicTypeEMetaFile 4 Picture ª«¥óªº¥[±j«¬¤¤Ä~ÀÉ ( Enhanced Metafile ) «¬ºA
Dim MyPic As Picture
Dim TypeArray(4) As String

TypeArray(0) = "¹Ï¥Ü«¬ºA"
TypeArray(1) = "ÂI°}¹Ï«¬ºA"
TypeArray(2) = "¤¤Ä~ÀÉ ( Metafile ) «¬ºA"
TypeArray(3) = "¹Ï¥Ü«¬ºA"
TypeArray(4) = "¥[±j«¬¤¤Ä~ÀÉ ( Enhanced Metafile ) «¬ºA"

CommonDialog1.ShowOpen

Set MyPic = LoadPicture(CommonDialog1.filename)
Debug.Print "¹Ï¼e(³æ¦ì Pixel)¡G" & Me.ScaleX(MyPic.Width, vbHimetric, vbPixels)
Debug.Print "¹Ï°ª(³æ¦ì Pixel)¡G" & Me.ScaleY(MyPic.Height, vbHimetric, vbPixels)
Debug.Print "¹ÏÀÉ«¬ºA¡G" & TypeArray(MyPic.Type)
End Sub

¦^¯Á¤Þ


¦Û»s MsgBox ¹ï¸Ü®Ø


MsgBox ¨ç¼Æ¡A¬O­t³d±Ò°Ê¤Î³]©w VB ¤º«Øªº¨t²Î¹ï¸Ü²°¡AÁöµM§Q¥Î»áºÙ«K§Q¡A¦ýÁ`¦³¨Ç¤HÁÙ¬O¶û¥¦¥\¯à¤£°÷¡A©Î¬O¥~Æ[³æ½Õ¤£¦n¬Ý¡A©Ò¥H³\¦h VB ³]­p®v³ßÅw¦Û¤v³]­p VB ªº¹ï¸Ü¤è¶ô¡C¤£¹L³]­p¦Û¤vªº¹ï¸Ü¤è¶ô®É¡A¦³¤@­Ó­«­n¥\¯à¡A´N¬O MsgBox ¨ç¼Æ¥i¥H¨Ì¨Ï¥ÎªÌ¦b¹ï¸Ü®Ø¤¤¤£¦Pªº«ö¶s¡A¦Ó¶Ç¦^¤£¦Pªº¼Æ´Ó¡A¦pªG§Ú­Ì¦Û¤vªº MsgBox ¨ç¼Æ¨S¦³³o¥\¯à¡A¥¼§K¤Ó¤£¦n¥Î¤F¡C

¦ý MsgBox ³o­Ó¨ç¼Æ°Ê§@«o©M¤@¯ë¨ç¼Æ°Ê§@¦³¤@­Ó¤Q¤À¤jªº¤£¦P¡A¨º´N¬O´¶³q¨ç¼Æ¥u¦b°õ¦æµ{¦¡³]­p®v³]­pªºµ{¦¡±Ô­z°Ê§@¡A±Ô­zµ²§ô±N¼Æ­È¦^¶Ç§Y¥i¡A¦ý MsgBox ¨ç¼Æ«o¬O­n¶}­Ó DialogBox ¡AµM«áµ¥¨Ï¥ÎªÌ«öÁä«á¡A¦A¨Ì¨Ï¥ÎªÌ«öÁä¨M©w¨ç¼Æ¦^¶Ç­È¡A¦pªG§A¥Î¤@¯ëªº¥\¯à¨ç¼Æ­ì²z¥h³]­p MsgBox ¡A³Ì«áªºµ²ªG¤@©w¬O¨Ï¥ÎªÌÁÙ¨S«öÁä¡A¨ç¼Æ´N¤w¸g°õ¦æ§¹²¦¡A©Ò¥H¥Ã»·¤]¨S¦³¾÷·|§â¨Ï¥ÎªÌªº¿ï¾Ü¶Ç¦^¨Ó¡A¦Ó¬O¤@ª½¶Ç¦^¨ç¼Æªº¹w³]­È¡C

¸Ñ¨M³o­Ó°ÝÃDªº¤@­Ó²³æ¿ìªk¬O§â¦Û»sªº MsgBox ¨ç¼Æ©ñ¨ì¤½¥Î¼Ò²Õ (Module) ¤¤¥h¡A¨º»ò´N·|²£¥Í¤@­ÓÃþ¦ü¨Æ¥ó³qª¾ªº®ÄªG¡A¥i¥Hµ¥«Ý¨Ï¥ÎªÌ¶Ç¦^«öÁä­È¡C¤U­±¬O­Ó²³æªº½d¨Ò¡G

  1. myMsgBox Module:
    'myMsgBox ¨ç¼Æªº¶Ç¦^­È
    Public myMsgBoxReturnValue As Integer
    '¤£¦P®æ¦¡¹ï¸Ü²°ªº°Ñ·Óªí³æª«¥ó
    Private Box As Form

    '¦Û»s°T®§¹ï¸Ü²°
    Public Function myMsgBox(prompt, buttons, title) As Integer
    '¨Ì buttons °Ñ¼Æ¿ï¥Î¹ï¸Ü²°®æ¦¡¡AfrmBox1~3 ¬O¤T­Ó¤£¦P®æ¦¡ªº DialogBox ªí³æ¡C
    Select Case buttons
    Case vbOKOnly
    Set Box = frmBox1
    Case vbOKCancel
    Set Box = frmBox2
    Case vbAbortRetryIgnore
    Set Box = frmBox3
    End Select

    '³o¸Ì¥²¶·§â load ©M show ¤À¶}°µ¡A§_«h box ªº prompt ©M title ·|¬OªÅ¥Õªº¡C
    Load Box
    Box.Caption = title
    Box.Label1.Caption = prompt
    Box.Show vbModal

    '§â³Q¹ï¸Ü²°§ó°Êªº myMsgBoxReturnValue ¤½¥ÎÅܼƷí mymsgbox ¶Ç¦^­È¡C
    myMsgBox = myMsgBoxReturnValue
    End Function
  2. frmBox Form:
    Private Sub Command1_Click(Index As Integer)
    '§â¤½¥ÎÅܼƭȳ]¦¨©R¥O¯Ã¯Á¤Þ­È¡A¥H§Q myMsgBox ¨ç¼Æ­È¦^¶Ç¡C
    myMsgBoxReturnValue = Index
    'ÁôÂæۻsªº MsgBox ªí³æ
    Me.Hide
    End Sub

    Private Sub Form_Load()
    Command1(0).Caption = "²æÂ÷"
    Command1(1).Caption = "­«¸Õ"
    Command1(2).Caption = "©¿²¤"
    End Sub
  3. Call Function Form:
    Private Sub Command1_Click(Index As Integer)
    '¨Ì©R¥O¶s½s¸¹¥h±Ò°Ê¹ïÀ³ªº¦Û»s¹ï¸Ü²°¡A¨Ã¥Î label1 ±µ¦¬ myMsgBox ¦^¶Ç­È¡C
    Label1.Caption = myMsgBox("¦Û»s°T®§¹ï¸Ü²°´ú¸Õ", Index, "¦Û»s¹ï¸Ü²°")
    End Sub

    Private Sub Form_Load()
    Command1(0).Caption = "vbOKOnly"
    Command1(1).Caption = "vbOKCancel"
    Command1(2).Caption = "vbAbortRetryIgnore"
    End Sub

¦^¯Á¤Þ


¦^­º­¶

1