Hi, i'm a bit of a VB-virgin in destress :)
I've wrote some vb6 to manipulate words in a text-box.
It has some bugs but it does the main job.
I like to compare it with a real VB-expert solution.
Does any of you can show me a small program witch can:
- scan the textbox witch contains a text-document (some text lines) for words.
- jump to a sub so the letters of that word can be scrambled
- and jump back and replace the original word
- then find the next word in the document, until the end of the document.
- all other characters in the sentence need to be ignored witch are not a part of the abc (26 letters)
- only words witch are 4 or more cahracters of length ought to be manipulated
so far i've got this:
'==============================================
'Written by spinnetje 05-11-2005
'Visual Basic 6 - WordScramble
'==============================================
Option Explicit
'load a text file
Private Sub cmdFile_Click()
Dim strTemp As String
On Error GoTo dropout
strTemp = txtFile
txtFile = ""
dlg.FileName = "*.txt"
dlg.ShowOpen
If Dir(dlg.FileName) <> "" Then
txtFile = ""
Open dlg.FileName For Input As 1
While Not EOF(1)
Line Input #1, strTemp
txtFile = txtFile & strTemp & vbCrLf
Wend
Close #1
Else
dropout:
txtFile = strTemp
MsgBox "File not found"
End If
End Sub
-------------------------------------------------------
Private Sub cmdReplace_Click()
'only scramble single given word
opnieuw:
swpReplace
If txtFind = txtReplace And Len(txtReplace) > 3 Then GoTo opnieuw
' If Len(txtFile.SelText) > 0 Then txtFile.SelText = txtReplace
End Sub
-------------------------------------------------------
Private Sub swpReplace()
'scramble all found words
On Error GoTo weg
Dim leng1, x, y, ts, sw(20), rn, lp, jmr As Integer
Dim t$, tst$, m$, h(20) As String
leng1 = Len(txtFind)
If leng1 < 3 Or leng1 > 20 Then
weg:
Exit Sub
End If
y = 0
jmr = 0
x = 1
m$ = ""
tst$ = " ,.-!?$)" + Chr$(13)
ts = Len(tst$)
leng1 = leng1 - 1
'filter words by recognision of one of the characters of TST$
Do
x = x + 1
t$ = Mid$(txtFind, x, 1)
'check if not normal character
For y = 1 To ts
If t$ = Mid$(tst$, y, 1) Then
jmr = 1
Me.txtFind = Left$(Me.txtFind, x - 1)
End If
Next y
'finnish test
h(x) = t$
Loop While x < leng1
If jmr = 0 Then
'scramble
///SCRAMBLE CODE witch scrambles: txtReplace ////
'scramble done
Else
txtReplace = txtFind
End If
End Sub
-------------------------------------------------------
Private Sub cmdFindWords_Click()
Dim lngNumberOfWords, src, tlr As Long
Dim onemoment As String
Dim strWordArray() As String
'remove extra spaces
onemoment = Me.txtFile.Text
'split it
strWordArray = Split(onemoment, " ")
'Count words
lngNumberOfWords = UBound(strWordArray) + 1
Me.Teller.Text = Str$(lngNumberOfWords)
Me.txtFile.Text = ""
For src = 0 To Str$(lngNumberOfWords) - 1
Me.txtFind = strWordArray(src)
tlr = 0
again:
tlr = tlr + 1
swpReplace
If txtFind = txtReplace And Len(txtReplace) > 3 And tlr < 3 Then GoTo again
strWordArray(src) = txtReplace
Me.txtFile.Text = Me.txtFile.Text + txtReplace + " "
txtReplace = ""
Next src
Me.txtFile.Text = Left$(Me.txtFile.Text, Len(Me.txtFile.Text) - 1)
End Sub
------------------------------------------------
used:
textboxes: txtFile / txtFind / txtReplace
buttons: cmdFile / cmdReplace / cmdFindWords
Your feedback will be greatly appreciated !! :lol: