DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   Convert Case To Random In Vb6 (http://www.daniweb.com/forums/thread181531.html)

clarkpoon Mar 14th, 2009 2:50 pm
Convert Case To Random In Vb6
 
Convert Case To Random In Vb6

I've only 1 Textbox & 1 Button... can anyone help my?

Thanks

cguan_77 Mar 14th, 2009 9:54 pm
Re: Convert Case To Random In Vb6
 
Quote:

Originally Posted by clarkpoon (Post 824953)
Convert Case To Random In Vb6

I've only 1 Textbox & 1 Button... can anyone help my?

Thanks

you like to convert a string but the position of the character to be converted will be controlled randomly or what?

clarkpoon Mar 15th, 2009 3:36 am
Re: Convert Case To Random In Vb6
 
^^

when i'll click the Button text in TEXTBOX shows Letters like...

ABCD to aBCd

every characters CASE Will change to RAnDom case...

clarkpoon Mar 15th, 2009 10:53 pm
Re: Convert Case To Random In Vb6
 
help me, guys :(

vb5prgrmr Mar 15th, 2009 11:37 pm
Re: Convert Case To Random In Vb6
 
Option Explicit

Private Sub Form_Load()
Text1.Text = "This is a test. This is only a test."
End Sub

Private Sub Command1_Click()
Randomize
Dim ForLoopCounter As Integer, TextLength As Integer, TempInt As Integer
TextLength = Len(Text1.Text)
For ForLoopCounter = 1 To TextLength
  If Mid(Text1.Text, ForLoopCounter, 1) <> " " Then
    TempInt = (Rnd * 1) + 1
    If TempInt > 1 Then
      ChangeCase ForLoopCounter, True, TextLength
    Else
      ChangeCase ForLoopCounter, False, TextLength
    End If
  End If
Next ForLoopCounter
End Sub

Private Sub ChangeCase(Position As Integer, UpperCase As Boolean, StringLength As Integer)
If Position = 1 Then
  If UpperCase = True Then
    Text1.Text = UCase(Left(Text1.Text, 1)) & Mid(Text1.Text, 2)
  Else
    Text1.Text = LCase(Left(Text1.Text, 1)) & Mid(Text1.Text, 2)
  End If
ElseIf Position = StringLength Then
  If UpperCase = True Then
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & UCase(Right(Text1.Text, 1))
  Else
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) & LCase(Right(Text1.Text, 1))
  End If
Else
  If UpperCase = True Then
    Text1.Text = Left(Text1.Text, (Position - 1)) & UCase(Mid(Text1.Text, Position, 1)) & Mid(Text1.Text, (Position + 1))
  Else
    Text1.Text = Left(Text1.Text, (Position - 1)) & LCase(Mid(Text1.Text, Position, 1)) & Mid(Text1.Text, (Position + 1))
  End If
End If
End Sub

clarkpoon Mar 16th, 2009 12:31 am
Re: Convert Case To Random In Vb6
 
thx vb5prgrmr :)


All times are GMT -4. The time now is 12:02 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC