Solved

scale up and down

Posted on 2011-02-27
9
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

734 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