|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I increment a byte with out casting?want to do any casting. The code below does it but it is hard on the eyes. Dim lineNumber As Byte = 0 Dim incrementer As Byte = 1 For Each line As Line In mCollection lineNumber += incrementer line.LineNumber.Value = lineNumber Next I'd like to do something more like this Dim lineNumber As Byte = 0 For Each line As Line In mCollection lineNumber += 1y line.LineNumber.Value = lineNumber Next Where y is what ever suffix would create that nameless temporary object as a byte with the value of 1. Is there a way to do this? Is there a better way to increment a byte? Thanks, Russ Hi,
You make me curious, why are you using a processor cycles eating command with a byte for this kind of operations and not the normal Integer that fits directly in the accumulatorregisters from a 32bit computer. Cor <kosherpi***@hotmail.com> schreef in bericht Show quoteHide quote news:1149613900.634596.223270@i40g2000cwc.googlegroups.com... >I want to increment a byte when I have Option Strict on and I don't > want to do any casting. The code below does it but it is hard on the > eyes. > > Dim lineNumber As Byte = 0 > Dim incrementer As Byte = 1 > > For Each line As Line In mCollection > lineNumber += incrementer > line.LineNumber.Value = lineNumber > Next > > I'd like to do something more like this > > Dim lineNumber As Byte = 0 > > For Each line As Line In mCollection > lineNumber += 1y > line.LineNumber.Value = lineNumber > Next > > Where y is what ever suffix would create that nameless temporary object > as a byte with the value of 1. > > Is there a way to do this? Is there a better way to increment a byte? > > Thanks, > Russ > I honestly couldn't tell you. I'm working at a new place that is
dragging along a lot of converted VB6 code and I assume old databases; not that that justifies using a byte. I only mean to explain the environment I seem to be stuck in. When I've been here a while they might answer my asking that question with a "Fine you're so smart go fix it". Regardless, is there any way to increment a byte that doesn't look so goofy? Russ Cor Ligthert [MVP] wrote: Show quoteHide quote > Hi, > > You make me curious, why are you using a processor cycles eating command > with a byte for this kind of operations and not the normal Integer that fits > directly in the accumulatorregisters from a 32bit computer. > > Cor > > <kosherpi***@hotmail.com> schreef in bericht > news:1149613900.634596.223270@i40g2000cwc.googlegroups.com... > >I want to increment a byte when I have Option Strict on and I don't > > want to do any casting. The code below does it but it is hard on the > > eyes. > > > > Dim lineNumber As Byte = 0 > > Dim incrementer As Byte = 1 > > > > For Each line As Line In mCollection > > lineNumber += incrementer > > line.LineNumber.Value = lineNumber > > Next > > > > I'd like to do something more like this > > > > Dim lineNumber As Byte = 0 > > > > For Each line As Line In mCollection > > lineNumber += 1y > > line.LineNumber.Value = lineNumber > > Next > > > > Where y is what ever suffix would create that nameless temporary object > > as a byte with the value of 1. > > > > Is there a way to do this? Is there a better way to increment a byte? > > > > Thanks, > > Russ > > <kosherpi***@hotmail.com> schrieb:
>I want to increment a byte when I have Option Strict on and I don't You don't need to do any explicit casting!> want to do any casting. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried K. Wagner [MVP] wrote:
> <kosherpi***@hotmail.com> schrieb: Great! Care to tell me how to do it? Don't forget I said I don't want> >I want to increment a byte when I have Option Strict on and I don't > > want to do any casting. > > You don't need to do any explicit casting! > to do ANY casting implicit or explicit. Implicit won't work with Option Strict on. "Option Strict On disallows implicit conversions from 'Integer' to 'Byte'" I'm hoping I can create a nameless temporary Byte with a value of 1. I've seen this kind of thing done with suffixes. kosherpi***@hotmail.com wrote:
Show quoteHide quote > I want to increment a byte when I have Option Strict on and I don't Why not just use> want to do any casting. The code below does it but it is hard on the > eyes. > > Dim lineNumber As Byte = 0 > Dim incrementer As Byte = 1 > > For Each line As Line In mCollection > lineNumber += incrementer > line.LineNumber.Value = lineNumber > Next > > I'd like to do something more like this > > Dim lineNumber As Byte = 0 > > For Each line As Line In mCollection > lineNumber += 1y > line.LineNumber.Value = lineNumber > Next > > Where y is what ever suffix would create that nameless temporary object > as a byte with the value of 1. > > Is there a way to do this? Is there a better way to increment a byte? > > Thanks, > Russ > lineNumber += 1 What's the problem with that? -- Rinze van Huizen C-Services Holland b.v > Why not just use The problem is just typing 1 gives you an integer. If lineNumber is a> > lineNumber += 1 > > What's the problem with that? Byte you're asking VB to do a narrowing conversion cast. When option strict is on that line produces this error message: "Option Strict On disallows implicit conversions from 'Integer' to 'Byte'" I need to create 1 as a byte but I'd like to do it with out having to create a variable or an explicit cast. I need strict on to enforce type safety. "Russ" <kosherpi***@hotmail.com> schrieb: I am not able to repro that in VB.NET 2003. Are you using VB 2005?>> Why not just use >> >> lineNumber += 1 >> >> What's the problem with that? > > The problem is just typing 1 gives you an integer. If lineNumber is a > Byte you're asking VB to do a narrowing conversion cast. When option > strict is on that line produces this error message: > > "Option Strict On disallows implicit conversions from 'Integer' to > 'Byte'" > I need to create 1 as a byte but I'd like to do it with out having to You'll have to use 'CByte(x)' because there are no type characters for the > create a variable or an explicit cast. I need strict on to enforce > type safety. 'Byte' type. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
> You'll have to use 'CByte(x)' because there are no type characters for the Which is converting but by C people called casting.> Byte' type. You know that song mostly done by Harry Belefonte, "there is a hole in the bucket" Cor Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht news:Oih0HAkiGHA.1600@TK2MSFTNGP04.phx.gbl... > "Russ" <kosherpi***@hotmail.com> schrieb: >>> Why not just use >>> >>> lineNumber += 1 >>> >>> What's the problem with that? >> >> The problem is just typing 1 gives you an integer. If lineNumber is a >> Byte you're asking VB to do a narrowing conversion cast. When option >> strict is on that line produces this error message: >> >> "Option Strict On disallows implicit conversions from 'Integer' to >> 'Byte'" > > I am not able to repro that in VB.NET 2003. Are you using VB 2005? > >> I need to create 1 as a byte but I'd like to do it with out having to >> create a variable or an explicit cast. I need strict on to enforce >> type safety. > > You'll have to use 'CByte(x)' because there are no type characters for the > 'Byte' type. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> Herfried K. Wagner [MVP] wrote:
>> "Option Strict On disallows implicit conversions from 'Integer' to 'Byte'" Microsoft Development Environment 2003 Version 7.1.3088> > I am not able to repro that in VB.NET 2003. Are you using VB 2005? >From Help About I see: Microsoft .NET Framework 1.1 Version 1.1.4322 Installed Products: Microsoft Visual Basic .NET 69461-005-0669635-18793 -Snip- Microsoft Visual Studio .NET 2003 Hotfix (KB822690) Herfried K. Wagner [MVP] wrote:
> "Russ" <kosherpi***@hotmail.com> schrieb: This is what I was afraid of when I couldn't find a suffix for Byte.> > I need to create 1 as a byte but I'd like to do it with out having to > > create a variable or an explicit cast. I need strict on to enforce > > type safety. > > You'll have to use 'CByte(x)' because there are no type characters for the > 'Byte' type. > Thanks for confirming it. One last question: Which of these do you think is the least horrifying practice? Dim LineNumber as Byte = 0 Dim Incrementer as Byte = 1 LineNumber += Incrementer - or - Dim LineNumber as Byte = 0 LineNumber += Cbyte(1) Short of abolishing all bytes that ever need incrementing these seem to be my only options under option strict. Thanks for all your help, Russ
Show quote
Hide quote
"Russ" <kosherpi***@hotmail.com> schrieb: I believe that 'LineNumber += 1' is the best solution. It will perform the >> > I need to create 1 as a byte but I'd like to do it with out having to >> > create a variable or an explicit cast. I need strict on to enforce >> > type safety. >> >> You'll have to use 'CByte(x)' because there are no type characters for >> the >> 'Byte' type. > > This is what I was afraid of when I couldn't find a suffix for Byte. > Thanks for confirming it. > > One last question: Which of these do you think is the least horrifying > practice? > > Dim LineNumber as Byte = 0 > Dim Incrementer as Byte = 1 > > LineNumber += Incrementer > > - or - > > Dim LineNumber as Byte = 0 > LineNumber += Cbyte(1) > > Short of abolishing all bytes that ever need incrementing these seem to > be my only options under option strict. conversion implicitly and no compile-time warning is raised. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Russ" <kosherpi***@hotmail.com> schrieb: Sorry, you are right, 'LineNumber += 1' will raise a compile-time error, > [...] however for some reason this was not the case for my sample project although 'Option Strict' was turned on. So I'd vote for 'CByte'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried K. Wagner [MVP] wrote:
> "Russ" <kosherpi***@hotmail.com> schrieb: Well now you've got me wondering how your sample project was> > [...] > > Sorry, you are right, 'LineNumber += 1' will raise a compile-time error, > however for some reason this was not the case for my sample project although > 'Option Strict' was turned on. So I'd vote for 'CByte'. > configured. :) Anyway, I really appreciate the help. I'm new to VB and I'm trying to make sure my coding style develops into a good one. "Russ" <kosherpi***@hotmail.com> schrieb: Honestly I don't know. It took a few minutes until the blue squiggly line >> Sorry, you are right, 'LineNumber += 1' will raise a compile-time error, >> however for some reason this was not the case for my sample project >> although >> 'Option Strict' was turned on. So I'd vote for 'CByte'. > > Well now you've got me wondering how your sample project was > configured. :) Anyway, I really appreciate the help. I'm new to VB > and I'm trying to make sure my coding style develops into a good one. became visible. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
bring an already running app to the front
Capturing mouse events (Mouse up and down on the desktop) Loading CrystalReports.rpt, I Am Asked To Enter Login ID And Password DAAB problem most natural behavior on mouse wheel Cancel Constructor (Me = Nothing) Parent child binding question RichTextBox in Vs2005 Vb.Net shows unformatted RTF Rollover button sampel how do I get date and time of compilation |
|||||||||||||||||||||||