Click here to Skip to main content
15,897,519 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
QuestionI need to copy a file into (anyone's) Startup Folder w/ no Access errors... Pin
WillB1215-Sep-12 22:45
WillB1215-Sep-12 22:45 
AnswerRe: I need to copy a file into (anyone's) Startup Folder w/ no Access errors... Pin
Richard MacCutchan16-Sep-12 0:18
mveRichard MacCutchan16-Sep-12 0:18 
GeneralRe: I need to copy a file into (anyone's) Startup Folder w/ no Access errors... Pin
WillB1216-Sep-12 0:39
WillB1216-Sep-12 0:39 
GeneralRe: I need to copy a file into (anyone's) Startup Folder w/ no Access errors... Pin
Richard MacCutchan16-Sep-12 1:07
mveRichard MacCutchan16-Sep-12 1:07 
GeneralRe: I need to copy a file into (anyone's) Startup Folder w/ no Access errors... Pin
WillB1216-Sep-12 3:23
WillB1216-Sep-12 3:23 

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.