problem with assignment
-
The value of w doesnt increase or decrease once it reaches the value 2 .. can someone please tell me why.. Thanks in advance
Public Class Form1 Dim g As Graphics Dim db As Boolean Dim x As Integer = 100 Dim y As Integer = 100 Dim w As Integer = 150 Dim h As Integer = 150 Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Console.WriteLine(e.Delta.ToString) If (e.Delta > 0) Then Console.WriteLine("in zoomin") w = w * (e.Delta / 100) Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString) Console.WriteLine("w" & w) h = h * (e.Delta / 100) End If If (e.Delta < 0) Then Console.WriteLine("zoomout") w = w / ((e.Delta * -1) / 100) h = h / ((e.Delta * -1 / 100)) End If Console.WriteLine("w" & w) Me.Refresh() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Black, x, y, w, h) End Sub End Class
-
The value of w doesnt increase or decrease once it reaches the value 2 .. can someone please tell me why.. Thanks in advance
Public Class Form1 Dim g As Graphics Dim db As Boolean Dim x As Integer = 100 Dim y As Integer = 100 Dim w As Integer = 150 Dim h As Integer = 150 Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Console.WriteLine(e.Delta.ToString) If (e.Delta > 0) Then Console.WriteLine("in zoomin") w = w * (e.Delta / 100) Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString) Console.WriteLine("w" & w) h = h * (e.Delta / 100) End If If (e.Delta < 0) Then Console.WriteLine("zoomout") w = w / ((e.Delta * -1) / 100) h = h / ((e.Delta * -1 / 100)) End If Console.WriteLine("w" & w) Me.Refresh() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Black, x, y, w, h) End Sub End Class
I suspect the answer is that even if VB doesn't round e.Delta/100 to an int, once it rounds the end result to an int, it's going to not be big enough to get past 2 in either direction. Do e.Delta / 100.0 to make it work with a float, and consider what you do when the end result moves the value by less than .5, which means it will round back to what it was. Perhaps you need to store w as a float, and make it an int only when you're using it to draw with.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
The value of w doesnt increase or decrease once it reaches the value 2 .. can someone please tell me why.. Thanks in advance
Public Class Form1 Dim g As Graphics Dim db As Boolean Dim x As Integer = 100 Dim y As Integer = 100 Dim w As Integer = 150 Dim h As Integer = 150 Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Console.WriteLine(e.Delta.ToString) If (e.Delta > 0) Then Console.WriteLine("in zoomin") w = w * (e.Delta / 100) Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString) Console.WriteLine("w" & w) h = h * (e.Delta / 100) End If If (e.Delta < 0) Then Console.WriteLine("zoomout") w = w / ((e.Delta * -1) / 100) h = h / ((e.Delta * -1 / 100)) End If Console.WriteLine("w" & w) Me.Refresh() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Black, x, y, w, h) End Sub End Class
Public Class Form1 Dim g As Graphics Dim db As Boolean Dim x As Integer = 100 Dim y As Integer = 100 Dim w As Integer = 150 Dim h As Integer = 150 Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Console.WriteLine(e.Delta.ToString) If (e.Delta > 0) Then Console.WriteLine("in zoomin") w = IIf((w * (e.Delta / 100)) < 3, 3, (w * (e.Delta / 100))) 'w = w * (e.Delta / 100) Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString) Console.WriteLine("w" & w) h = IIf((h * (e.Delta / 100)) < 3, 3, (h * (e.Delta / 100))) 'h = h * (e.Delta / 100) End If If (e.Delta < 0) Then Console.WriteLine("zoomout") w = w / ((e.Delta * -1) / 100) h = h / ((e.Delta * -1 / 100)) End If Console.WriteLine("w" & w) Me.Refresh() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Black, x, y, w, h) End Sub End Class dinvit83
-
Public Class Form1 Dim g As Graphics Dim db As Boolean Dim x As Integer = 100 Dim y As Integer = 100 Dim w As Integer = 150 Dim h As Integer = 150 Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Console.WriteLine(e.Delta.ToString) If (e.Delta > 0) Then Console.WriteLine("in zoomin") w = IIf((w * (e.Delta / 100)) < 3, 3, (w * (e.Delta / 100))) 'w = w * (e.Delta / 100) Console.WriteLine("inside zoomin e.delta " & e.Delta.ToString) Console.WriteLine("w" & w) h = IIf((h * (e.Delta / 100)) < 3, 3, (h * (e.Delta / 100))) 'h = h * (e.Delta / 100) End If If (e.Delta < 0) Then Console.WriteLine("zoomout") w = w / ((e.Delta * -1) / 100) h = h / ((e.Delta * -1 / 100)) End If Console.WriteLine("w" & w) Me.Refresh() End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Black, x, y, w, h) End Sub End Class dinvit83
Not very efficient, but it works. I prefer to lead people to water, rather than throw water at them.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
Not very efficient, but it works. I prefer to lead people to water, rather than throw water at them.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
Christian Graus wrote:
lead people to water, rather than throw water at them
Remind me never to spontaneously combust around you!!
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010