|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
vb.net I have a text tob in the validation event of that text box I want to make sure thefitst word in each entry is capitialized.
ie (thanke for your help) entered in the text box should be displayed as (Thanks For Your Help) I just can't seem to find the code to do this |
|
#2
|
|||
|
|||
|
i think u will need to code that your self.
Its not too hard.... just loop thru the string like a char array, then whenever u see a space, capitalise the next letter. It hink there is a builtin funciton for capitalisation. in Straing.Something. if not just play with ascii code
__________________
Regards, James Yang .NET Developer / Network Engineer MCSE, MCDBA, MCSA, CCNA http://www.yellowpin.com/ http://www.opentechsupport.com/ |
|
#3
|
|||
|
|||
|
Hi Cinners
James gave you the absolute right suggestion. However, if you still didnt solve the problem. Here is the solution. I create 2 richtextboxs. Type your text in the richtextbox1 and click the button, you will get the expected result in the richtextbox2. Following is the VB.NET code, designed with VS.NET. Find the necessary codes. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox Friend WithEvents RichTextBox2 As System.Windows.Forms.RichTextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button() Me.RichTextBox1 = New System.Windows.Forms.RichTextBox() Me.RichTextBox2 = New System.Windows.Forms.RichTextBox() Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(88, 232) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(80, 24) Me.Button1.TabIndex = 1 Me.Button1.Text = "Button1" ' 'RichTextBox1 ' Me.RichTextBox1.Location = New System.Drawing.Point(32, 8) Me.RichTextBox1.Name = "RichTextBox1" Me.RichTextBox1.Size = New System.Drawing.Size(192, 88) Me.RichTextBox1.TabIndex = 2 Me.RichTextBox1.Text = "RichTextBox1" ' 'RichTextBox2 ' Me.RichTextBox2.Location = New System.Drawing.Point(32, 112) Me.RichTextBox2.Name = "RichTextBox2" Me.RichTextBox2.Size = New System.Drawing.Size(192, 88) Me.RichTextBox2.TabIndex = 3 Me.RichTextBox2.Text = "RichTextBox2" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox2, Me.RichTextBox1, Me.Button1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Function ProperCase(ByVal strText As String) As String 'Capitalize all first characters of the input string 'and set all the others to lowercase On Error GoTo Err_ProperCase Dim I As Integer, intLen As Integer, strTemp As String, strFinal As String Dim isSpace As Boolean strTemp = LCase(Trim(strText)) intLen = Len(Trim(strText)) isSpace = True For I = 1 To intLen If Mid(strTemp, I, 1) = Chr(32) Then strFinal = Mid(strFinal, 1, I - 1) & Chr(32) & Mid(strFinal, I + 1) isSpace = True ElseIf isSpace Then strFinal = Mid(strFinal, 1, I - 1) & UCase(Mid(strTemp, I, 1)) & Mid(strFinal, I + 1) isSpace = False Else strFinal = Mid(strFinal, 1, I - 1) & Mid(strTemp, I, 1) & Mid(strFinal, I + 1) End If Next I ProperCase = strFinal Exit_ProperCase: Exit Function Err_ProperCase: MsgBox(Err.Description & vbCrLf & strText, vbInformation, "ProperCase function") End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyStr As String MyStr = RichTextBox1.Text RichTextBox2.Text = ProperCase(MyStr) & "" End Sub End Class |
|
#4
|
||||
|
||||
|
lol - err - i think you may have gone a little over board iahmed... all he asked for was a capitalisation routine!
Code:
function capitalise(InString)
if InString = "" then InString = " "
InString = Replace(InString, "'","''")
FoundSpace = True
OutputString = ""
for MidPosition = 1 to len(InString)
if FoundSpace = true then
OutputString = OutputString & UCase(Mid(InString,MidPosition,1))
FoundSpace = false
else
OutputString = OutputString & LCase(Mid(InString,MidPosition,1))
if Mid(InString,MidPosition,1) = " " then FoundSpace = true
if Mid(InString,MidPosition,1) = chr(10) then FoundSpace = true
end if
next
Capitalise = trim(OutputString)
End Function
|
|
#5
|
|||
|
|||
|
Mr. Stumpy
all he needed following function in my codes: Public Function ProperCase(ByVal strText As String) As String ----------------------------------------------------------------------------- I just wanted him to extract the needed code. Did you get it? If not, try to remember Blaise Pacal. once he said: "Word differenly arranged have different meanings, and meanings differenly arranged have different effect." |
|
#6
|
|||
|
|||
|
I was looking for something like this This Workes fine It just took me somt time to find it.
Private Sub txtName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.Leave Dim HoldText As String HoldText = txtName.Text txtName.Text = (StrConv(HoldText, VbStrConv.ProperCase)) End Sub before StrConv(HoldText, bStrConv.ProperCase) thank you for your help! After Thank You For Your Help! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Camel Case |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|