首頁  >  文章  >  軟體教學  >  VB中實作大寫字母轉換和百分比計算有哪些方法?

VB中實作大寫字母轉換和百分比計算有哪些方法?

WBOY
WBOY轉載
2024-01-17 10:06:16855瀏覽

VB中實作大寫字母轉換和百分比計算有哪些方法?

vb中把小寫文字轉換成大寫還有個問題VB怎麼百分比

直接複製下面的程式碼到窗體測試即可Private Sub Form_Load()

Dim small As String

Dim Big As String

Dim xiaoShu As Single

##Dim BaifenShu As String

#small = InputBox("請輸入一個字串")

Big = UCase(small)

MsgBox "你輸入的字串轉換成大寫後結果為:" & vbCrLf & Big

xiaoShu = InputBox("請輸入一個需要轉換為百分比的小數:")

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

MsgBox "你輸入的小數對應的百分數為:" & BaifenShu

End Sub

VB寫一個文字方塊中對輸入的字元進行轉換的程式

例如因為你輸入大寫時,觸發 text_change 事件,會改為小寫,而這樣又會觸發 change 事件,又把小寫改為大寫,這樣就是死循環,導致溢出

可以定義一個變數保存目前狀態,當改變一次就不再執行,直到有鍵盤或滑鼠輸入時恢復

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設計對輸入的字元進行轉換的程式

嚴格的說來回車和Backspace鍵也不應該轉換,轉換了2個文字就跟不上進度了,只不過只有按照樓主的要去做

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###

以上是VB中實作大寫字母轉換和百分比計算有哪些方法?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:docexcel.net。如有侵權,請聯絡admin@php.cn刪除