Solved

scale up and down

Posted on 2011-02-27
9
226 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 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