Visual Basic Strings


Joined
Jun 13, 2005
Messages
148
Reaction score
0
Fun w/Visual Basic Strings...Can you solve?

OK, heres the deal.
Some words and phrases of the english luanguage are spelled the same backwards as they are frontwards.
I forget the name for this attribute though..
However i have been tinkering with a program designed to create these little beauties
They dont have to make sense at this poijnt, i just want to make them.

By combining a random 4 words from a list then checking them, i can do this.

But after checking about 4 million combinations ive yet to score one,or so i believe.

So if anyone is intriqued by this idea and wants to help, look at my prog... drop me a line or reply
 
Last edited:
Ad

Advertisements

Joined
Jun 13, 2005
Messages
148
Reaction score
0
oh c'mon no one gets a kick outta this, i've revamped the code and it performs much better have found several 2 word "palindromes"
 
Joined
Jun 13, 2005
Messages
148
Reaction score
0
neat little applet but not many real words, With mine i use a list of real words to create phrases though thay may not make sense..to hot.....its in RAW VB code and included exe's are older then the code, and unfortunately dont have vb on this machine to compile.
 
Joined
Apr 19, 2005
Messages
107
Reaction score
0
still cant see your code so i dont know exactly what you are doing. but ...
i have some java code (a bit elementary) but if u can grasp the concept im sure it could help:

static void funString()
{
String worda = "",
wordRev = "";
char wordTemp = ' ';
int length = 0;


System.out.print("\n\t\tPlease enter a word: ");
worda = getin.readString(); -------> storing the string

length = worda.length(); --------> geting the length

for(int i=length-1;i>=0;--i)
{
wordTemp = worda.charAt(i); -----> geting every character of the word

wordRev = wordRev.concat(Character.toString(wordTemp)); ----> conacatinating it backwards
}//END FOR


if(worda.equalsIgnoreCase(wordRev)) ----- checking to see if the initial word is equal to the word spelled backwards
System.out.println("\t\t\t" + worda + " is a palindrome.");

}//END FUNSTRING SUBROUTINE


this was an assignment a while ago ... but from what you are saying you want something that can find palindromes in phrases and sentences even with spaces. does it check for the spaces?
 
Joined
Jun 13, 2005
Messages
148
Reaction score
0
testoing is easy i wanna make em


ive got plenty of code

and using it in a database it workls though only with two words rihght now
to got
to hot
im i
at a


code;

Option Compare Database


Private Sub Command1_Click()

maxTries = 0
'maxTries = InputBox("Enter number of word combinations to try.", "Enter Number", , Form1.Top + 300, Form1.Left + 100)
maxTries = InputBox("howmany lopps")

'Text1.Visible = False 'hide final word box
'Command3.Visible = False 'hide load list button
blnCorrect = False 'word is no good
blnHALT = False 'set halt boolean to allow loops
For cow = 1 To maxTries 'entered by the user
For z = 1 To 30 '_______________
strletterA(z) = "" 'erase all
strletterB(z) = "" 'letters
Next z '----------------
z = 1 'reset variable

strword = "": str1stHalf = "": str2ndHalf = ""
strdirtyword = "" 'Clean important word strings
'*******
LoadWord 'duh...
'*******
'get rid of the spaces that shouldnt exist anyway
strdirtyword = Trim(strdirtyword)

'****************************************************
'IGNORE
If intloop = 10000 Then
intloop = intloop 'set stop here
'useless code for debug stop
End If
'*************************************************

'remove spaces and any non letter characters
For z = 1 To Len(strdirtyword)
'pull one letter at a time and check
strtempletter = Mid(strdirtyword, z, 1)
'next line for debug purposes
'Text2.Text = Asc(strtempletter)
'if the characters "ok" add it to "clean" string
If Asc(strtempletter) > 96 And Asc(strtempletter) < 124 Then
strword = strword & strtempletter
Else
strtempletter = "" ' clean if not
End If
Next z
z = 1 'reset variable

'begin work


v = Len(strword) 'save integer for extarction calc.
'extract halves
If v / 2 = Int(v / 2) Then
'if the rounded value
'and orig. are = then
'words even...
str1stHalf = Left(strword, v / 2)
str2ndHalf = Right(strword, v / 2)
Else
'odd word
'this may be flawed....
str1stHalf = Left(strword, (Int(v / 2))) 'might round up (bad)
str2ndHalf = Right(strword, (Int(v / 2)))

End If

'*************************************
'Reverse 2nd half to mirror first
str2ndHalf = StrReverse(str2ndHalf)
'works
'**************************************

'extract letters
For x = 1 To Len(str1stHalf)
'save each to array
strletterA(x) = Mid(str1stHalf, x, 1)
strletterB(x) = Mid(str2ndHalf, x, 1)
Next x
'check letters
For y = 1 To Len(str1stHalf)
If strletterA(y) = strletterB(y) Then
blnCorrect = True
Else
blnCorrect = False
Exit For
End If
Next y


If blnCorrect = True Then
saveword 'store in array to print
End If
Next cow
Text1 = strdirtyword 'show last combo

'Text1.Visible = True
'Command4.Visible = False
' Command3.Visible = False
With Command2
.Visible = True
.Caption = "Try Another"
End With
If L = 0 Then
Label4.Caption = "sorry no luck, " & cow & " Tries."
Else

'notify off succcess
Label4.Caption = "Log Printed to file!, " & L & " successes."


End If
'give em the fireworks
Label4.Visible = True

End Sub

Private Sub Command2_Click()
'try again button resets
'Text1.Visible = True
'Text1 = ""
'Image1.Visible = False
Label4.Visible = False
Label4.Caption = ""

Command1.SetFocus
Command2.Visible = False

Command1.Visible = True
L = 1
End Sub

Private Sub Command3_Click()
'load list
Form1.Hide
Form2.Show
End Sub

Private Sub Form_Load()
Command1.Caption = "Click to Decode"
L = 0 ' number of words found
End Sub






module called

Option Compare Database

Public varwordnumber As Integer
Public maxcount, logprint As Integer
Public maxTries, intloops As Long
Public varword As String
Public strdirtyword, strword, str1stHalf, str2ndHalf, strtempletter As String
Public v, x, y, z, T, L As Integer
Public strletterA(1 To 50) As String
Public strletterB(1 To 50) As String
Public blnCorrect As Boolean
Public strwhatchama(1 To 500) As String
Public blnHALT As Boolean


Public Sub LoadWord()
'declare database,recordset,and variables


Dim db As Database
Dim rec As Recordset
Dim intRecords As Integer
Set db = CurrentDb()


'set upper bound record, not to exceed

Set rec = db.OpenRecordset("words")
intRecords = rec.RecordCount
'move to first record, although should be default...safety first

'GENERATES RANDOM NUMBER WHICH WILL CHOOSE WORD FROM LIST
Randomize
'loop through records finding case number

For T = 1 To 2 ' numbr of words to join
varwordnumber = Int(Rnd * intRecords) + 1
rec.MoveFirst

For x = 1 To intRecords
If x = varwordnumber Then
varword = rec![word] 'save to temp
strdirtyword = strdirtyword & varword & " "
Else
rec.MoveNext
End If ''add to joined string with spaces
Next x


Next T
x = 1
rec.Close
End Sub

Public Sub saveword()
L = L + 1
strwhatchama(L) = strdirtyword
'strwhatchama(L) = strword
Dim db As Database
Dim rec As Recordset
Dim intRecords As Integer
Dim strIndex As String
Set db = CurrentDb()
Set rec = db.OpenRecordset("palindromes")

With rec
.AddNew

![palindromes] = strwhatchama(L)
.Update
End With
rec.Close
End Sub
 
Ad

Advertisements

Joined
Apr 19, 2005
Messages
107
Reaction score
0
im not really a VB person although im in an intro vb.net class but your problem sounded cool. so you have a list of words in a database? you have a loop that goes through the whole database? every word you get rid of the spaces, get rid of symbols and stuff and you find the middle and split it? (after this it gets kinda hazy) u reverse the second half and check to see if they have the same amount of letters? (u said there might be a flaw if it rounds the first half up) im not sure but isnt there a function that can make it not round at all cuz im thinkin that might be a way to get the best result from that ... u have a boolean checking to see if it is equal or not? ... then it loses me ... i dont have a vb compiler and i dont know vb code so i guess im no help huh ... i still dont understand what u mean by creating one
 
Ad

Advertisements

Joined
Jun 13, 2005
Messages
148
Reaction score
0
It Has Arrived

iTS DONE!!!! AND WORKSS

OK im a big dork but i get a huge kick outta this.

my prgram is no longer random, rather it stores an entire word list into an array,
then, dependent on the amount of words you, the user, choose to join( 2 to 7); it systematically climbs through all possible combinations. because combinations can exceed the trillions, it also allows for "broken" runs, continuing where it laast left off.


all successful palidromes are saved to a log file.
all phrases with 2 repeateing wortds are thrown out before thier tested.
and thanks to "thamenace" the actual check process has been reduced greatly now only flipping the string and checking

the zipped Builder,wordlists,and wordlist counter are included below

i look foward to any comments, anyone may have...be critical please
 

Attachments

Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top