|
-
Jun 28th, 2009, 05:09 PM
#2
Re: Stupid Questions, I Know... But I'm Stumped
1). Your New method does not get called? It should be... I have no idea why. Can you show us the code?
On the other hand, you can initialize your code in the Form_Load event just fine. The form will only be shown when all the code in the Form_Load event is run, not right before it is run. Your form is not visible yet in the Form_Load event.
2) The better way is using the Anchor and Dock properties of every control. Those allow you to determine how controls behave when the form is resized. Look them up, or play with them to find out what they do.
3) Turn Option Strict On, please. X / 2 is not an Integer, it's a Double. If you turn Option Strict on, VB will error on your Dim Y As... line, telling you that "Option Strict On disallows implicit conversions from 'Double' to 'Integer'. This means that you explicitly have to convert the Double to an Integer, and in doing so, you can tell VB how to round, or truncate, the double (floating point) value.
A few ways to do this:
- Use integer division (\ instead of /)
- Use the CInt function (only if you are certain that the argument you are passing is numeric)
- Use the Integer.TryParse function (recommended, especially if you cannot guarantee that the argument is numeric)
The CInt and integer division will fail if "x" is not numeric (like "92b"). The TryParse method will tell you (by returning False) that it could not convert "x" to an integer, and you can handle that gracefully instead of your application aborting.
 Originally Posted by RayLivingston
Division should truncate, not round!
No, it shouldn't. You are comparing apples to oranges. If I tell you to add 5 oranges and 3 apples, you wouldn't tell me I have 8 oranges, would you?
What you are doing is called implicit conversion. You are basically telling VB to choose whichever conversion method it likes to use, because you don't care about the result. It is only 'kind' of VB to let you do this, but you should expect trouble if you do.
Last edited by NickThissen; Jun 28th, 2009 at 05:16 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|