vb.net - This code is supposed to output the number of times a word starts with a letter from the alphabet, but just displays zero for each one -
this code supposed output number of times word starts letter alphabet, displays 0 each 1 no errors, text file of letters , 0 each one.
when pressing debug button, appears nothing. here's code
imports system.io module module1 sub main() dim myarray new list(of string) using myreader streamreader = new streamreader(".\myfile.txt") 'telling vb we're using streamreader, read line @ time dim myline string myline = myreader.readline 'assigns line string variable myline while (not myline nothing) myarray.add(myline) 'adding list of words in array console.writeline(myline) myline = myreader.readline loop end using sortmyarray(myarray) 'calls new subroutine => sortmyarray, passing through parameter myarray, 'created on line 7 stores of lines read text file. 'console.readline() wordcount(myarray) end sub sub sortmyarray(byval mysort list(of string)) dim tmp string, writepath string = ".\sorted.txt" dim max integer = mysort.count - 1 dim mywriter streamwriter = new streamwriter(writepath) loop1 = 0 max - 1 loop2 = loop1 + 1 max if mysort(loop1) > mysort(loop2) tmp = mysort(loop2) mysort(loop2) = mysort(loop1) mysort(loop1) = tmp end if next mywriter.writeline(mysort.item(loop1).tostring()) next mywriter.dispose() end sub sub wordcount(byval stringarray list(of string)) dim alphabet string = "abcdefghijklmnopqrstuvwxyz", mystring string dim writepath string = ".\counted.txt" dim mywriter streamwriter = new streamwriter(writepath) dim countof(25) integer, max integer = stringarray.count - 1 loop1 = 0 25 mystring = alphabet.substring(loop1, 1) loop2 = 0 max if stringarray(loop2).substring(0, 1) = mystring countof(loop1) += 1 end if next mywriter.writeline(mystring & " occured " & countof(loop1) & " times ") next mywriter.dispose() end sub end module
any appreciated. thanks
Comments
Post a Comment