earlscott
05-31-2003, 06:14 PM
Trying to write VB code to view the file and generate a message box that tells me how many times each number appears.
I can load the file on a text box, but need to put a message box that states the number xx occurs the most and it appears xx times.
Thanks
MikeJ
05-31-2003, 06:20 PM
There might be an easier way, but this should work too...
Dim sTimes() as string 'sets it as a variable
sTimes = Split(Text1.Text, "2") 'splits for the number 2
MsgBox "The number 2 occurred the most, and it appeared " & Ubound(sTimes) + 1 & "times."
' the above line shows the msg box, and the +1 is necessary unless you have Option Base 1.
That code splits for 2, so if it is some other number, replace 2 with whatever it is.
Hope this helps,
~MikeJ
Squirm
05-31-2003, 06:24 PM
http://www.xbeat.net/vbspeed/c_InStrCount.htm
earlscott
05-31-2003, 06:37 PM
I think I need to clarify a little what I am trying to do.
Sorry, just a beginner in this VB.
I have a text box, with LOAD, EXAMINE, PRINT and EXIT command buttons.
I also have a text file that contains random numbers from 0 to 99, one under the next and so on.
When I click on the LOAD button, I want to load the text file and display a message on the text box, indicating xx records loaded.
When I click on the EXAMINE button, I want it to go thru the text file that has been loaded and determine how many times each number has occured and how many times, and display that info.
I am right now able to load the file, but it displays the entire text file on my text box.
Thanks
MikeJ
05-31-2003, 06:38 PM
That code I gave you will work for the EXAMINE button.
~MikeJ
earlscott
05-31-2003, 07:03 PM
Yes, it does work Mike.
But how do I get it to go thru the file and determine how many times a number appears(numbers in text file)?
Thanks
MikeJ
05-31-2003, 07:13 PM
Use the link that Squirm provided along with http://www.xbeat.net/vbspeed/IsGoodInStrCount.htm. They are very good functions, and I've found a new favorite site for code... (besides here, of course...)
~MikeJ