Home>Article>Software Tutorial> What are the methods to implement uppercase letter conversion and percentage calculation in VB?

What are the methods to implement uppercase letter conversion and percentage calculation in VB?

WBOY
WBOY forward
2024-01-17 10:06:16 829browse

What are the methods to implement uppercase letter conversion and percentage calculation in VB?

There is still a problem in converting lowercase text to uppercase in VB. How to use percentage in VB

Copy the following code directly into the form to test it Private Sub Form_Load()

Dim small As String

Dim Big As String

Dim xiaoShu As Single

Dim BaifenShu As String

small = InputBox("Please enter a string")

Big = UCase(small)

MsgBox "The string you entered will be converted to uppercase and the result will be:" & vbCrLf & Big

xiaoShu = InputBox ("Please enter a decimal that needs to be converted into a percentage:")

BaifenShu = CStr(xiaoShu * 100) & "%""

MsgBox "The percentage corresponding to the decimal you entered is:" & BaifenShu

End Sub

VB writes a program to convert the characters entered in the text box

For example, when you input uppercase, the text_change event is triggered, and it will be changed to lowercase, which will trigger the change event, and then change the lowercase to uppercase. This is an infinite loop, leading to overflow

You can define a variable to save the current state. When it is changed once, it will no longer be executed until there is keyboard or mouse input.

Dim b As Boolean

Private Sub t1_Change()

If b Then

b = False

t1.SelStart = Len(t1.Text)

a = Right(t1.Text, 1)

If Asc(a) >= 65 And Asc(a)

t1.Text = Mid$(t1.Text, 1, Len(t1.Text) - 1) LCase(a)

ElseIf Asc(a) >= 97 And Asc(a)

t1.Text = Mid$(t1.Text, 1, Len(t1.Text) - 1) UCase(a)

ElseIf Asc(a) = 32 Then

t1.Text = Mid$(t1.Text, 1, Len(t1.Text) - 1) a

Else

t1.Text = Mid$(t1.Text, 1, Len(t1.Text) - 1) "*""

End If

End If

End Sub

Private Sub t1_KeyDown(KeyCode As Integer, Shift As Integer)

b = True

End Sub

Private Sub t1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

b = True

End Sub

VB design program to convert input characters

Strictly speaking, the Enter and Backspace keys should not be converted. If you convert two texts, you will not be able to keep up with the progress. You can only do it according to the original poster's instructions.

Private Sub Form_Load()

Text1.Text = """

Text2.Text = """

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

Select Case KeyAscii

Case 65 To 90

Text2.Text = Text2.Text & LCase(Chr(KeyAscii))

Case 97 To 122

Text2.Text = Text2.Text & UCase(Chr(KeyAscii))

Case 32

Text2.Text = Text2.Text & Chr(KeyAscii)

Case Else

Text2.Text = Text2.Text & Chr(42)

End Select

End Sub

The above is the detailed content of What are the methods to implement uppercase letter conversion and percentage calculation in VB?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete