Solved

scale up and down

Posted on 2011-02-27
9
221 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

895 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

14 Experts available now in Live!

Get 1:1 Help Now