Solved

scale up and down

Posted on 2011-02-27
9
220 Views
Last Modified: 2012-05-11
I have a global counter and want to refer to it later on to control the counter value I have two buttons on the form one plus one minus and I would like to go up and down from 0 to .5 dependant upon which button i pressed but in increments of .1

the code increments ok but if i traverse down when i get to zero it fails and then the next negative it gets stuck on -.01

not sure why.




Private Sub BtnVNomMinus_Click()

     Select Case VNomCount
     
     Case 0 To 0.4
        VNomCount = VNomCount - 0.1
     Case 0.5
        VNomCount = VNomCount - 0.1
     Case -0.4 To -0.1
       VNomCount = VNomCount - 0.1
     Case -0.5
     
     
     
     
     End Select
      LblVNomCount.Caption = VNomCount
  
  
  
  

End Sub

Private Sub BtnVNomPlus_Click()
    Select Case VNomCount
     Case 0 To 0.4
    VNomCount = VNomCount + 0.1
     Case 0.5
 
     Case -0.4 To 0
    VNomCount = VNomCount + 0.1
     Case -0.5
     VNomCount = VNomCount + 0.1
     
     
     
     End Select
      LblVNomCount.Caption = VNomCount
End Sub

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 4
  • 4
9 Comments
 

Author Comment

by:PeterBaileyUk
ID: 34991375
vnomcount is a double.

debugging shows vnomcount as -.1

yet the statement: Case -0.4 To -0.1

does not get run it drops out of the case
0
 
LVL 22

Expert Comment

by:Thomasian
ID: 34991405

If VNomCount > -0.5 Then
   VNomCount = VNomCount - 0.1
End If

LblVNomCount.Caption = VNomCount  'You can put this inside the If block if always shows the value of VNomCount

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 34991534
It now goes up and down I amended the plus routine to        If VNomCount < 0.5 Then
   VNomCount = VNomCount + 0.1
End If
     
     
      LblVNomCount.Caption = VNomCount

after your code suggestion BUT zero doesnt appear

it goes -.5 -.4 -.3 -.2 -.1 2.7 .1 .2 .3 .4 .5


not sure how to resolve that zero should be zero and mean no variance the increments are variance that will be added to another figure

 
0
 
LVL 22

Expert Comment

by:Thomasian
ID: 34991653
vb sometimes doesn't show accurate results when computing in double. As a workaround you could round the values.

i.e. Change
LblVNomCount.Caption = VNomCount

Open in new window

To
LblVNomCount.Caption = Round(VNomCount, 1)

Open in new window

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 22

Expert Comment

by:Thomasian
ID: 34991672
Btw, the value of VNomCount isn't actually 2.7. It is something like 2.77555E-17 or 2.77555 X 10^17 which is very close to 0. You only see 2.7 on the label probably because the size of label is too small and you only see the 1st 3 characters.
0
 
LVL 6

Expert Comment

by:TinTombStone
ID: 34991693
Is VNomCount a control?  I assume so

How about this

Private Sub BtnVNomMinus_Click()

           Select Case VNomCount

           if vnomcount = 0.5 then exit sub

      VNomCount = VNomCount - 0.1

           LblVNomCount.Caption = VNomCount
 
End Sub

Private Sub BtnVNomPlus_Click()
       
           if vnomcount = 0 then exit sub

      VNomCount = VNomCount + 0.1

           LblVNomCount.Caption = VNomCount
End Sub

0
 

Author Comment

by:PeterBaileyUk
ID: 34991716
VNomCount is a global variable that is controlled by a plus and a minus button so that I can set the variance I want in the sub records

my subform filter will be
strFilter = strFilter & " and " & "((abs([ClientNomDerived] - Forms!cw_client_matching_form.[NOM CC].[value])<=ReturnvNomcount()) Or (isnull([ClientNomDerived])))"

ReturnvNomcount() this returns the value of the global variable so 0 must be a valid value so if my client nom is 1.6 i can filter on my value of 1.6

BUT i need variance that can be adjusted as sometimes a client has a nom of 1.5 but our data holds it as 1.6

the methods are tested in as much that I have done this for bhp and for cc but these were whole integers.

the global variable VNomCount is a double which could be where the issue lay.

but i am not sure hence my visit here.

0
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 34991725
Since you will be using VNomCount on other parts of your program, the you should apply the round on this function instead.

VNomCount = Round(VNomCount - 0.1, 1)
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 34991766
thank you!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now