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

¦^­º­¶


¤ÀÃþ

¼ÐÃD

¤j·N

§@ªÌ

¤é´Á

¼Æ­È³B²z ¨D¨ú½è¼Æ ¡@ ¦Ñ©Ç 1998/8/21
¼Æ­È³B²z ²©ö VB ¹Bºâ¾¹ ¡@ ¦Ñ©Ç 1998/8/29
¼Æ­È³B²z ¤£­«ÂЪº¶Ã¼Æ ¡@ ¦Ñ©Ç 1998/9/4
¼Æ­È³B²z ¥Î And ­È°µ IF ±ø¥ó§PÂ_ ­­¨î¹Bºâ»P¥]§t¹Bºâªº°Ï§O ¦Ñ©Ç 1998/9/4
ÅܼƹB¥Î ¥Î For Each...In... °µ¦h Control ªº±±¨î ¡@ ¦Ñ©Ç 1998/8/29
±±¨î¶µ³B²z CommandButton ªº Color ÄÝ©Ê ¡@ ¦Ñ©Ç 1998/8/29
±±¨î¶µ³B²z ListBox ªº Item Move & Disabled ¼ÒÀÀ VB ¤£´£¨ÑªºÄÝ©Ê©M¤èªk ¦Ñ©Ç 1998/9/9
±±¨î¶µ³B²z ¤@­ÓFrame¨â²Õ¥H¤Wªº Option Buttons ¤S¤@­Ó VB »Ù²´ªk Peter 1998/9/12
±±¨î¶µ³B²z ¦b TextBox ùØ¿é¤J Chr(vbKeyTab) ÄdºI Tab Áä ¦Ñ©Ç 1998/9/1
±±¨î¶µ³B²z ©î¸Ñ¦h¦æ TextBox ¡@ ¦Ñ©Ç 1998/9/1
±±¨î¶µ³B²z TextBox ­­¿é¤J¼Æ¦r»P¤p¼ÆÂI ¦b Text_Change ùتº§@ªk ¦Ñ©Ç 1998/9/14
±±¨î¶µ³B²z ¦C¥X Container ®e¾¹ùتºª«¥ó Container & Controls ¦Ñ©Ç 1998/9/14
ª«¥ó³B²z ¦p¦ó¨ú±o¥Ø«ewindowsªº¹w³]¦Cªí¾÷­È ¡@ ¦Ñ©Ç 1998/8/29
ª«¥ó³B²z ¤À¦C¤¤¤å¡B­^¤å¦r«¬ §A§Ñ¤F StdFont.Charset ¶Ü ¦Ñ©Ç 1998/9/20
¨Ï¥ÎªÌ¬É­± ¤@¶s±±¦h Form ªº¬É­±³]­p ActiveForm Äݩʪº¨Ï¥Î ¦Ñ©Ç 1998/8/30
¨Ï¥ÎªÌ¬É­± ¦A½× ActiveForm ÄÝ©Ê Screen & MdiForm ¦Ñ©Ç 1998/9/3
¨Ï¥ÎªÌ¬É­± ¦Û°Ê¤Á´« TextBox ªº¿é¤Jªk ImeMode ªº¨Ï¥Î ¦Ñ©Ç 1998/9/1
¨Ï¥ÎªÌ¬É­± ½Õ°Ê Form ªº¤W¤U¦¸§Ç SetFocus ¤èªk ¦Ñ©Ç 1998/9/3
¨Ï¥ÎªÌ¬É­± ¦p¦ó³B²z¤ñ¿Ã¹õ¤jªº Form ±Ò¥Î MDIForm ¦Ñ©Ç 1998/9/14
ÀÉ®× I/O ²©öÀH¾÷Àɽs¿è¾¹ Random Àɮשµ¦ù§Q¥Î ¦Ñ©Ç 1998/9/4

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©Ò¦³¨Ã¨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

¦^¯Á¤Þ


¨D¨ú½è¼Æ


Option Explicit

Private Function ¨D½è¼Æ(ByVal CalcNum As Long) As Variant
Dim I As Long, J As Long
Dim varRedimNum As Long
Dim ¾ã°£¼Æ As Boolean
Dim varReturn() As Long
    If CalcNum < 1 Then
        MsgBox "¿é¤J¼Æ­È¤£¯à¤p©ó 1 ", vbOKOnly, "°Ñ¼Æ¿ù»~"
        Exit Function
    End If

    '¥ý§â  1 ¸Ë¶i¶Ç¦^°}¦CùØ
    ReDim varReturn(varRedimNum)
    varReturn(varRedimNum) = 1

    '¶Ç¤J­È¬O 1 ´N¤£©¹¤Uºâ
    If CalcNum = 1 Then
        ¨D½è¼Æ = varReturn
        Exit Function
    End If

    '¦^¶Ç°}¦C«ü¼Ð¥[ 1
    varRedimNum = varRedimNum + 1

    For I = 2 To CalcNum
        For J = 2 To I
            If J <> I Then
                If (I Mod J) = 0 Then
                    ¾ã°£¼Æ = True
                    Exit For
                End If
            End If
        Next

        If Not ¾ã°£¼Æ Then
            ReDim Preserve varReturn(varRedimNum)
            varReturn(varRedimNum) = I
            varRedimNum = varRedimNum + 1
        Else
            ¾ã°£¼Æ = False
        End If
    Next

    ¨D½è¼Æ = varReturn

End Function

'¨D½è¼Æ¨ç¼Æ©I¥s¤èªk
Private Sub Command1_Click()
Dim Accept
Dim I As Long
    '¶Ç¤J°Ñ¼Æ 1000
    Accept = ¨D½è¼Æ(1000)

    '¿é¤J­È¿ù»~«hµ²§ô
    If IsEmpty(Accept) Then Exit Sub

    '¦b ListBox ¤WÅã¥Üµ²ªG
    For I = 0 To UBound(Accept)
        List1.AddItem Accept(I)
    Next
End Sub

¦^¯Á¤Þ


¥Î For Each...In... °µ¦h Control ªº±±¨î


©ñ¤@Áû¤ß... ¼¶¼g©ó¤å³¹

¦pªG«Ü¦h­Ócontrol­n¦p¦ó¥h±±¨î©O??¨Ò¦p¦³20­Ócheckbox,¤£§Æ±æ¨ú¦W±q1¨ì20...¥i¥H¥Îarrayªº¤è¦¡¶Ü??

¦Ñ©Çµª¡G

Option Explicit
Private Sub Command1_Click()
Dim Cont As Control
    For Each Cont In Me.Controls
        If TypeName(Cont) = "CheckBox" Then
            Cont.Visible = Not Cont.Visible
        End If
    Next
End Sub

¦^¯Á¤Þ


CommandButton ªº Color ÄÝ©Ê


  1. ¦b VB 5 ùØ CommandButton ªº¦U Color ÄݩʬO©M¨ä¥L±±¨î¶µ«Ü¤£¤@¼Ëªº¡C
  2. CommandButton ¨S¦³ ForeColor ÄÝ©Ê¡A¤]´N¬O»¡¥¦ªº Caption ¥Ã»·¥u¦³¤@­ÓÃC¦â¡A´N¬O Windows ¨t²Î©w¸qªº [«ö¶s¤W­±¤å¦rªºÃC¦â]¡C
  3. CommandButton.BackColor ³]©w¡A¥u¦³·í CommandButton.Style=1( ¹Ï¤ù¥~Æ[)®É¤~¯à§e²{¥X¨Ó¡A¦pªG Style=0(¼Ð·Ç¥~Æ[)¡ACommandButton.BackColor ¥Ã»·¬O Windows ¨t²Î©w¸qªº [«ö¶sªí­±ªºÃC¦â]¡C
  4. CommandButton.MaskColor ¥i¥H«ü©w CommandButton.Picture ùØ¡A¬Y¤@¦â­È°Ï°ì¬O³z©úªº(§e²{ Command.BackColor ¦â±m)¡A¤£¹L¥ý¨M±ø¥ó¬O CommandButton.UseMaskColor=True¡C

¦^¯Á¤Þ


²©ö VB ¹Bºâ¾¹


¤¦¡]BOY¡^ ¼¶¼g©ó¤å³¹

¦p¦óÅý¨Ï¥ÎªÌ¦b¤å¦r¤è¶ô¿é¤J¥ô·N¼Æ­È¤Î¼Æ¾Ç¹Bºâ¦¡«á¡A¥Ñ VB ¥[¥H¹Bºâ¡H

¦Ñ©Çµª¡G

Option Explicit
'FUnit ²Ä¤@¹Bºâ¤¸¡A
'CalcUnit ¹Bºâ¤l¡A
'LUnit ²Ä¤G¹Bºâ¤¸¡A
'°õ¦æ¦¹µ{¦¡½Ð©óªí³æ¥¬¸m 4 ­Ó TextBox ¤Î 1 ­Ó Command
'Text1->FUnit
'Text2->CalcUnit
'Text3->LUnit
'Text4->­pºâµ²ªG¿é¥X
Private Function Operator(ByVal FUnit As Variant, _
        ByVal CalcUnit As String, ByVal LUnit As Variant) As Variant
Dim ReValue As Variant

    Select Case UCase(CalcUnit)
        '¥H¤Uºâ³N¹Bºâ¤l¹Bºâ
        Case "^"
            ReValue = FUnit ^ LUnit
        Case "*"
            ReValue = FUnit * LUnit
        Case "/"
            ReValue = FUnit / LUnit
        Case "\"
            ReValue = FUnit \ LUnit
        Case "MOD"
            ReValue = FUnit Mod LUnit
        Case "+"
            ReValue = FUnit + LUnit
        Case "-"
            ReValue = FUnit - LUnit

        '¥H¤U¤ñ¸û¹Bºâ¤l
        Case "LIKE"
            ReValue = FUnit Like LUnit

        '¥H¤U³sµ²¹Bºâ¤l
        Case "&"
            ReValue = FUnit & LUnit

        '¥H¤UÅÞ¿è¹Bºâ¤l
        Case "AND"
            ReValue = FUnit And LUnit
        Case "EQV"
            ReValue = FUnit Eqv LUnit
        Case "IMP"
            ReValue = FUnit Imp LUnit
        Case "NOT"
            ReValue = Not LUnit
        Case "OR"
            ReValue = FUnit Or LUnit
        Case "XOR"
            ReValue = FUnit Xor LUnit

        'µL®Ä¹Bºâ¤l³B²z
        Case Else
            MsgBox "[" & CalcUnit & "] ¤£¬O¤@­Ó¦³®Äªº¹Bºâ¤l", vbOKOnly _
                    , "¿é¤Jºâ¦¡¿ù»~"
            Exit Function
    End Select

    Operator = ReValue
End Function

Private Sub Command1_Click()
    Text4.Text = Operator(Text1.Text, Text2.Text, Text3.Text)
End Sub

¦^¯Á¤Þ


¦p¦ó¨ú±o¥Ø«ewindows ªº¹w³]¦Cªí¾÷­È


Annie Chiu ¼¶¼g©ó¤å³¹ ...

  1. À³¦p¦ó¨ú±o¥Ø«ewindows ªº¹w³]¦Cªí¾÷­È
  2. ­Y¸Ó­È¦b°õ¦æ¤¤·|³Q§ó´«, ½Ð°Ý¤SÀ³¦p¦ó±N¹w³]¦Cªí¾÷Á٭즨­ì¨Óªº

¦Ñ©Çµª¡G

Option Explicit

'Àx¦s¦Lªí¾÷¸Ë¸m¦WºÙ¤§ÅܼÆ
Dim DriveString As String

Private Sub Form_Click()
Dim X As Printer

    Print Printer.DeviceName
    Print Printer.DriverName

    For Each X In Printers
        '§â¦Lªí¾÷³]©wµ¹»P¹w³]¦Lªí¾÷¤£¦P¦Wªº¨ä¥L¦Lªí¾÷
        If X.DriverName <> DriveString Then
            Set Printer = X
            Exit For
        End If
    Next

    Print Printer.DeviceName
    Print Printer.DriverName

    For Each X In Printers
        'Àˬd DriveString ªº­È¡A§â¹w³]¦Lªí¾÷§ì¦^¨Ó
        If X.DriverName = DriveString Then
            Set Printer = X
            Exit For
        End If
    Next

    Print Printer.DeviceName
    Print Printer.DriverName

End Sub

Private Sub Form_Load()
    '§â¹w³]¦Lªí¾÷ªº¸Ë¸m¦WºÙ©ñ¨ìÅܼÆùØ
    DriveString = Printer.DriverName
End Sub

¦^¯Á¤Þ


¤@¶s±±¦h Form ªº¬É­±³]­p


hsu shihchieh ¼¶¼g©ó¤å³¹

¦pªG§Ú·Q³]­p¤@±Æ«ö¶s,¤Î¦h±i Form ¡A¦p¦óÅý VB ª¾¹D§Ú¶}¨º­Ó Form ¨Ã¦b MainForm ¤¤¾ÞÁa SubForm ùتº°Ê§@¡H

¦Ñ©Çµª¡G

  1. §A¦b MDIForm ¤W©ñ¤@­Ó PictureBox¡A°µ¬° CommandButton ªº Container¡C
  2. ¦b Picturebox ¤W©ñ¤T­Ó CommandButton.
  3. ¥[¤J Form1.MdiChild=true
  4. §â MDIForm ³]¬°±Ò°Êªí³æ¡A¨Ã§â¤U¦C±Ô­z¶K¨ì MDIForm

    Option Explicit

    Private Sub Command1_Click()
        Me.ActiveForm.Print "ABC"
    End Sub

    Private Sub Command2_Click()
        Me.ActiveForm.Print "123"
    End Sub

    Private Sub Command3_Click()
        Me.ActiveForm.Print "¦n²³æ"
    End Sub

    Private Sub MDIForm_Load()
    Dim AForm As New Form1
    Dim BForm As New Form1
    Dim CForm As New Form1
        AForm.Show
        AForm.Caption = "AForm"
        BForm.Show
        BForm.Caption = "BForm"
        CForm.Show
        CForm.Caption = "CForm"
    End Sub
  5. ±Ò°Ê«á½ü¬yÂI A,B,CForm ¡A¦A«ö Command ¡A§A´N·|¬Ý¨ì®ÄªG¡C

¦^¯Á¤Þ


¦b TextBox ùØ¿é¤J Chr(vbKeyTab)


bigcake ¼¶¼g©ó¤å³¹

¦b¤@­Ó Form ¤¤¥[¤J¨â­Ó (©Î¥H¤W) ªº TextBox,¦b Text1_KeyDown §ì¤£¨ì TAB Áä (vbKeyTab)why?¤S­n¦p¦ó¸Ñ¨M©O?

¦Ñ©Çµª¡G

  1. §A¬O­n¦b TextBox ùإΠTab ¿é©w¦ì²Å¸¹¶Ü¡H³Â·Ðªº¬O Tab ³o­ÓÁä°T¸¹Äd¤£¦í¡A¦ü¥GVB ¤@¦¬¨ì Tab ´N·|§â Focus ¥æµ¹¤U­Ó±±¨î¶µ¡A¦Ó¤£·|°õ¦æ KeyDown ùØ­±ªºµ{¦¡±Ô­z¡A§A¦³¨â­Ó¸Ñ¨M¿ìªk¡G
  2. §â©Ò¦³±±¨î¶µªº TabStop Äݩʳ]¬° False(³oµ¥©ó¨Ï Tab Á䥢¯à¡A·|¨Ï¨Ï¥ÎªÌ¾AÀ³¤£¨}¡C)
  3. ¥Î²Õ¦XÁä [Ctrl]+[Tab]¦p¡G
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyTab And Shift = 2 Then
            Text1.SelText = Chr(vbKeyTab)
        End If
    End Sub
    ¦A¦b§Aµ{¦¡ Help ¤¤¦V¨Ï¥ÎªÌ»¡©ú¡A¿é¤J [Tab] ²Å¸¹ªº¤è¦¡¬O [Ctrl]+[Tab]¡C

¦^¯Á¤Þ


¦Û°Ê¤Á´« TextBox ªº¿é¤Jªk


Private Sub Text1_GotFocus()
    Text1.IMEMode = 1
End Sub
Private Sub Text1_LostFocus()
    Text1.IMEMode = 2
End Sub

CWW5 ¨Ó¨ç·N¨£¡G

ImeMode¦ü¥G¦³Bug¡A¦pªG¦³¦h­ÓTextBox³]¤FImeMode¨º·|¦³¤@¨Ç·N·Q¤£¨ìªº¶Ã¡C

¦Ñ©Ç·N¨£¡G

¦hÁ CWW5 ¡A¸g´ú¸Õªº½T¦³¦¹²{¶H¡A¦Ó¥B Text1_LostFocus() ¨Æ¥ó¤¤ªº  Text1.IMEMode = 2 ±Ô­z¦n¹³¤]¤£¥¿½T¡A­ì¦]¤j·§¦b Mouse_Click ©M IMEMode Change °T®§¶Ç°e¤W¦³¨Ç°ÝÃD¡C©Ò¥H Text.IMEMode ¦n¹³¦b¨Æ¥ó³B²z¤W¦³¨º»ò¨Ç©_©Çªº·Pı¡C«OÀIªº§@ªk¬O¥u¨Ï¥Î¤@­Ó TextBox ¡A¨Ã¥Ñ¥~³¡ª«¥óµ{§Ç¨ÓÅܧó Text.IMEMode ÄÝ©Ê¡C¨Ò¦p§Ú­Ì¦b¥Î Access 97 ®É¡A¦b¬Y¨Ç¿é¤JÄæ¦ì·|¦Û°Ê¤Á´«¿é¤Jª¬ºA¡A§Ú·Q VB ¥i¥H³o»ò¼ÒÀÀ¡G

Private Sub MSFlexGrid1_Click()
Text1.IMEMode = 2
With MSFlexGrid1
Text1.Move .CellLeft + .Left, .CellTop + .Top, .CellWidth, .CellHeight
Text1.Text = .Text
'¥Ñ Col ÄݩʧPÂ_²Ä´X­ÓÄæ¦ì¤Á´«¿é¤Jª¬ºA¡C
If .Col = 2 Then
Text1.IMEMode = 1
End If
Text1.SetFocus
End With
End Sub

¦^¯Á¤Þ


©î¸Ñ¦h¦æ TextBox


¤ìÀY ¼¶¼g©ó¤å³¹

¦p¦ó±N¦h¦æTextBoxÂà´«¦¨ListBox

¦Ñ©Çµª¡G

¥»ÃD¸Ñªk­«ÂI¦b TextBox ùتºÂ_¦æ¡A¥²¶·¥Ñ Chr(13)+Chr(10) ¨â¦r²Õ¦X°_¨Ó°õ¦æ¡A©Ò¥HÀ³¥H Chr(13) ¬°¤Á³Î§PÂ_ÂI¡G

Dim AllString As String
Dim SingleString As String
Dim SepString As String
Dim I As Long
    AllString = Text1.Text

    For I = 1 To Len(AllString)
        SingleString = Mid(AllString, I, 1)
        If SingleString = Chr(13) Then
            '¹J¨ì Chr(13) «h§â¤À³Î¦r¦ê¥[¨ì ListBox ùØ
            List1.AddItem SepString
            SepString = ""
        Else
            If SingleString <> Chr(10) Then
                '°£ Chr(10) ¥~³v¦r¥[¤J SepString ¤¤
                SepString = SepString + SingleString
            End If
        End If
    Next
    '¥[¤J³Ì«á¤@­Ó SepString
    List1.AddItem SepString

CWW5 ¨Ó¨ç·N¨£¡G

©î¸Ñ¦h¦æ TextBox ³o­­¨î¦bMultiLine¦Ó¥B¦³Keyin Enter¨Ó´«¦æªºTextBox¡A¦pªGMultiLine¤§¤U¤@ª½KeyIn¤£´«¦æ¡A¨ì¤FTextBox³Ì¥kÃä«á¡A¦AKeyinªº¦r·|§é¤U¨Ó¡AÅܦ¨¥t¤@¦æ¡A³o¤è¦¡¸Ñ¨M¤£¤F¡A½Ð¬d¤@¤Uhtmapi101.htmªº°µªk¡C

¦Ñ©Ç·N¨£¡G

ÁÂÁ CWW5 ¡Aªº½T¬O¦p¦¹¡A¦pªG·Q¤À¸Ñ Mutiline ¦Û°Ê§é¦^ªº¦r¦ê¡A½Ð¨ì
http://sunh.hosp.ncku.edu.tw/~cww/htmapi101.htm °Ñ¦Ò CWW5 ªº°µªk¡C

¦^¯Á¤Þ


¦A½× ActiveForm ÄÝ©Ê


±H¥óªÌ: kook

  1. §Ú¬Ý¤F§Aªº Email«á¥[¤J  Me.ActiveForm.PrintForm  ,·í§Ú©I¥s Form2 ,and click the print botton(in Form1) ,  µ²ªG¥X²{¿ù»~.§Ú·Q¬OVB¤£ª¾½Ö¬OActiveForm,
  2. your's form1 ¬O§@¦ó¥Î??? ¸ÑÄÀ¤@¤U, form1 ¤Î MDIForm ¬O §Q¥Î MDIForm °µ mainform ÁÙ¬O¥Îform1,

¦Ñ©Çµª¡G

  1. ActiveForm ¬O Screen ¤Î MDIForm ¤~¦³ªºÄÝ©Ê¡AForm ª«¥ó¬O¨S³o§@¥Îªº¡C
  2. VB ùØ¥u¦³ Start Form ªºÆ[©À¡A¨S¦³ MainForm ªºÆ[©À¡A¹ï©ó ActiveForm ³oÄݩʨӻ¡¡AForm.MDIChild=True ªº Form ­n¥Î MDIForm.ActiveForm ¨Ó¦s¨ú¡AForm.MdiChild=False ªº Form ¡A«h¥Î Screen.ActiveForm ¨Ó¦s¨ú¡C

¦^¯Á¤Þ


½Õ°Ê Form ªº¤W¤U¦¸§Ç


¬q ÅA ¼¶¼g©ó¤å³¹

¦^¯Á¤Þ


¤£­«ÂЪº¶Ã¼Æ


¦Ñ©Ç¡G

¨ä¹ê¥»½d¨Òªº­ì²z©Mªì¯Å¥Í½d¨Ò²Ä¤@¿è¡A¦p¦ó§âµP¬~´²¬~¶Ã¬O¦P¼Ëªº¡A¥u¬O¨º½d¨Ò§¨Âøªá¦â§PÂ_¡A¦A§Q¥Î©Ê¸û®t¡A©Ò¥H§Ú§ï¼g¤@¤U¡A§â¥¦°µ¦¨ Function ¡A¥i¥H«Ü¤è«Kªº¥Ñ§A¨M©wªº¶}©l¼Æ»Pµ²§À¼Æ¤¤¶¡ªº¼Æ­È¶Ã¼Æ­«±Æ«á¡A¥H°}¦C§ÎºA°e¦^¡C´ú¸Õ¥»½d¨Ò½Ð©ó Form ¤W¥¬¸m Command1,List1¡C

Option Explicit
Private Function NoDoubleRnd(ByVal StartNum As Long, _
        ByVal EndNum As Long) As Variant
Dim ReturnArray() As Long
Dim TempNum As Long, I As Long, J As Long

    '¦pªG°_ÂI¼Æ¤j©ó²×ÂI¼Æ«h¨â¼Æ¹ï´«
    If StartNum > EndNum Then
        TempNum = EndNum
        EndNum = StartNum
        StartNum = TempNum
    End If

    '¨Ì¼Æ­È¤j¤p³]©w¶Ç¦^ Array ¤j¤p
    ReDim ReturnArray(Abs(EndNum - StartNum))
    '§â¤¤¶¡¼Æ¸Ë¶i¥h
    For I = 0 To UBound(ReturnArray)
        ReturnArray(I) = StartNum + I
    Next

    '±Ò°Ê¶Ã¼ÆºØ¤l
    Randomize

    '§Q¥Î Rnd ­«±Æ°}¦C
    For I = UBound(ReturnArray) To 0 Step -1
        'ÀH«ü¼ÐÁY´î°Ñ»P Rnd ªº°}¦C¤¸¯À
        J = Int((I + 1) * Rnd)
        '§âÀH¾÷«ü¨ìªº¤¸¯À­È©ñ¨ì Buff
        '¥H§Q´`§Ç¤¸¯À­È¤ÎÀH¾÷¤¸¯À­È¥æ´«
        TempNum = ReturnArray(J)
        ReturnArray(J) = ReturnArray(I)
        ReturnArray(I) = TempNum
    Next
    '¶Ç¦^¸g Rnd ­«±Æªº°}¦C
    NoDoubleRnd = ReturnArray
End Function

Private Sub Command1_Click()
Dim Accept, I As Long

    '²M°£Åã¥Üªº ListBox
    List1.Clear

    '©I¥s NoDoubleRnd ¦Û­q¨ç¼Æ¨Ã±µ¦¬¶Ç¦^­È
    Accept = NoDoubleRnd(0, 8)

    For I = 0 To UBound(Accept)
        List1.AddItem Accept(I)
    Next
End Sub

¦^¯Á¤Þ


²©öÀH¾÷Àɽs¿è¾¹


¥»µ{¦¡½d¨Ò¥Ü½d¤F¥H¤U¤@¨Ç¤èªk¡G

  1. ¥H¨Ï¥ÎªÌ¦Û­q«¬ºAÅܼƶ}±Ò Random¡C

  2. ¦p¦ó¨ú±o°O¿ýÁ`µ§¼Æ¡C

  3. ¦p¦ó¬°°O¿ý¥[¤W§R°£°O¸¹¡C

  4. ¦p¦ó»s§@°O¿ý«ü¼Ð¾¹¡C

  5. ¦p¦ó²¾°£¥´¤W§R°£°O¸¹ªº°O¿ý¡C

VERSION 5.00
Begin VB.Form frmRandom
   Caption         =   "²©öÀH¾÷Àɽs¿è¾¹"
   ClientHeight    =   4170
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5445
   LinkTopic       =   "Form1"
   ScaleHeight     =   4170
   ScaleWidth      =   5445
   StartUpPosition =   3  '¨t²Î¹w³]­È
   Begin VB.CommandButton btnClearData
      Caption         =   "²M°£§R°£°O¿ý"
      Height          =   495
      Left            =   2880
      TabIndex        =   13
      Top             =   3480
      Width           =   2175
   End
   Begin VB.CommandButton btnDelete
      Caption         =   "§R°£"
      Height          =   495
      Left            =   2880
      TabIndex        =   12
      Top             =   2760
      Width           =   2175
   End
   Begin VB.CommandButton btnAdd
      Caption         =   "·s¼W"
      Height          =   495
      Left            =   2880
      TabIndex        =   11
      Top             =   2040
      Width           =   2175
   End
   Begin VB.CommandButton btnEdit
      Caption         =   "§ó·s"
      Height          =   495
      Left            =   2880
      TabIndex        =   10
      Top             =   1320
      Width           =   2175
   End
   Begin VB.CommandButton btnDown
      Caption         =   "¤U¤@µ§"
      Height          =   495
      Left            =   4080
      TabIndex        =   9
      Top             =   600
      Width           =   855
   End
   Begin VB.CommandButton btnUp
      Caption         =   "¤W¤@µ§"
      Height          =   495
      Left            =   2880
      TabIndex        =   8
      Top             =   600
      Width           =   975
   End
   Begin VB.TextBox txtSalary
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   3360
      Width           =   1695
   End
   Begin VB.TextBox txtName
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   2280
      Width           =   1695
   End
   Begin VB.TextBox txtNo
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   1200
      Width           =   1695
   End
   Begin VB.Label Label5
      Caption         =   "­û¤uÁ~¸ê"
      Height          =   255
      Left            =   240
      TabIndex        =   7
      Top             =   2880
      Width           =   1695
   End
   Begin VB.Label Label4
      Caption         =   "­û¤u©m¦W"
      Height          =   255
      Left            =   240
      TabIndex        =   5
      Top             =   1800
      Width           =   1695
   End
   Begin VB.Label Label3
      Caption         =   "­û¤u½s¸¹"
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   720
      Width           =   1695
   End
   Begin VB.Label Label2
      Caption         =   "Label2"
      Height          =   255
      Left            =   1680
      TabIndex        =   1
      Top             =   120
      Width           =   1575
   End
   Begin VB.Label Label1
      Caption         =   "ÀÉ®×°O¿ý"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   1215
   End
End
Attribute VB_Name = "frmRandom"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type MyType
    '§R°£°O¿ýÄæ¦ì
    Del As Boolean
    No As Long
    Name As String * 8
    Salary As Single
End Type
'¶}Àɽs¸¹
Dim FileHandle As Integer
'¦s¨úÄæ¦ì¸ê®Æ¦Û­qÅܼÆ
Dim MyMan As MyType
'¹ê»ÚªºÁ`°O¿ý¼Æ
Dim RealNo As Long
'Á`°O¿ý¼Æ
Dim FileLength As Long
'²{¦b°O¿ý½s¸¹
Dim RecNo As Long
'«ü¼Ð°}¦C
Dim Pointer() As Long
'§R°£«ü¼Ð
Dim IsDelete As Boolean
Private Sub btnAdd_Click()
    If Not (IsNumeric(txtNo.Text) And IsNumeric(txtSalary.Text)) Then
        MsgBox "¿é¤J¸ê®Æ¿ù»~"
        If RecNo <> 0 Then
            DataShow
        End If
        GoTo ReEnabled
    End If

    '²{°O¿ý¥[ 1
    RecNo = FileLength + 1
    '¹ê»Ú°O¿ý¥[ 1
    RealNo = RealNo + 1
    '°O¿ý°}¦C¥[ 1
    ReDim Preserve Pointer(FileLength)
    '±N¹ê»Ú¬ö¿ý­È¥[¨ì·s¤¸¯ÀùØ
    Pointer(FileLength) = RealNo
    'Á`°O¿ý¤]¥[ 1
    FileLength = RecNo
    DataSave
    DataShow

ReEnabled:
    If FileLength = 0 Then
        NoRecord
    Else
        btnDown.Enabled = False
        If RecNo > 1 Then
            btnUp.Enabled = True
        End If
    End If

    txtNo.SetFocus
End Sub
Private Sub btnClearData_Click()
Dim TempHandle As Integer, I As Long
Dim TempMan As MyType

    '¶}¼È¦sÀÉ
    TempHandle = FreeFile
    Open "c:\temp\test.tmp" For Random As #TempHandle Len = Len(TempMan)

    'µL°O¿ý«h¸õ¦Ü¿ù»~³B²zµ{§Ç
    On Error GoTo ArrayInDexWrong
    '±N¸ê®ÆÀÉ¥¼§R°£°O¿ý¼g¤J¼È¦sÀÉ
    For I = 0 To UBound(Pointer)
        Get #FileHandle, Pointer(I), MyMan
        TempMan.Del = False
        TempMan.No = MyMan.No
        TempMan.Name = MyMan.Name
        TempMan.Salary = MyMan.Salary

        Put #TempHandle, I + 1, TempMan
    Next

ArrayInDexWrong:

    'Ãö³¬¸ê®ÆÀɤμȦsÀÉ
    Close #TempHandle
    Close #FileHandle

    '¥Î¼È¦sÀÉÂл\¸ê®ÆÀÉ
    FileCopy "c:\temp\test.tmp", "c:\temp\test.txt"
    '§R°£¼È¦sÀÉ
    Kill "c:\temp\test.tmp"

    '§R°£«ü¼Ð°}¦C
    Erase Pointer
    '­«·s¸ü¤J¸ê®Æ
    LoadData
End Sub
Private Sub btnDelete_Click()
Dim I As Long

    '³]§R°£«ü¼Ð¬°¯u
    IsDelete = True
    DataSave

    '­«±Æ«ü¼Ð°}¦C
    If FileLength = 1 Then
        Erase Pointer
    Else
        For I = RecNo To FileLength
            If I <> FileLength Then
                Pointer(I - 1) = Pointer(I)
            End If
        Next
        ReDim Preserve Pointer(FileLength - 2)
    End If

    RecNo = RecNo - 1
    FileLength = FileLength - 1

    If FileLength = 0 Then
        NoRecord
        TextClear
        ShowRec
    Else
        If RecNo = 0 Then RecNo = FileLength
        DataShow
    End If

    txtNo.SetFocus
End Sub
Private Sub btnDown_Click()
    RecNo = RecNo + 1
    DataShow
    txtNo.SetFocus
End Sub
Private Sub btnEdit_Click()
    DataSave
    txtNo.SetFocus
End Sub
Private Sub btnUp_Click()
    RecNo = RecNo - 1
    DataShow
    txtNo.SetFocus
End Sub
Private Sub Form_Load()
    LoadData
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Close #FileHandle
End Sub
Private Sub DataShow()
    'Ū¤J«ü¼Ð°}¦C¸ê®Æ
    Get #FileHandle, Pointer(RecNo - 1), MyMan
    txtNo.Text = MyMan.No
    txtName.Text = MyMan.Name
    txtSalary.Text = MyMan.Salary

    If RecNo <> 1 Then
        btnUp.Enabled = True
    Else
        btnUp.Enabled = False
    End If

    If RecNo <> FileLength Then
        btnDown.Enabled = True
    Else
        btnDown.Enabled = False
    End If
    ShowRec
    OpenEdit
End Sub
Private Sub DataSave()
    '¨Ì§R°£«ü¼Ð¨M©w Del Äæ­È
    MyMan.Del = IsDelete
    MyMan.No = CLng(txtNo.Text)
    MyMan.Name = txtName.Text
    MyMan.Salary = CSng(txtSalary.Text)

    Put #FileHandle, Pointer(RecNo - 1), MyMan

    '±N§R°£«ü¼Ð´_¤¸
    IsDelete = False
End Sub
Private Sub ShowRec()
    Label2.Caption = RecNo & "/" & FileLength
End Sub

Private Sub LoadData()
Dim I As Long, J As Long
    FileHandle = FreeFile
    Open "c:\temp\test.txt" For Random As #FileHandle Len = Len(MyMan)
    '°Oºâ¹ê»ÚÁ`°O¿ý¼Æ
    RealNo = LOF(FileHandle) / Len(MyMan)
    If RealNo <> 0 Then
        For I = 1 To RealNo
            Get #FileHandle, I, MyMan
            '¥u§â¥¼§R°£°O¿ý©ñ¤J«ü¼Ð°}¦CùØ
            If Not MyMan.Del Then
                ReDim Preserve Pointer(J)
                Pointer(J) = I
                J = J + 1
            End If
        Next
    End If

    '¥¼§R°£°O¿ýÁ`¼Æµ¥©ó«ü¼Ð°}¦C¼Æ
    FileLength = J

    If FileLength = 0 Then
        ShowRec
        NoRecord
    Else
        RecNo = 1
        DataShow
    End If

End Sub
Private Sub NoRecord()
    btnUp.Enabled = False
    btnDown.Enabled = False
    btnEdit.Enabled = False
    btnDelete.Enabled = False
    btnClearData.Enabled = False
End Sub
Private Sub OpenEdit()
    btnEdit.Enabled = True
    btnDelete.Enabled = True
    btnClearData.Enabled = True
End Sub
Private Sub TextClear()
    txtNo.Text = ""
    txtName.Text = ""
    txtSalary.Text = ""
End Sub

¦^¯Á¤Þ


ListBox ªº Item Move & Disabled


±H¥óªÌ: Jessie

ListBox¸Ì¦³¤@¨Ç¿ï¶µ,µM«á§Ú·QÂI¿ï¤@­Ó¿ï¶µ,©¹¤W©Î¤U©ì¦², ÁÙ¦³¦pªG§Ú·QÅý Listbox¸Ìªº¨ä¤¤¤@­Ó¿ï¶µDisable,¥i¥H¬Ý±o¨ì¨º­Ó¿ï¶µ,¦ýµLªkÂI¿ï¨º­Ó¿ï¶µ,¦Ó¥B¤]¥i¥H§ïÅÜ¥¦ªºÃC¦â,¤S­n¦p¦ó³]©w©O?

¦Ñ©Çµª¡G

  1. List ¶µ¥Ø¬J¸g AddItem «á¦ì¸m§Y§i½T©w¡A­n§ïÅÜ¥u¦³­«±Æ¡C
  2. ListBox Item µL Disable ÄÝ©Ê¡A¦ý¨C­Ó Item ³£¦³¤@­ÓªþÄÝÄÝ©Ê¥sItemData(ItemData ¤£·|Åã¥Ü¦b ListBox ùØ)¡A³o¬O¤@­Óªø¾ã¼Æªº¸ê®Æ«¬ºA¡A§Ú­Ì¥i¥H§Q¥Î¥¦°µ¥¦°µ Diabled «ü¼Ð¡AÄ´¦p»¡ ItemData =-1 ªí Disable¡C
  3. ListBox ªº Item µLªk³æ¿W³]©wÃC¦â¡A°t¦X«e­± ItemData ³]©w¡A§A¥i¥H¥t¥~¦w±Æ¤@Label Åã¥Ü«D®Ö¨úª¬ºA¡C
  4. ¥H¤U§Y¬°¤@­Ó´À¥N¤è®×¡G
    Option Explicit
    '°õ¦æ¥»µ{¦¡½Ð¦b Form ¤W¥¬¸m List1,Command1,Command2
    '¤Î Label1
    Dim MousePick As Long

    Private Sub Command1_Click()
        If List1.ListIndex > -1 Then
            List1.ItemData(List1.ListIndex) = -1
        End If
    End Sub

    Private Sub Command2_Click()
        If List1.ListIndex > -1 Then
            List1.ItemData(List1.ListIndex) = 0
        End If
        Label1.Caption = ""
    End Sub

    Private Sub Form_Load()
        List1.AddItem "aaa"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "bbb"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "ccc"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "DDD"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "EEE"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "fff"
        List1.ItemData(List1.NewIndex) = 0
        List1.AddItem "ggg"
        List1.ItemData(List1.NewIndex) = 0

        Command1.Caption = "³]©w«D®Ö¨ú¶µ¥Ø"
        Command2.Caption = "¨ú®ø«D®Ö¨ú¶µ¥Ø"
    End Sub

    Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As
    Single, Y As Single)
        Label1.Caption = ""
        If Button = 1 Then
            MousePick = List1.ListIndex
            If List1.ItemData(MousePick) = -1 Then
                Label1.Caption = "[" & List1.List(MousePick) & "]¤£¥i¿ï¨ú"
            End If
        End If
    End Sub

    Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single,
    Y As Single)
    Dim varList() As String, TempString
    Dim varItem() As Long, TempNum As Integer
    Dim I As Long

        If Button = 1 Then
            If MousePick <> List1.ListIndex Then
                ReDim varList(List1.ListCount - 1)
                ReDim varItem(List1.ListCount - 1)
                For I = 0 To List1.ListCount - 1
                    varList(I) = List1.List(I)
                    varItem(I) = List1.ItemData(I)
                Next
                TempString = varList(List1.ListIndex)
                varList(List1.ListIndex) = varList(MousePick)
                varList(MousePick) = TempString
                TempNum = varItem(List1.ListIndex)
                varItem(List1.ListIndex) = varItem(MousePick)
                varItem(MousePick) = TempNum
                List1.Clear
                For I = 0 To UBound(varItem)
                    List1.AddItem varList(I)
                    List1.ItemData(List1.NewIndex) = varItem(I)
                Next
            End If
        End If
    End Sub

¦^¯Á¤Þ


¤@­ÓFrame¨â²Õ¥H¤Wªº Option Buttons


VB ºô¤Í°Ý¡G

¦pªG­n¦b¦P¤@­ÓFrame¤¤,¥i¥H¾Ö¦³¨â²Õ¥H¤Wªºoption buttons...

Peter 榭G

¦b¦¹Frame ¤¤¦A¥[¨â­Ó Frame ©ñ option buutons

¦Ñ©Ç´¡ªá¡G

Frame.BorderStyle=0 ¡A·|Åý¨Ï¥ÎªÌ§¹¥þ·P¨ü¤£¨ì Frame ªº¦s¦b¡C

¦^¯Á¤Þ


¥Î And ­È°µ IF ±ø¥ó§PÂ_


word ¼¶¼g©ó¤å³¹

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  Label1.Caption = "no ascii code"
  Label2.Caption = "no ascii code"
  Label3.Caption = KeyCode
  If Shift And vbShiftMask Then

shift ©M vbshiftmask¥Îand¹BºâÅÞ¿è¶Ü, ÁÙ¬O¦³¨ä¥L·N¸q¡A¬°¦ó Shift ©M¨ä¥L«öÁä¤@°_«ö©M³æ¿W¥u«ö Shift ³£¯àÅã¥Ü ¦¨¥ß(True)? ³o¨â¥ó¨Æ¦bvb¤º³¡¤£¬O¹ï¤Þ¼Æ Shift¨Ó»¡¤£¦P¶Ü?

shift¼Æ­È ¨Æ¥ó ¥N¸¹
1 ³æ¿W«öshift vbshiftmask
3 shift+ctrl ¡@
5 shift+alt ¡@

!?§Ú¯uªº¤£À´?!

¦Ñ©Çµª¡G

  1. §Ú­Ì¥Î IF §PÂ_¦¡®É¡A§PÂ_±ø¥ó«¬ºA¤@¯ë¬O±Ä¥Î Boolean ¡A¦ý¤]¥i±Ä Integer or Long ¡A¥Î Integer or Long °µ§PÂ_±ø¥ó®É¡A¥u¦³§PÂ_±ø¥ó=0 ®É¤~§P¬° False¡A¨ä¥L³£¬O True¡C
  2. And ¹Bºâ¬O¤@ºØ¥]§t¹Bºâ¡A¦Ó¤£¬Oµ¥©ó¹Bºâ¡A¦p§A¦Û¤vªº¨Ò shift+ctrl=3¡A«h 3 and vbshiftmask ¡B3 and vbCtrlMask¡B3 and vbshiftmask+vbCtrlMask ³£¬O True ¡A¤]´N¬O³£¦¨¥ß¡A©Ò¥H¥u­n¤@¼Æ­È¥]§t¦b¥t¤@¼Æ­È¤¤¡AAnd ¹Bºâ³£·|¬O¯u¡C
  3. ÁÙ¬O¤@ÀYÃú¤ô¡H¦n§a¡A¦ì¤¸¹Bºâ¶}©l¡G
    1 and 0=0
    1 and 1=1
    0 and 0=0
    0 and 1=0

    ³o¬O and ¹Bºâ°ò¥»ªk«h¡A§A¸ÓÀ´ªº¡A¤£À´»°§Ö½ VB ¹Bºâ¤lªº Help¡C

    §Ú­Ì¥H Byte «¬ºAÁ|¨Ò¡G

    0="00000000"

    ¤]´N¬O¹Bºâ¥X¨Óµ²ªG¬O "00000000" ªº¤~³Q§P§@ False ¡A¨ä¥L³£¬O True¡C

    1="00000001" (vbShiftMask ªº­È)
    2="00000010" (vbCtrlMask ªº­È)
    3="00000011" (Shift+Ctrl ªº­È)

    1 and 3="00000001" and "00000011"="00000001" (µ²ªG«D "00000000"¡A±ø¥ó§PÂ_¬°
    True)
    2 and 3="00000010" and "00000011"="00000010" (µ²ªG¦P¤W)

    ¦Ü©ó 3 and 3 ¤£¥²¦AÁ|¨Ò¤F§a¡C
  4. ©Ò¥H IF Shift = ShiftCode ¬O­­¨î¹Bºâ¡A¥u¦³§¹¥þ¬Û¦P±ø¥ó¤~¦¨¥ß¡AIF Shift and ShiftCode ¬O¥]§t¹Bºâ¡A¥u­n¨ä¼Æ­È¥]§t¨ä¤¤¡A±ø¥ó´N¦¨¥ß¡C
  5. ¨Ã¤£¬O©Ò¦³¼Æ­È¦X¦b¤@°_³£¥i¥H°µ And ¹Bºâ¡A¨Ò¦p§Aªº¤@²Õ¼Æ¦r¬O 1,2,3,4 ¡A´NµLªk°µ And ¹Bºâ¡A¦]¬°·í¨t²Î¶Ç¦^¼Æ­È 3 ®É¡A­Ë©³¥Nªí¬O ¦P®É«ö 1,2 ©Î¥u«ö¤F 3 ¡H©Ò¥H¦b¼Æ­È±`¼Æ«Å§i®É­n±Ä¥Î 2^N ªº¤è¦¡¨Ó«Å§i¡A§Y 1,2,4,8,16...........¡A²{¦b§A¤F¸Ñ VB ¬°¤°»ò Shift =1 ¡ACtrl=2 ¡AAlt=4 ¤F§a¡A³o¬O«Ü¦n¥Îªº«Å§i§Þ¥©¡A¦pªG§A¤]·Q¨Ï¥Î And ¹Bºâ¥\¯à¡A³oºØ±`¼Æ«Å§i¤è¦¡ªº§Þ¥©§AÀ³¸Ó¾Ç°_¨Ó¡C

¦^¯Á¤Þ


TextBox ­­¿é¤J¼Æ¦r»P¤p¼ÆÂI


pute ¼¶¼g©ó¤å³¹

§Q¥ÎKeycode¨Ó­­¨îÁä½L¡A¥Î¥kÃ䪺¼Æ¦rÁä "Del"ªº"." keycode=110¡A¦]¦¹¼g¤F¥H¤Uªºµ{¦¡½X¡A¨Ó§@­­¨îÅýtext1¥u¯à¿é¤J ¼Æ¦r©Î¤p¼ÆÂI

Text_keydown()
dim a as long, b as string
for a=1 to len(text1.text)
b=mid(text.text,a,1)
if isnumeric(b)=false then
msgbox"±z¿é¤J«D¼Æ"
end if
end sub
¦ý¬O§Ú¿é¤J¤F 12.2 µ¥¦³¤p¼ÆÂIªº¸ê®Æ¤§«á«oÅã¥Ü «D¼Æ¦r¡H

¦Ñ©Çµª¡G

¦^¯Á¤Þ


¦C¥X Container ®e¾¹ùتºª«¥ó


Alex. Chang. ¼¶¼g©ó¤å³¹

¦U¦ì¥ý¶i ¦b³o¶¶¹D½Ð±Ð¤@¤U ­n¦p¦óª¾¹D Frame¤º¦³¨º´X­ÓOptionButton©O?(³oùØ«üªº¬O Runtime®É)¡H

¦Ñ©Çµª¡G

  1. [Function ®e¾¹¥]§tª«¥ó¬d¸ß] ¥i¥H¬d©Ò¦³¦¬¯Ç¾¹ªº¥]§tª«¥ó¡C
  2. ¨ç¼Æ©I¥sªº²Ä¤@­Ó°Ñ¼Æ¬O¦¬¯Ç¾¹¥»¨­¡C
  3. ¨ç¼Æ©I¥sªº²Ä¤G­Ó°Ñ¼Æ¬O VB Control ª«¥ó¥þ¦W¡A¥²¶·¥´¥¿½T¨Ãª`·N¤j¤p¼g¡C
  4. ²Ä¤G­Ó°Ñ¼Æ¤£¥´ªí¥Ü¦C¥X©Ò¦³¥]§tª«¥ó¡C
  5. [Function ®e¾¹¥]§tª«¥ó¬d¸ß]¶Ç¦^­È¬O¤@­Óª«¥ó°Ñ·Ó°}¦C¡A§A¥i¥H¥Î ±µ¦¬ª«¥ó(Index) ¨Ó°õ¦æ³Q°Ñ·Óª«¥óªº¤@¤ÁÄÝ©Ê¡B¤èªk¤Î¨Æ¥ó¡C
  6. ½d¨Ò¦p¤U¡G
    Option Explicit
    Private Sub Command1_Click()
    Dim ±µ¦¬ª«¥ó As Variant
    Dim I As Integer

        On Error GoTo ¨S¦³¶Ç¦^ª«¥ó

        ±µ¦¬ª«¥ó = ®e¾¹¥]§tª«¥ó¬d¸ß(Frame1, "OptionButton")

        For I = 0 To UBound(±µ¦¬ª«¥ó)
            Debug.Print ±µ¦¬ª«¥ó(I).Name
        Next

        Exit Sub

    ¨S¦³¶Ç¦^ª«¥ó:
        Select Case Err.Number
            Case 9
                MsgBox "®e¾¹¿ù»~©Î¨S¦³¥]§t¶µ¥Ø"
        End Select
    End Sub

    Private Function ®e¾¹¥]§tª«¥ó¬d¸ß(ByVal ®e¾¹ As Object _
            , Optional ByVal ¤ÀÃþ¦WºÙ As String) As Variant
    Dim ¶Ç¦^ª«¥ó() As Variant
    Dim ¦³«ü©wª«¥ó¦WºÙ As Boolean
    Dim ª«¥ó«ü¼Ð As Control
    Dim AddOne As Integer

        If ¤ÀÃþ¦WºÙ = "" Then
            For Each ª«¥ó«ü¼Ð In Me.Controls
                If ª«¥ó«ü¼Ð.Container Is ®e¾¹ Then
                    ReDim Preserve ¶Ç¦^ª«¥ó(AddOne)
                    Set ¶Ç¦^ª«¥ó(AddOne) = ª«¥ó«ü¼Ð
                    AddOne = AddOne + 1
                End If
            Next
        Else
            For Each ª«¥ó«ü¼Ð In Me.Controls
                If ª«¥ó«ü¼Ð.Container Is ®e¾¹ Then
                    If TypeName(ª«¥ó«ü¼Ð) = ¤ÀÃþ¦WºÙ Then
                        ReDim Preserve ¶Ç¦^ª«¥ó(AddOne)
                        Set ¶Ç¦^ª«¥ó(AddOne) = ª«¥ó«ü¼Ð
                        AddOne = AddOne + 1
                    End If
                End If
            Next
        End If

        ®e¾¹¥]§tª«¥ó¬d¸ß = ¶Ç¦^ª«¥ó

    End Function

¦^¯Á¤Þ


¦p¦ó³B²z¤ñ¿Ã¹õ¤jªº Form


±H¥óªÌ: sinrue

¦Ñ©Ç±z¦n:½Ð±Ð±z,½s¿èFORM1ªí³æ¤w¸g±N¥¦³Ì¤j¤Æ¤F(¥þ¿Ã¹õ),¦ý§Ú­n½s¿èªºªí®æ«o¤ñ¥¦¤j,¤]´N¬O»¡FORM1¯à¤£¯à¦³µe­±±²°Êªº¥\¯à³]©w,ÁÙ¦³,§Ú­n±NFORM1©Ò¹ºªºªí®æ¦C¦L¤U¨Ó,windowstate=2 §Q¥Îform1.printform°õ¦æ,µ²ªG¦L¥X¨Óªºªí®æªø and ¼e³£¤ñ­ì½Z¤p,¸Ó«ç»ò¿ì?ÁÂÁ±z«ü±Ð!

¦Ñ©Çµª¡G

¥Î¤@­Ó³Ì²³æªº¿ìªk¸Ñ¨M¡G

  1. ·s¼W¤@­Ó MDIForm ¡C
  2. §â§A­ì Form.MDIChild=True
  3. §â§A­ì Form.WindowsState=0 or 1
  4. ·í§A­ì Form ¤ñ MDIForm ¤j®É¡A¦ÛµM·|¦³±²¶b¥i©Ô¡A¤]´N¬O»¡§A¥i¥H§â Form ³]ªº«Ü¤j«Ü¤j(¯à°÷¦h¤j¨S¸Õ¹L)¡C
  5. ³o°ÝÃD§Ú¥»¨Ó«Ü¿ðºÃ­n¤£­n¦¬¶i¥»½g¡A¦]¬°©È¤H»¡¦Ñ©Ç¨S¦³½d¨Ò¦n¼g¡A¶}©l¦bÄé¤ô¤F¡F«á¨ÓÂà©À¤@·Q¡A¦³®É«Ü²³æªº°ÝÃD¡A¨S¤H¦b®ÇÃäÂI¤@¤U¡AÁÙ¯u·|·U·Q·U½ÆÂø¡A©Ò¥H´N§â¦¹½g·í°µÂI¤@¤Uªº½d¨Ò§a¡C

¦^¯Á¤Þ


¤À¦C¤¤¤å¡B­^¤å¦r«¬


  1. ¥»½d¨Òªº§Þ¥©¬O§Q¥Î VB stdole ¼Ò²Õ¤¤ªº StdFont ª«¥óªº Charset ÄݩʨӧP§O¤¤­^¦r«¬¡AStdFont.Charset = 136 ªº³£¬O¤¤¤å¦r«¬¡A¨ä¥L«hÂkÄÝ­^¤å¦r«¬¡C
  2. ¥t¤@­nª`·Nªº¬OFixedsys©M System ¦r«¬¡A³o¨â¦r«¬¦n¹³¬O¸òµÛ Windows »y¨¥ª©¥»¨«ªº,Windows95 ¤¤¤åª©¤¤¬OÂk¤J¤¤¤å¦r¶°ªº¡C
  3. ¥»µ{¦¡¥u¦b Windows95 ¤¤¤åª©´ú¸Õ¹L¡A­Y¦³¤£¥¿±`¤§³B¡A½Ð¨Ó«H§iª¾¡C

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   4140
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5955
   LinkTopic       =   "Form1"
   ScaleHeight     =   4140
   ScaleWidth      =   5955
   StartUpPosition =   3  '¨t²Î¹w³]­È
   Begin VB.TextBox Text2
      Alignment       =   2  '¾a¤¤¹ï»ô
      BeginProperty Font
         Name            =   "·s²Ó©úÅé"
         Size            =   14.25
         Charset         =   136
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   2760
      MultiLine       =   -1  'True
      TabIndex        =   6
      Top             =   3240
      Width           =   2775
   End
   Begin VB.TextBox Text1
      Height          =   375
      Left            =   240
      TabIndex        =   5
      Text            =   "Text1"
      Top             =   3480
      Width           =   2175
   End
   Begin VB.ListBox List2
      Height          =   2040
      Left            =   2520
      Sorted          =   -1  'True
      TabIndex        =   3
      Top             =   840
      Width           =   1935
   End
   Begin VB.ListBox List1
      Height          =   2040
      Left            =   240
      Sorted          =   -1  'True
      TabIndex        =   2
      Top             =   840
      Width           =   2055
   End
   Begin VB.Label Label3
      Caption         =   "Label3"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   3120
      Width           =   2055
   End
   Begin VB.Label Label2
      Caption         =   "Label2"
      Height          =   375
      Left            =   2640
      TabIndex        =   1
      Top             =   480
      Width           =   1695
   End
   Begin VB.Label Label1
      Caption         =   "Label1"
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   480
      Width           =   1935
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
Dim CheckFont As New StdFont
Dim I As Long
    Label1.Caption = "¤¤¤å¦r«¬"
    Label2.Caption = "­^¤å¦r«¬"
    Label3.Caption = "§A¿ï¥Îªº¿Ã¹õ¦r«¬"
    Text1.Text = "·s²Ó©úÅé"
    Text2.Text = "¦r«¬®ÄªG¹wÄý ABC"
    Text2.FontSize = 14

    Me.Show
    ChangeVisibleMode
    ShowLogo

    For I = 0 To Screen.FontCount - 1
        CheckFont = Screen.Fonts(I)
        If CheckFont.Charset = 136 Then
            List1.AddItem CheckFont.Name
        Else
            List2.AddItem CheckFont.Name
        End If
    Next
    Me.Cls
    ChangeVisibleMode
End Sub
Private Sub List1_Click()
    Text1.Text = List1.List(List1.ListIndex)
    SetTextFont
End Sub
Private Sub List2_Click()
    Text1.Text = List2.List(List2.ListIndex)
    SetTextFont
End Sub
Private Sub SetTextFont()
    Text2.Font = Me.Font
    Text2.FontSize = 14
    Text2.FontName = Text1.Text
End Sub
Private Sub ChangeVisibleMode()
Dim I As Integer
    For I = 0 To Me.Controls.Count - 1
        Me.Controls(I).Visible = Not Me.Controls(I).Visible
    Next
End Sub
Private Sub ShowLogo()
Dim ShowString As String
Dim Size As Integer
    ShowString = "¦r«¬¸ü¤J¤¤¡A½Ðµy«Ý¡C"

    Size = Me.FontSize
    Me.FontSize = 18

    Me.CurrentX = (Me.ScaleWidth - Me.TextWidth(ShowString)) / 2
    Me.CurrentY = (Me.ScaleHeight - Me.TextHeight(ShowString)) / 2

    Me.Print ShowString
    DoEvents

    Me.FontSize = Size
End Sub

¦^¯Á¤Þ


¦^­º­¶

1