It's a shame that neither responder thought to actually help you.
First off, when you get a value as a result of an expression, and you want
to use it in a comparison, it is often best to store the value in a variable
of the proper type. You are taking a string and converting to an integer in
the IF expression. This is cool for VB, but it can lead to some confusion,
as you can see here. Also, if you are using the 'str' prefix to mean
'String' then you are adding an integer to a string, which causes TWO data
conversions (first from string to int for the addition, then back to string
for storage). Declare the counter variables to be Integer.
So, first off:
Dim Numval as Integer
Dim ct18 as Integer
Dim ct35 as Integer
Numval = strRecord.Remove(0,2)
Now put that number into your logical expression:
If (Numval > 17) and (Numval < 36) Then
ct18 = ct18 + 1
Else If (Numval >35) and (Numval < 51) Then
ct35 = ct35 + 1
End If
Also:
[quoted text, click to view] > oh also how can i get the program not to input the under 18 here is my
> code am i missing something?
>
Your code block looks fine. It's the code that follows the End If that
worries me. You appear to be putting up a message box and then proceeding
with the logic. You need to have your routine return inside the 'If' block,
or put the logic for writing the record in an 'Else' block.
Good luck!
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
[quoted text, click to view] "tjshadyluver" <tjshadyluver@discussions.microsoft.com> wrote in message
news:B7D9B890-0392-4602-99BA-797867CE8AD4@microsoft.com...
> ok i have gotten this damn project almost done but i am frustrated on
> this one step. getting 18-35 together and 36-50 and so on. here is my
> code how can i get them combined in one line instead of writing it out a
> million times. please help me. i have to write a program that you type in
> the age and it stores it in a text file then i have to catagorize them and
> when i hit the read button it shows how many times 18-35 was typed in,
> then
> how many times 36-50 was typed in and so on.
>
> If strRecord.Remove(0, 2) = 18 Then
> strEighteen = strEighteen + 1
> ElseIf strRecord.Remove(0, 2) = 36 Then
> strThirtySix = strThirtySix + 1
> End If
> Loop
>
> it works if i put individual numbers in and continue it down but that is
> alot of code and i am sure there is an easier way
>
> oh also how can i get the program not to input the under 18 here is my
> code am i missing something?
>
> If Me.txtAge.Text <=18 Then
> MessageBox.Show("Your age must be 18 or older thank
> you", "POA", _
> MessageBoxButtons.OK, MessageBoxIcon.Information, _
> MessageBoxDefaultButton.Button1, _
> MessageBoxOptions.DefaultDesktopOnly)
> End If
>
> when i type in 17 for the age it still puts it in the text file. i need it
> to not store in the text file if it is less than 18.
> ok well that is my queestions please help me thanks very much
>
> Tommy
> Advanced Visual Basic .NET Programming Class