By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

help with my homework

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Mostly we don't help with homework, however a little help to bring you on
the right thrack
If strRecord.Remove(0, 2) = 18 Then
You probably mean Substring instead of Remove
strEighteen = strEighteen + 1
Using a string is not so nice you can use an Integer for that
ElseIf strRecord.Remove(0, 2) = 36 Then
strThirtySix = strThirtySix + 1
End If
Loop

If Me.txtAge.Text <=18 Then
Why <=18 and not simple <18
MessageBox.Show("Your age must be 18 or older thank
you", "POA", _
MessageBoxButtons.OK, MessageBoxIcon.Information, _
MessageBoxDefaultButton.Button1, _
MessageBoxOptions.DefaultDesktopOnly)
Else
do your storing
End If

Jul 21 '05 #2

P: n/a
First of all, what is "Advanced Visual Basic"?? Isn't that an oxymoron?

Anyway, my advice is that if you can't solve this trivial problem on
your own, either go back to "Basic Visual Basic" or pick a different
course of study, because you'll be screwed when you get to the
difficult problems.

JMHO.

Jul 21 '05 #3

P: n/a
"Patrick A" <pw*******@gmail.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
First of all, what is "Advanced Visual Basic"?? Isn't that an oxymoron?
Admittedly the juxtaposition of "Advanced" and "Basic" might seem
oxymoronic, but the fact of the matter is that there's very little that
Visual Basic.NET can't do as compared to C#. I do believe that the gap
between the languages will grow in future, e.g iterators, and anonymous
methods in C#2 and static form instances in VB.NET2 (shudder), but right now
they're on a pretty similar footing. If you can't have Advanced Visual
Basic.NET, you can't have Advanced .NET. Unless perhaps you feel that the
only advanced .NET programming is found in unsafe code blocks?
Anyway, my advice is that if you can't solve this trivial problem on
your own, either go back to "Basic Visual Basic" or pick a different
course of study, because you'll be screwed when you get to the
difficult problems.
And I take it you sprang from you mothers womb with a full-fledged knowledge
of all programming idioms? We should be encouraging beginners to learn
rather than trying to smash their self-confidence.

Keep in mind that the marketers for these courses call them Advanced this
and Expert that, but generally they all start off as beginner programming
courses, the difference between them being where they end up. Using the
courses name to hammer a beginner with hardly seems fair.

JMHO.

Jul 21 '05 #4

P: n/a
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:
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.
--
"tjshadyluver" <tj**********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.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

Jul 21 '05 #5

P: n/a
> It's a shame that neither responder thought to actually help you.

Beg your pardon?

I thought I actual did, I see not anything you have added to my answer.

:-)

You know that I am smiling now.

Cor
Jul 21 '05 #6

P: n/a
Sorry about that,Cor. My ISP sometimes drops news messages. I don't see
your response.

(or are you just pulling my leg :-)

--
--- 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.
--
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ot****************@TK2MSFTNGP09.phx.gbl...
It's a shame that neither responder thought to actually help you.

Beg your pardon?

I thought I actual did, I see not anything you have added to my answer.

:-)

You know that I am smiling now.

Cor

Jul 21 '05 #7

P: n/a
Nick,

I dont use my ISP anymore, I go directly to (by instance for this newsgroup)

news://news.microsoft.com/microsoft....dotnet.general

Although Google is as well good at time.
http://groups-beta.google.com/group/...fdd860e5242b7c

And I never will write things that could confuse an OP, maybe a regular
understand it, however a newbie does not.

Cor
Jul 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.