VB quetion

Hardware, Software, Internet, etc.

Moderators: Big-O Ryan, Big-O Mark, Matt, jester22c

Post Reply
User avatar
Timelessblur
Extreme Groupie
Extreme Groupie
Posts: 800
Joined: Sun Dec 15, 2002 9:06 pm
Contact:

VB quetion

Post by Timelessblur »

Well basicly I am now having to learn a little Visial Basic for one of my classes. I trying to keep any quetion that I have that pop up that I may need help on in this thread since I have a feeling I will have a lot of them.

Out of cursisity is there a round funition in VB because I need to round an intiger up. I can trick the comptuer into doing it with a if than else loop.

here is the code that teacher gave us in the example. It works but I am thinking there is an easier way to do it I just can not find it.

Code: Select all

        'Convert to an integer
        IntStamps = Convert.ToInt64(Stamps)

        'Rounding up if hte number of stamps is not exaclty divisible by 5
        If Sheets / 5 - IntStamps <= 0 Then
            txtStamps.Text = IntStamps
        Else
            txtStamps.Text = IntStamps + 1
        End If
This one more for my infomatoin but our final project which is 15% of our grade is more than likely going to be a VB project and we will have a homework dealling with them
http://www.myimgs.com/data/timelessblur ... omulan.jpg
Yeah I know I got pulled in but its a nice way to kill time
my link for kings of Choas
User avatar
Plasma2002b
Extreme Groupie
Extreme Groupie
Posts: 976
Joined: Thu Jul 18, 2002 11:36 pm
Location: Riverside, Ca
Contact:

Post by Plasma2002b »

what are you rounding?


like give what the numbers are that you get then say what the number is that you want
Image

its teh infamous life of brian gaut to teh max0r!
User avatar
Moon Child
Veteran
Veteran
Posts: 318
Joined: Sun Dec 15, 2002 6:45 pm
Location: Bowling Green, Ohio wishing I was with LP
Contact:

Post by Moon Child »

~Maeg

Resident LP Fanatic

*Nobody likes you when you're 23* - Blink 182

Image
User avatar
harra
Veteran
Veteran
Posts: 324
Joined: Thu Sep 12, 2002 7:03 am
Location: Houston, Texas
Contact:

Post by harra »

Timeless,

VB is one of the things I do for a living. What version are you using? VB6.0 or VB.NET?

This line:

Convert.ToInt64(x)

Doesn't look familiar to me and since I've never used VB.NET which a more object-oriented programing language (ala Java and C++), I'm wondering if you are using VB.NET
Ray

"Everybody needs friends. No one wishes to be without them. But never lose sight of the fact that it is your friends who will lead you along the paths that you will follow."
—Gordon B. Hinckley
User avatar
Timelessblur
Extreme Groupie
Extreme Groupie
Posts: 800
Joined: Sun Dec 15, 2002 9:06 pm
Contact:

Post by Timelessblur »

Yeah it is VB.net. I think Int64 is just converting the verble stamps to a 64 bit integer and then storing as Intstamps
http://www.myimgs.com/data/timelessblur ... omulan.jpg
Yeah I know I got pulled in but its a nice way to kill time
my link for kings of Choas
User avatar
harra
Veteran
Veteran
Posts: 324
Joined: Thu Sep 12, 2002 7:03 am
Location: Houston, Texas
Contact:

Post by harra »

Drat!

Unfortunately, I can't be of much help with VB.NET. My company hasn't upgraded any of their development platforms to the new .NET infrastructure. Since M$ still supports the 6.0 architecture, we still use it.

Maybe someone else here on the forum knows VB.NET, or try and locate a VB.NET related forum. THat is your best bet to get quick, informative answers to all your programming needs :)
Ray

"Everybody needs friends. No one wishes to be without them. But never lose sight of the fact that it is your friends who will lead you along the paths that you will follow."
—Gordon B. Hinckley
User avatar
Master Jedi
Guru
Guru
Posts: 1161
Joined: Sat Jun 15, 2002 10:34 pm
Contact:

Post by Master Jedi »

Timeless:

Math.Round() - Round nearest
Math.Ceiling() - Round up
Math.Floor() - Round down

Rounding to the nearest x (in your case your rounding UP to 5):

'Round up to 5
x = 121
x = 5*Math.Ceiling(x / 5)
'x is now 125

'Round down to 5
x = 123
x = 5*Math.Floor(x / 5)
'x is now 125

'Round to nearest 5
x = 123
x = 5*Math.Round(x / 5)
'x is now 125


It appears as though the function determines the number of stamps required to mail something by the number of pages, in which case you'd want:

NumOfStamps = Math.Ceiling(NumOfPages / 5)

So if "Sheets" were the number of pages and intStamps were the number of stamps, you'd want:

Code: Select all

        Sheets = 37 'Replace this line with the correct one to retrieve # of sheets
        intStamps = Math.Ceiling(Sheets / 5)
        txtStamps.Text = intStamps
By the example your teacher gave you, I think it's safe to assume he's an idiot. Why the hell would you need a 64 bit number to represent the number of stamps (as many as 2^63 - 1...high order bit represents pos/neg). That many stamps would cost $3,412,647,653,636,267,048.59 (something like a million times the combined net worth of everyone in the country)
User avatar
Master Jedi
Guru
Guru
Posts: 1161
Joined: Sat Jun 15, 2002 10:34 pm
Contact:

Post by Master Jedi »

Harra:

Convert is used to change the type of an expression. For instance if you have a string with a number in it A = "32" then Convert.ToInt16(A) would return a 16-bit number: 0000000000100000
User avatar
Plasma2002b
Extreme Groupie
Extreme Groupie
Posts: 976
Joined: Thu Jul 18, 2002 11:36 pm
Location: Riverside, Ca
Contact:

Post by Plasma2002b »

just wondering here..... wouldnt a type of cInt() function be better for that though?
Image

its teh infamous life of brian gaut to teh max0r!
User avatar
Master Jedi
Guru
Guru
Posts: 1161
Joined: Sat Jun 15, 2002 10:34 pm
Contact:

Post by Master Jedi »

Plasma2002b wrote:just wondering here..... wouldnt a type of cInt() function be better for that though?
CInt(), CStr(), CDbl(), etc. are not present in VB.NET. They were replaced by the Convert class.
User avatar
Timelessblur
Extreme Groupie
Extreme Groupie
Posts: 800
Joined: Sun Dec 15, 2002 9:06 pm
Contact:

Post by Timelessblur »

Thanks Jedi.
As for my teacher he is pretty good but when it comes to programing he does not know that much and hell we are Civil Engineers so it is not like he knows much hell it not like I am going to be learning that much in it. At did admite to the class that he knows very little about programing which is more than I can say for the EE/CS teacher teacher people here how to really program From what I am told this guy does not know how to program at all and he just teaching straight out of the book. I am so glad I am not a Computer science major
http://www.myimgs.com/data/timelessblur ... omulan.jpg
Yeah I know I got pulled in but its a nice way to kill time
my link for kings of Choas
User avatar
Master Jedi
Guru
Guru
Posts: 1161
Joined: Sat Jun 15, 2002 10:34 pm
Contact:

Post by Master Jedi »

I'm glad I'm not either. I'm a nuclear engineering major.
User avatar
harra
Veteran
Veteran
Posts: 324
Joined: Thu Sep 12, 2002 7:03 am
Location: Houston, Texas
Contact:

Post by harra »

Master Jedi wrote:Harra:

Convert is used to change the type of an expression. For instance if you have a string with a number in it A = "32" then Convert.ToInt16(A) would return a 16-bit number: 0000000000100000
I knew that. It is very similar to the C and Java programming I'm doing. I should've been clearer in my previous statement. What I meant to say was that since I know it wasn't present in VB6.0 (where I would've suggested the CInt() that Brian mentioned) it MUST be VB.NET.
Ray

"Everybody needs friends. No one wishes to be without them. But never lose sight of the fact that it is your friends who will lead you along the paths that you will follow."
—Gordon B. Hinckley
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest