Results 1 to 7 of 7

Thread: [RESOLVED] Int keeps rounding to whole number...HELP!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Resolved [RESOLVED] Int keeps rounding to whole number...HELP!

    I have code that for some reason or another itsnt doing what it should be doing.

    Heres the code:
    Code:
       
    Dim scales As Integer = 1
    .
    .
    .
    Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
            formGraphics.Clear(Color.Black)
            Select Case e.Delta
                Case Is < 0
                    scales = scales / 1.5
                Case Is > 0
                    scales = scales * 1.5
            End Select
            Button1.Text = scales
            writer()
    
        End Sub
    As I scroll the wheel, "scales" only moves by whole numbers. Whats causing this issue?



    Full code (I know it's sloppy right now):
    Code:
    Public Class Form1
        Dim dxs As Integer
        Dim dys As Integer
        Dim scales As Integer = 1
    
        Dim obj As String
        Dim x As Single
        Dim y As Single
        Dim xx As Single
        Dim yy As Single
        Dim d As Single
        Dim ang1 As Single
        Dim ang2 As Single
        Dim ang3 As Single
        Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
        Dim formGraphics As System.Drawing.Graphics
        Dim deltax As Integer = 0
        Dim deltay As Integer = 0
        Dim flag As Boolean = False
        Dim objects(1000, 5) As Integer
        Dim objnum As Integer = 1
    
    
    
    
    
        Private Sub reader()
            FileOpen(1, "C:\Documents and Settings\Temp\Desktop\xxx.dxf", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
            Do While Not EOF(1)
                obj = LineInput(1)
                If obj = "EOF" Then Exit Do
                If obj = "ENTITIES" Then Exit Do
            Loop
    
            Do While objnum < 10000
                obj = LineInput(1)
                If obj = "EOF" Then Exit Do
                Select Case obj
    
                    Case "LINE"
                        obj = LineInput(1)
                        objects(objnum, 1) = 1
                        Do
                            obj = LineInput(1)
                            Select Case obj
                                Case " 10"
                                    objects(objnum, 2) = LineInput(1)
                                Case " 20"
                                    objects(objnum, 3) = LineInput(1)
                                Case " 11"
                                    objects(objnum, 4) = LineInput(1)
                                Case " 21"
                                    objects(objnum, 5) = LineInput(1)
                                Case "  0"
                                    Exit Do
                            End Select
                        Loop
                        objnum = objnum + 1
                        ' formGraphics.DrawLine(myPen, (x * scales) + deltax, (1000 - y * scales) + deltay, (xx * scales) + deltax, (1000 - yy * scales) + deltay)
    
                    Case "CIRCLE"
                        obj = LineInput(1)
                        objects(objnum, 1) = 2
                        Do
                            obj = LineInput(1)
                            Select Case obj
                                Case " 10"
                                    objects(objnum, 2) = LineInput(1)
                                Case " 20"
                                    objects(objnum, 3) = LineInput(1)
                                Case " 40"
                                    objects(objnum, 4) = LineInput(1)
                                Case "  0"
                                    Exit Do
    
                            End Select
                        Loop
                        objnum = objnum + 1
                        '                    formGraphics.DrawEllipse(myPen, New Rectangle((x * scales) - (d * scales) + deltax, 1000 - (y * scales) - (d * scales) + deltay, (d * scales * 2), d * scales * 2))
    
    
                    Case "ARCl"
                        obj = LineInput(1)
                        Do
                            obj = LineInput(1)
                            Select Case obj
                                Case " 10"
                                    x = LineInput(1)
                                Case " 20"
                                    y = LineInput(1)
                                Case " 40"
                                    d = LineInput(1)
                                Case " 50"
                                    ang1 = LineInput(1)
                                Case " 51"
                                    ang2 = LineInput(1)
                                Case "  0"
                                    Exit Do
                            End Select
                        Loop
                        If ang1 < ang2 Then ang3 = ang1 - ang2 Else ang3 = (ang1 - ang2) - 180
                        formGraphics.DrawArc(myPen, (x * scales) - ((d * scales)), 1000 - (y * scales) - (d * scales), d * 2 * scales, d * 2 * scales, ang2 + 180, ang3)
                        MsgBox(ang1 & ":" & ang2 & ";" & ang1 & ":" & ang1 + ang3)
                End Select
            Loop
            FileClose(1)
            writer()
        End Sub
    
        Private Sub writer()
            For i As Integer = 1 To objnum
                Select Case objects(i, 1)
                    Case 1
                        formGraphics.DrawLine(myPen, (objects(i, 2) * scales) + deltax, (1000 - objects(i, 3) * scales) + deltay, (objects(i, 4) * scales) + deltax, (1000 - objects(i, 5) * scales) + deltay)
                    Case 2
                        formGraphics.DrawEllipse(myPen, New Rectangle((objects(i, 2) * scales) - (objects(i, 4) * scales) + deltax, 1000 - (objects(i, 3) * scales) - (objects(i, 4) * scales) + deltay, (objects(i, 4) * scales * 2), objects(i, 4) * scales * 2))
                End Select
            Next
        End Sub
    
        Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
            If e.Button = Windows.Forms.MouseButtons.Middle Then
                deltax = deltax + (e.X - dxs)
                deltay = deltay + (e.Y - dys)
                formGraphics.Clear(Color.Black)
                writer()
                dxs = e.X
                dys = e.Y
            End If
        End Sub
    
    
    
    
    
        Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
            formGraphics.Clear(Color.Black)
            Select Case e.Delta
                Case Is < 0
                    scales = scales / 1.5
                Case Is > 0
                    scales = scales * 1.5
            End Select
            Button1.Text = scales
            writer()
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            formGraphics.Clear(Color.Black)
            reader()
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            formGraphics = Me.CreateGraphics()
            formGraphics.Clear(Color.Black)
            writer()
        End Sub
    
        Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    
            flag = False
        End Sub
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            If flag = False Then
                flag = True
                dxs = e.X
                dys = e.Y
            End If
    
    
            'End If
        End Sub
    End Class

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Int keeps rounding to whole number...HELP!

    integers are whole numbers. use decimal

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Int keeps rounding to whole number...HELP!

    You need to ask yourself this question: what is an integer? Once you have the answer what an integer is, you will find the problem.
    Hints: Can the value 12.345 be called an integer?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: Int keeps rounding to whole number...HELP!

    Well that made me bang my head on the keyboard a few times....

    Well what would be the best to define scales? I would like to be able to handle "1234.123"

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: Int keeps rounding to whole number...HELP!

    well I defined it as a single, and that seemed to work... However is this the right thing to do?

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Int keeps rounding to whole number...HELP!

    i'd use decimal

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [RESOLVED] Int keeps rounding to whole number...HELP!

    For what you're doing, Single is OK. If you need a large range or higher precision, use Double or Decimal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width