|
Dave,
The Divide-by Function("\") caught the exception, and produced a Text Message = "Infinity"
Thus the statement "ex" would be false, No Exception.
That is by design... It's no "trick or trap".
You can test this by doing this, It will now throw the exception to "ex":
Dim n1, n2, n3 as integer
Try
n3 = n1 \ n2
Catch ex As Exception
Label2.Text = "Warning! " & ex.Message
End Try
Hope this helps dave.
Progoad
|
|
|
|
|
So, the key is making n3 an integer. If it's anything else, it won't throw the exception.
It's confusing, but it's really just an example from the book, so no big deal. I should have checked out the book more carefully before purchasing - it's 3 years old.
Anyway, now that I'm into it, I'm seeing that this book is covering basic stuff I already know about VB. (The first time I looked at VB.NET code, I was terrified by all the "Region / Friend WithEvents Button1 As System.Windows.Forms.Button" stuff - I thought I was starting at square one.)
Once the object-oriented stuff from my little bit of Java programming comes back, I'll be more comfortable.
________________________________________________________________________
Dave
Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002)
|
|
|
|
|
Yes,
The label control is a text control, thus if you return the text ("Infinity") into it, why would it throw an exeception (to ex) because it is text?
The author was not following proper basic syntax coding...
and created his own "bug".
By the Way, I realy enjoy VB and VB.Net, and it's Math capability.
Beyond what you see a lot of folks saying... I think it is a very powerfull language.
Have fun learning it.. I am..
progload
|
|
|
|
|
progload wrote:
thus if you return the text ("Infinity") into it
Ah, well I'd assumed it would be the / operation that would throw it.
I see what you're saying now. The / operation catches the error internally and simply returns 'infinity'. Thus, externally, it is not an error at all until I attempt to do something with it.
In fact, the error it's been coded to throw isn't arithmetical at all, it is a type error - I can't assume that the / operation will return a numerical value; it could return a string.
Small potatoes. This is actually baby steps towards developing an app that will access the Windows Media Services 9 SDK to manipulate broadcast media publishing points. And even THAT is an intermediate step to transposing it to ASP.NET so I can do it from a web app.
Can you say 'out of my league'? Why do I do this to myself?
________________________________________________________________________
Dave
Y10K bug! Let's not get caught with our pants down **AGAIN**! (DC 02002)
|
|
|
|
|
Sorry Dave, you seem to have stumbled upon an amazingly illogical and inconsistent piece of VB.NET behaviour, hence the discussion. I thought I did in fact explain how to get the exception to throw though, didn't I ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
1] The book says Catch e As Exception, but Visual Studio defaults to 'ex' instead of 'e'. If I deliberately put in 'e', I get a build error: "Variable 'e' hides a variable in an enclosing block." What is wrong here?
The book that you are using may have a different definition in its parameters for your code block.
For example:
public sub Test(byval sender as object, byval e as system.eventargs)<br />
Dim n1, n2 As Integer<br />
Dim n3 As Single<br />
n1 = CInt(txtIn1.Text)<br />
n2 = CInt(txtIn2.Text)<br />
Try<br />
lblOut.Text = n1 / n2<br />
Catch e As Exception<br />
lblWarn.Text = "Warning!"<br />
End Try<br />
end sub<br />
If you tried to catch 'e as an exception' than the e would override the 'e as system.eventargs' which is in the sub parameter. So you can change either of the two variables but they cannot be the same. Look in your book and see if the parameters for the sub or function use an e variable.
|
|
|
|
|
In addition to the comment above, I would advide just assuming "ex" as a standard way for naming exceptions, because for all practical purposes you should just consider "e" as a system reserved variable because NET always declares event arguments as "e".
As far as the "VB is crap" comments, you'll get use to that. It happens on a regular basis. This is a tired, no longer relevant pet argument that some tired, no longer relevant people seem to be unable to let go of.
The reality is that although there are some very minor differences between C# and VB.NET, once you learn to program against the NET framework, you will discover that there is essentially no practical difference.
They both compile to exactly the same machine level code, and they both have for all practical purposes the same level of functionality.
Just tune it out.
|
|
|
|
|
hellow to all ..
can i combien an MS.office command like Save file , or Open file with a program .
for example if i click Save File from the office , the program will Run ?
and one have anyideas ?
Thxx a lott
|
|
|
|
|
if no one have answer for me at least tell me where i can find the answer ..
thxx a lott ..
|
|
|
|
|
Well, we really are not on this message board to be at your beck and call and so a little patience will go a long way to endearing yourself to the rest of the community. Not all of us 'live and breathe' to answer questions.
Now that I have that off my chest, yes you can run your own program (in almost any language) in place of the MS Word-supplied menus. You will need to override the MS one with your own. Exactly how to do this I am not sure as it has been a looooooong time since I have touched Word. Your best bet is to look at the MS Office Tools and/or MSDN web sites for the methods to achieve this.
In fact this was the first hit on Google... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k2/html/odc_wdoverride.asp[^]
...Steve
|
|
|
|
|
Hello
Is there anyone who can tell me how to use the mtgccombobox in datagridview in vb.net 2005 to replace the combobox that comes with the datagridview
soren lovgren
|
|
|
|
|
Here is my problem :
On a PC there is a software that I do not control that is writing a line text in a file every time it receive data.
My software, in VB .net, should read this file and recover only the last line. I made a routine that read the file every 5 secondes.
It's running under WinDows XP.
The problem is that the soft that is writing into the file do not give me access to the file, even in read only. I use a streamreader .
The solution I currently use consist in making a copy of the original data file, then read the copy. This is ugly !!
Any idea to do it the proper way ?
Thanks for help,
Loïc
|
|
|
|
|
Can't be done. If it's open for writing, you can't read it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am working on this application at the moment that automatically sends and email to a user and prompts them to input data to store in an sql server database. To try and simplify to process of inputting data I was wondering if it is possible to insert the .aspx page into the email so the user dosen't need to click on a link and then input the data. Any help is much appreciated.
|
|
|
|
|
No, it's not. You can send the HTML that is generated when the server interprets the aspx page, but not the page itself.
Really, you're MUCH better off just sending a link. In this age of email scams and spam, email filters will pretty much wreck your page to begin with, or the user might not get it at all.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi
When the user select some files and copies them in using rightclick->Copy, or Ctrl+C how could an application get those files?
To make myself more clear, I want to retreive the files that user have selected and copied.
(I have tried the Clipboard object in vb6 but I couldn't get these information out of it.)
Thanks
|
|
|
|
|
Hi,
I am using VB6 and I want to know how could I shutdown the computer from my program while not run as an administrator.
I used the file "shutdown.exe" in windows XP to shutdown while run as an administrator. how if there are no administrator privillages?
Thanks
|
|
|
|
|
|
Hi an thanks for the answer.
When I used the InitiateSystemShutdown API, (even though I was running under an administrator account, Nothing in fact happened.
I tries to give my computer neame, but that didn't help either.
Could you please explain why?
I am using windows XP 2001 without any service packs.
Thanks
|
|
|
|
|
Could you please explain why?
Could be dozens of things. We can't tell you anything without seeing your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hi all,
Does someone here know how can I execute an external vbscript file from within an ASP.NET page (using VB.NET).
Thanks,
Yaron
|
|
|
|
|
|
Thanks. But that's not what I meant.
I need to be able to execute (run) a vbs file from an ASP.NET page not to include the script in an ASP page or another vbscript.
Anyway thanks for your prompt response.
|
|
|
|
|