|
Hello,
I've been thinking about this one for a long time. The following code always gives me an OverflowException when I run it:
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:
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.
|
|
|
|
|
Nope. That's the simplest and fastest way to do it. Well, it'll be a tiny bit faster if you just used integers to begin with.
|
|
|
|
|
Well, couldn't have asked for it any clearer than that! Thank you.
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.
|
|
|
|
|
I have created an updater, but I want a way to hide the exe being downloaded, is this possible?
Thanks,
Bryan
modified 16-Sep-12 22:49pm.
|
|
|
|
|
Hi Bryan, just to let you know that nobody here is going to write the code and paste it here for you for two reasons:
1. We're here because we want to help people with specific questions about programming, not take on programming tasks on your behalf. You'll need to hire someone for that.
2. That kind of vagueness makes it impossible for anybody reading your question to know what you're talking about, let alone start to help you out. Do you mean hide the downloaded executable file on-disk? There's no way we can know for sure to give a useful answer unless you're more specific. Then and only then can we help you out.
I direct you to the "How to get an answer to your question" message posted by Chris Maunder. It's up at the top of the message board there. Good luck with your project.
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.
|
|
|
|
|
Fixed it, Sorry about that.
|
|
|
|
|
Bryan Muschter wrote: I want a way to hide the exe being downloaded
Why? That sounds rather shady and malicious...
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Im making a program to check emails and I want it to download updates.
|
|
|
|
|
Hi,
I have two forms. In form1 I use the code
frm2.PrintPreviewControl1.InvalidatePreview() But it won't update the control
Why?
I use now, as a work around, a timer
in that timer I use
PrintPreviewControl1.InvalidatePreview()
timer1.enable = false
and in the calling control I use
timer1.enable = false
And that work fine but thats not the correct way I think
Jan
|
|
|
|
|
i want to know what is the code in visual basic 8 that will examine the shape of a number FROM DIGIT TO DIGIT
example
i have the number 1733
1-7 is an anscendig distance i name "U"
7-3 is descending distance i name "D"
3-3 is equal distance i name "Q"
so the shape of the number is "UDQ"
thank you
george
|
|
|
|
|
memas63 wrote: what is the code
So you have not actually tried anything or read the "How to ask a question" message?
Sounds to me like you just need to write a couple of if statements. How is this a problem?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
i dont know how to start i am 63 years old
thank you
|
|
|
|
|
Reading the documentation helps. This[^] will tell you how to use an if statement.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
i read the example but i want to know how i use the if and then if is a number from one digit to the other
make me the start from the first digit to the second and i will try the rest
thank you
|
|
|
|
|
You cannot iterate over a number. You will have to convert the number to a string and then iterate over the string converting each character to a number and then comparing them
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
please show me the startig code and i will understand better
thank you
|
|
|
|
|
Here's some code that might give you an idea, since it takes a string, iterates through character by character, and tests each character. Obviously your test will be different, but it should get you on the right track. Taken from <a href="http://msdn.microsoft.com/en-us/library/system.string.chars.aspx">MSDN</a>[<a href="http://msdn.microsoft.com/en-us/library/system.string.chars.aspx" target="_blank" title="New Window">^</a>].
<pre lang="vb">Console.Write("Type a string : ")
Dim myString As String = Console.ReadLine()
Dim i As Integer
For i = 0 To myString.Length - 1
If Uri.IsHexDigit(myString.Chars(i)) Then
Console.WriteLine("{0} is a hexadecimal digit.", myString.Chars(i))
Else
Console.WriteLine("{0} is not a hexadecimal digit.", myString.Chars(i))
End If
Next
' The example produces output like the following:
' Type a string : 3f5EaZ
' 3 is a hexadecimal digit.
' f is a hexadecimal digit.
' 5 is a hexadecimal digit.
' E is a hexadecimal digit.
' a is a hexadecimal digit.
' Z is not a hexadecimal digit. </pre>
|
|
|
|
|
thank you for your help i ll try to do it and if i make it will let you know
thanks again
george
|
|
|
|
|
I've written an app in VB12, and if the user wants the app run from the Windows' Startup Folder, I'm trying to copy my executable from it's current residence to the Startup folder with
Environment.GetEnvironmentVariable("ALLUSERSPROFILE")
& "\Microsoft\Windows\Start Menu\Programs\Startup\" & My.Settings.ExeName)
where ExeName is a static constant in the My Settings object.
This works to give me the a valid path string to "C:\ProgramData\"{et. al.} - but I get an Access Error (Error 5) when my app tries to do a
FileIO.FileSystem.CopyFile(strCurrentAppName, strDestinationFileName) where strDestinationFileName is a concatenation of
Environment.GetEnvironmentVariable("ALLUSERSPROFILE") & "\Microsoft\Windows\Start Menu\Programs\Startup\" & My.Settings.ExeName
Can anyone give me a method that will work without User Rights Access business? I may try using "APPDATA" instead of "ALLUSERSPROFILE" in the interim.
Or if anyone has a better approach to getting an executable to run at Windows' Startup, I'm all ears...
modified 16-Sep-12 5:06am.
|
|
|
|
|
This is not really an issue with VB, but with the system. Access control exists in order to prevent you from doing what you are trying here, without being given permission from the owner of the system. You should set your program manifest to request administration rights and then, if the user grants it, your application will be able to write into these protected locations.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks Richard,
I knew that access rights was the problem, and the keyword answer for me is "Application Manifest". I wondered why it didn't prompt the user (me in this case) to decide whether or not to allow the program to write to the hard drive.
I should be able to alter the manifest accordingly.
Thanks again.
|
|
|
|
|
No problem; it's strange how the obvious is often the last thing we look at.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Actually, now a funny thing. I altered the app.manifest accordingly, and no matter what edit I had done, still I had "ring-around-the-collar" - Windows wouldn't let me write there because of Access rights.
At 6am, when I finally decided to call it a night and leave the problem to be revisited tomorrow-today (lol), I did a save all in VS12 and hit the magic "x". When VS shut down, it prompted me with a dialog saying that it "did not function correctly" and suggested that it log me in as administrator - and once it re-logged me in, it wrote just fine with the code that I had.
Moral of the story: Go ahead and give up, then Windows will allow your code to work correctly!!!
|
|
|
|
|
I guess you were trying to run the application from within a 'non-administrative' execution of Visual Studio. Had you run the enhanced app from a command prompt or Windows Explorer, then it probably would have done what you required. Yes, it's sometimes a pain, but much better than some cheap virus trashing your system.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
The "All Users" folder is only writable by account with admin priv's. If a normal user runs your app, they will never be able to write the shortcut (you ARE putting a shortcut and not the actual .EXE in there aren't you?!) to that folder.
If an admin rusns the app, it'll work just fine. If the system has UAC turned on, the user will get the UAC prompt to ask you if they want to use their admin priv's to do this. This won't work when launched from inside Visual Studio by the way.
Since "All Users" is considered a system setting, this makes perfect sense. If you want individual users to be able to pick whether they want this app to launch when they log in, you should be putting the shortcut in the users Startup folder, not All Users. Every user has read/write permissions to their own Startup folder.
|
|
|
|