Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PROBLEM SOLVED : NOW CONVERT DELPHI TO VISUAL BASIC

Status
Not open for further replies.

Cballe

Programmer
Apr 14, 2002
16
ZA
Hi,

I have came to this site with the same problem for a long time now, and due to the fact that I never came upon a real solution, I solved the problem in the language that I use, which is Borland Delphi and now just want to convert the code, that works fine, to do the same in Visual Basic.

Just in short:

The program that I am developing in Visual Basic (I am new to the language) is a speech recognition program. TextBox 1 gives the user some text to read and the same text is displayed in a ListBox (beneath each other). When the user read the text of TextBox1, thru a microphone, it is displayed in Textbox2. After the user have finished reading the text in TextBox1, the user click on a Calculate button and a percentage is given of how accurate the text of TextBox1, compares to the text in ListBox1.

The code below does the following:

· TextBox1 = masterstring. TextBox2 = teststring
· Each word in the masterstring is searched for in the teststring. When extra words are contained in the teststring, it is ignored. The order in which the words appear does not matter, just if the word exists.
· When a word is found in the teststring, it are removed form the teststring to make sure that the same word (that could appear again later) in the masterstring, are not compared several times with the first occurrence in the teststring.

Please – I hope this would help you all understand what is going on. Here is the code that I have developed in Borland Delphi, but I need some help to do the same in Visual basic – to use the same Algorithm:

}
procedure TfrmTextCompare.btbtnCalculateClick(Sender: TObject);
var s1, s2 : String;
i, iStart, iPos : Integer;
iFound : Integer;
sWord : String;
begin
//Extract words from s1 and put them into listbox
s1 := Copy(mString1.Text,1,Length(mString1.Text)-2) + ' ';
lstString1.Clear;
i := 1;
iStart := 0;
while i <= Length(s1) do
begin
if (s1 <> ' ') and (s1[i+1] = ' ') then //end of word
lstString1.Items.Add(Trim(Copy(s1,iStart,i-iStart+1)))
else
if (s1 = ' ') and (s1[i+1] <> ' ') then //start of word
iStart := i+1;
Inc(i);
end;

//Search for individual words in list box (master string) in the test string
iFound := 0;
s2 := ' ' + Copy(mString2.Text,1,Length(mString2.Text)-2) + ' ';

//Step through words in master string
for i := 0 to lstString1.Items.Count-1 do
begin
//Ensure that we don't find partial words, e.g. &quot;is&quot; inside &quot;disappear&quot;
sWord := ' '+ lstString1.Items + ' ';

//Determine if word occurs in the test string
iPos := Pos(sWord,s2);
if iPos > 0 then
begin
//Remove word form test string so that it is not used for
// subsequent occurrences of word in master string
Delete(s2,iPos+1,Length(lstString1.Items));
Inc(iFound);
end
end;

//Display results
lblRemainder.Caption := s2;
lblWordsInList1.Caption := 'Words in list 1: ' + IntToStr(lstString1.Items.Count);
lblFound.Caption := 'Found: ' + IntToStr(iFound);
lblPercentage.Caption := 'Percentage: ' + FloatToStrF((iFound)*100/lstString1.Items.Count,ffFixed,8,2);

end;


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top