VB 6文本框中的大写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB 6文本框中的大写相关的知识,希望对你有一定的参考价值。

vb 6.0中按Tab键或空格时如何制作大写的第一个字母?

我的代码如下

txtFirstName.Text = UCase$(txtFirstName.Text)

但它在标签或空格后不会改变

答案

使用LostFocus事件

Private Sub yourTextBox_LostFocus()
    With yourTextBox
        'first letter in upper case, the rest, untouched.
        .Text = UCase(Mid(.Text, 1, 1)) & Mid(.Text, 2, Len(.Text))
    End With
End Sub

将相同的逻辑应用于KeyDown事件并检查按下的键是否为空格键。

Private Sub yourTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 32 Then
        With yourTextBox
            'first letter in upper case, the rest, untouched.
            .Text = UCase(Mid(.Text, 1, 1)) & Mid(.Text, 2, Len(.Text))
            .SelStart = Len(.Text) 'put the cursor at the end of the textbox...
        End With
    End If
End Sub
另一答案
StrConv Function


Returns a Variant (String) converted as specified. 

Syntax

StrConv(string, conversion, LCID)

The StrConv function syntax has these named arguments:

Part Description 
string Required. String expression to be converted. 
conversion Required. Integer. The sum of values specifying the type of conversion to perform. 
LCID Optional. The LocaleID, if different than the system LocaleID. (The system LocaleID is the default.) 


Settings

The conversion argument settings are:

Constant Value Description 
vbUpperCase 1 Converts the string to uppercase characters. 
vbLowerCase 2 Converts the string to lowercase characters. 
vbProperCase 3 Converts the first letter of every word in string to uppercase. 

AND THERE IS MORE ...

到GSERGE

当应用于函数名而不是变量名时,$表示什么都不是。 VBA使用$ AND B作为后缀来表示类似的功能。

VB6是VBA的人说可能在VB6但不在VBA中。 VB6程序主机VBA作为其编程语言。 VB6本身就是一些应用程序对象和表单包 - 没有编程语言。最好将VB6视为像Office这样的VBA主机。

如果你想要正确的情况下看到这个WORDBASIC Ver 6代码,(哪个单词2003有助于转换为vba)。

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Sub MAIN()
Select Case WordBasic.Int(GetModifer)
        Case 0
                WordBasic.ChangeCase
        Case 1
                WordBasic.ChangeCase 4
        Case 2
                WordBasic.ChangeCase 2
        Case 3
                ProperCase
        Case Else
                WordBasic.ChangeCase
End Select
End Sub

Private Sub ProperCase()
Dim F
Dim z
Dim a$
Dim P
F = 1
WordBasic.ChangeCase 2
WordBasic.EditBookmark Name:="SerenityChangeCase", SortBy:=0, Add:=1
z = WordBasic.GetSelEndPos()
WordBasic.CharLeft 1
        While WordBasic.GetSelEndPos() < z And Not WordBasic.AtEndOfDocument()
                WordBasic.SelectCurWord
                a$ = WordBasic.[Selection$]()
                P = 0
                If LCase(a$) = "a" Then
                        P = 1
                ElseIf LCase(a$) = "an" Then
                        P = 1
                ElseIf LCase(a$) = "as" Then
                        P = 1
                ElseIf LCase(a$) = "at" Then
                        P = 1
                ElseIf LCase(a$) = "be" Then
                        P = 1
                ElseIf LCase(a$) = "by" Then
                        P = 1
                ElseIf LCase(a$) = "in" Then
                        P = 1
                ElseIf LCase(a$) = "is" Then
                        P = 1
                ElseIf LCase(a$) = "of" Then
                        P = 1
                ElseIf LCase(a$) = "on" Then
                        P = 1
                ElseIf LCase(a$) = "or" Then
                        P = 1
                ElseIf LCase(a$) = "to" Then
                        P = 1
                ElseIf LCase(a$) = "and" Then
                        P = 1
                ElseIf LCase(a$) = "are" Then
                        P = 1
                ElseIf LCase(a$) = "for" Then
                        P = 1
                ElseIf LCase(a$) = "the" Then
                        P = 1
                ElseIf LCase(a$) = "from" Then
                        P = 1
                ElseIf LCase(a$) = "what" Then
                        P = 1
                ElseIf LCase(a$) = "with" Then
                        P = 1
                End If
                If P = 1 And F = 0 Then WordBasic.Insert LCase(a$)
                WordBasic.WordRight 1
                F = 0
        Wend
WordBasic.WW7_EditGoTo Destination:="SerenityChangeCase"
WordBasic.EditBookmark Name:="SerenityChangeCase", SortBy:=0, Delete:=1
End Sub

Private Function GetModifer()
Dim a
Dim B
Dim c
Dim X
        a = GetAsyncKeyState(16)
        B = GetAsyncKeyState(17)
        c = GetAsyncKeyState(18)
        X = 0
        If a < 0 Then X = X + 1
        If B < 0 Then X = X + 2
        If c < 0 Then X = X + 4
GetModifer = X
End Function

以上是关于VB 6文本框中的大写的主要内容,如果未能解决你的问题,请参考以下文章

vb中怎样使记事本中的内容显示在文本框中

vb窗体程序运行时,文本框中的默认的文字怎么设置为空

VB禁止文本框输入

在 vb.net 的文本框中显示 datagridview 单元格数据

VB如何把文件内容显示在文本框中?

vb中怎么把时间格式化