473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

help with my homework

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
7 1744
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
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
"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
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
with the onclick=openWindow() function I have to be able to pick a file and a location where I want that file to open. I have 4 files and 4 location. I know I have to write a if statement...
11
by: The_Kingpin | last post by:
Hi all, I'm new to C programming and looking for some help. I have a homework project to do and could use every tips, advises, code sample and references I can get. Here's what I need to do....
45
by: davy.zou | last post by:
I have started learning c++ and I need help. I need to write a program, the question is as follows. At a post office, there are a certain number of 2, 7, and 9cents stamps, now, given a total...
3
by: azzuri | last post by:
Hi, The title seems vague, but i could not think of anything more descriptive. I am creating a database and i am a bit stuck. I have started to create a database for pupils in a school. I...
62
by: vubaboota | last post by:
I HAVE SOME SERIOUS PROBLEM , HOW TO MAKE A PROGRAM IN C Q1: Write a program using malloc function. In which you take input from user and allocate memory equal to square of this number. Which...
19
by: mohammaditraders | last post by:
a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the...
20
by: zerobinary | last post by:
#include <algorithm> #include <iomanip> #include <ios> #include <iostream> #include <string> #include <vector> using namespace std; int main () { cout <<" plz enter your first name: ";
1
by: gator6688 | last post by:
I need to be able to save my additional data to my .dat file. The additional data is not part of the vector though. It is data I made after the vector. I have to save the finalGrade and letter grade...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.