?
Solved

scale up and down

Posted on 2011-02-27
9
Medium Priority
?
234 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 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