Click here to Skip to main content
15,887,746 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: vb 6.0 API Pin
Wes Aday21-Sep-12 8:54
professionalWes Aday21-Sep-12 8:54 
AnswerRe: vb 6.0 API Pin
Joan M20-Sep-12 6:37
professionalJoan M20-Sep-12 6:37 
Questionvb 2008 methods Pin
dcof18-Sep-12 8:28
dcof18-Sep-12 8:28 
AnswerRe: vb 2008 methods Pin
Richard MacCutchan18-Sep-12 9:44
mveRichard MacCutchan18-Sep-12 9:44 
GeneralRe: vb 2008 methods Pin
dcof19-Sep-12 4:04
dcof19-Sep-12 4:04 
GeneralRe: vb 2008 methods Pin
Steven St. John19-Sep-12 4:19
Steven St. John19-Sep-12 4:19 
AnswerRe: vb 2008 methods Pin
Paul Conrad19-Sep-12 5:33
professionalPaul Conrad19-Sep-12 5:33 
QuestionBytes overflowing despite modulo... [Solved] Pin
Saul Johnson16-Sep-12 13:28
Saul Johnson16-Sep-12 13:28 
Hello,

I've been thinking about this one for a long time. The following code always gives me an OverflowException when I run it:
VB
Dim x As Byte = 200
Dim y As Byte = 100
Dim z As Byte = (x + y) Mod 256

I know the problem is the fact that I'm adding two byte values together, which is exceeding the limits of the data type in the intermediate step (x + y) before the modulo 256 is performed and the result assigned to z. I can fix it if I do this:
VB
Dim x As Byte = 200
Dim y As Byte = 100
Dim z As Byte = (CInt(x) + CInt(y)) Mod 256

But that just seems like a lot of bother to achieve something that should be simple. One of my latest projects involved a lot of arithmetic like this and I can't help but wonder whether or not there's a better way of performing pure byte arithmetic with modulo operations without resorting to declaring larger integers all over the place or casting to and from them in code.

SixOfTheClock
A programming language is to a programmer what a fine hat is to one who is fond of fancy garden parties. Just don't try wearing any .NET language on your head. Some of them are sharp.


modified 17-Sep-12 5:21am.

AnswerRe: Bytes overflowing despite modulo... Pin
Dave Kreskowiak16-Sep-12 17:46
mveDave Kreskowiak16-Sep-12 17:46 
GeneralRe: Bytes overflowing despite modulo... Pin
Saul Johnson16-Sep-12 23:22
Saul Johnson16-Sep-12 23:22 
QuestionUpdater Help Pin
Bryan Muschter16-Sep-12 10:10
Bryan Muschter16-Sep-12 10:10 
AnswerRe: Updater Help Pin
Saul Johnson16-Sep-12 13:43
Saul Johnson16-Sep-12 13:43 
GeneralRe: Updater Help Pin
Bryan Muschter16-Sep-12 16:52
Bryan Muschter16-Sep-12 16:52 
AnswerRe: Updater Help Pin
Paul Conrad16-Sep-12 17:26
professionalPaul Conrad16-Sep-12 17:26 
GeneralRe: Updater Help Pin
Bryan Muschter17-Sep-12 15:01
Bryan Muschter17-Sep-12 15:01 
QuestionPrintPreviewControl InvalidatePreview wont triger Pin
JR21216-Sep-12 8:40
JR21216-Sep-12 8:40 
Questionshape of number Pin
memas6316-Sep-12 6:24
memas6316-Sep-12 6:24 
AnswerRe: shape of number Pin
Wes Aday16-Sep-12 6:44
professionalWes Aday16-Sep-12 6:44 
GeneralRe: shape of number Pin
memas6316-Sep-12 7:00
memas6316-Sep-12 7:00 
GeneralRe: shape of number Pin
Wes Aday16-Sep-12 7:08
professionalWes Aday16-Sep-12 7:08 
GeneralRe: shape of number Pin
memas6316-Sep-12 7:13
memas6316-Sep-12 7:13 
GeneralRe: shape of number Pin
Wes Aday16-Sep-12 7:18
professionalWes Aday16-Sep-12 7:18 
GeneralRe: shape of number Pin
memas6316-Sep-12 7:19
memas6316-Sep-12 7:19 
GeneralRe: shape of number Pin
Steven St. John16-Sep-12 16:03
Steven St. John16-Sep-12 16:03 
GeneralRe: shape of number Pin
memas6317-Sep-12 0:42
memas6317-Sep-12 0:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.