Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Calculate Simple Math Formula?


My question is this:
How do I work the following problem in Visual BAsic?
= ((102/(102+308))*((998.99-385-385))+385
= (.24878)*(228.99)+385
= 441.97 to get this exact answer

I must have 5 decimal places in the first part, and I keep trying different types of parentheses in order to get the appropriate order of operations but still no luck.
Do I use "= Round((102/(102+308)),5)"
As you might imagine, there are variables in each of these
places that show number values but I figured it would be more easily understood in this format. Thanks for any help you can provide as I am just getting started in VB.
w3000




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Simple (?) Logical Math Formula In View???
'Afternoon all!

I just recently started working with views in SQL Server 2000 (and boy are they great!). Things were smooth until I realized a needed another formula. To keep things simple, I have 5 fields that I'm pulling in. I need to validate them (if each field is < 3 then count it as 1 else count it as 0), then add the validations together, and finally divide it by 5. So basically the formula/psuedo is like this:

If Field1 < 3 then intFoo1 = 1 else 0
If Field2 < 3 then intFoo2 = 1 else 0
If Field3 < 3 then intFoo3 = 1 else 0
If Field4 < 3 then intFoo4 = 1 else 0
If Field5 < 3 then intFoo5 = 1 else 0

Final = (intFoo1 + intFoo2 + intFoo3 + intFoo4 + intFoo5)/5

No matter what I try, I can't get anything to work for me. I'm leaning towards it not being possible, but how can you declare variables in a view? Does anyone have any other ideas? I could validate on the view end and then formulate on the code end, but because the way a few Crystal Reports are designed, it would be best to validate and formulate within the view itself. I'm open to anything, however.

Thanks for your time!!!

Calculate Formula Sample
From time to time I find it diffecult to punch into a calculator a formula with parenthesys. Especially as complex as this '[4(4)/4]^{8-(2)3}'

So I decided to create a routine to evaulate the formula and I attached the zip project to this thread. Please let me know if you find any bugs.

Calculate And Formula In Crystal Report
I must do a report by crystal report6 about testing result that concerns 4 tables as follows:
1. Product table => ID, Name, …..(other details of product)
Eg. F102 Bead wire02

2. Specification => Table that keep specification of each product
Effect_date : effective date for this product (mm/dd/yyyy)
Product_ID : id that links to product table
Aname: Type of analysis
Min: Minimum value
Target: Target value
Max: Max value
XXXX = Aname in specification
Test value = Value of testing

Eg.
Effect_date-----Product_ID------Aname--------------Min----Target---Max
06/1/2000-------F102-------------Rugosity-------------3.5---------5---------7
06/1/2000-------F102-------------Diameter-------------5----------7---------10
06/1/2000-------F102-------------WL---------------------2----------5---------7
06/1/2000-------F103-------------WL---------------------2----------8---------10
07/1/2000------F102--------------Rugosity--------------3---------5---------7

3. Production record
Ticket_no----Product_ID: --------Production_date …..other production detail
10005---------F102------------------07/25/2000
10006---------F102------------------07/26/2000
10007---------F102------------------07/27/2000

4. Test result
Ticket_NO: Ticket number in production line
Product_ID: id that links to product table
TestDate: Testing date
XXXXX1 : Test value
…….
XXXXXn: Test value
Eg.
Ticket No---------Product_ID ---------TestDate-----Rugosity---------Diameter---------WL
1005---------F102------------------08/1/2000---------5------------------7------------------5
1006---------F102------------------08/1/2000---------6------------------7------------------5.5
1007---------F102------------------08/2/2000---------5------------------7------------------5


1. How I can get specification value of the product. The specification has constraint that the effective date <= test date and it must be up to date specification.
2. How I can calculate min, avg, max value of ticket no 1005, 1006 and 1007

My designed report is….
Product ID:
Product Name: Bead wire02
Production date: 07/25/2000 – 07/27/2000
Number of product = 3

------------------------------------Test result----------------------------Specification
ITEMS--------------Min---------Avg---------Max-------------Min---------Avg---------Max
Rugosity-------------5---------5.33---------6------------------3------------5-------------7
Diameter-----------7----------7------------7------------------ 5------------7------------10
WL-------------------5---------5.16---------5.5----------------2-----------5--------------7
………….


I can code in VB to show on listview control but I can’t do it in Crystal report.. what I can do
I would like to use parameter fields but it has a lot of fields (about 10-17 analysis in specification)

I Need Calculate (build) Formula Macd And Rsi And ....
hi
 
i need calculate (build) formula macd and rsi and ......
 
in sheet excel
 
plz must ruselt same metastock.
 
and return change in attach
 
thanksssssssss  to all
 

 
  Express yourself instantly with MSN Messenger! MSN Messenger Download today it's FREE!

How To Calculate The Output Value From A Formula String???
Hi,

just simple question, but it is trouble me lot.

how can i get value from this string formula.

Dim strFormula As String
Dim douOutput As Double

strFormula="20+30+(100+20+30)*0.1"
douOutput = Function(strFormula)


i tried this way, but not working....
douOutput = val(strFormula)


tks


Best of Luck,
Kartheeee...

The Full Build-in Math Function In VB, And Calculate Angle X From Known Sin(x)
Someone please provide a full list of VB build-in functions. Especially, the function of pi (=3.14159), and how to calculate angle from known sin(x).

For example, if I know sin(x) = 0.5, I can solve x = 30 deg manually. What build-in function in VB can I use to perform such calculations?

Thanks!

Minghua

 

Math Formula Problem In VB
I hope this is in the right spot, and I apologize if it's been posted before, I'm just so incredibly frustrated, lol..

Here's the code I'm typing..

Quote:




Private Sub CommandButton1_Click()
TextBox2.Text = TextBox2.Text & 1
TextBox5.Text = TextBox1.Text
TextBox1.Text = ""
End Sub




What I'm wanting is for it to add on top of itself, not add another one to the field. It's something I'm doing for work, and have gotten frustrated over it. When I click the plus sign, it puts a 1 there.. then I click it again it puts another one there instead of a 2. Any help?

Math Formula And Textboxes
Hello

First, I'm sorry if this is posted under the 'wrong headline'
but I didn't find any suitable headline.

Also, English isn't my native language, so please ignore any grammatical errors.

I have tried for two weeks now to code a math formula which is supposed to calcuate some taxes for import cars.

the principle are as follows:
the user types in the weight of the car in text6
the volume of the engine goes in text5
and the effect goes in text3
also the age of the car in years are taken into consideration.
And there are some % which is subtracted from the answer of text3 + text5 + text6
The age is selected in a combobox or from a label in form2.
the weight are calculated as follows:

The tax are changeable values, and are numbers in this format:
XX.XX or XXX.XX

from 0 to 1150 kilo = tax1
the next 250 kilo = tax2
the next 100 kilo = tax3
over 1500 kilo = tax4

the volume uses this calculation:

from 0 to 1200 ccm = vtax1
the next 600 ccm = vtax2
the next 400 ccm = vtax3
over 2200 ccm = vtax4

finally the effect:

from 0 to 65 kW = etax1
the next 25 kW = etax2
the next 40 kW = etax3
over 130 kW = etax4

example:

a car weighs 800 kilos, the engine are 1000 ccm and the effect are 65 kW.
this car is 1 year old:

then the import price will be tax1 + vtax1 + etax1 - age% (based upon choice in combobox or a label)

if a car weighs 1360 and the engine are 1700 ccm / 80 kW (12 years old)
weight = 1150 + 210 and engine 1200 + 500 65 + 15 kW - age
like this:
1150 * tax1 + 250 * tax2 + 1200 * vtax1 + 500 * vtax2 + 65 * etax1 + 15 * etax2 - % of age
if a car weighs 1490 kilo 2100 ccm volume / 120 kw
weight first:
1150 * tax1
+ 250 * tax2
+ 90 * tax3
volume
1200 *vtax1
+ 600 *vtax2
+ 300*vtax3
effect:
65 *etax1
+25*etax2
+30*etax3
finally all taxes:
text6 = 2200 kilo
text5 = 2500 ccm
text3 = 200 kW
- age in %
the formula will be all taxclasses * all tax and rest of the weight, effect and volume are * tax4 in all.
weight:
1150 * tax1
+250 * tax2
+100 * tax3
+700 * tax4
volume:
1200 * vtax1
+600 * vtax2
+400 * vtax3
+300 * vtax4
kW:
65 * etax1
25 * etax2
40 * etax3
70 * etax4

Since I dont know the input in the text boxes, I will need to check the numbers up against the rules,
and if the car weighs more than 1150 kilo:
then the formula contuines to check and see if it passes the next tax class ( 250 ) if so contuine and see next ( 100 ) if positive then contuine ( + the rest ) or stop.

This also goes for the effect and volume.

Thanks in advance

Calc A Formula? (Math)
would it be possible to calc formulas such like this one:

v^2 = v0^2 + 2a (x-x0)

in vb!?

I would like to give the V, D0, X and X0 and the program would show me the value of "a"?

How To Run Math Formula From A String?
hello,

I have a String which contains the following:

100/20
1/60
20/5

How do I go about converting these into decimal value of the formula if the number on the left side is greater than one?

Parse A Math Formula
Hi,

I am recieving a simple math formula as a string, and need to return the result of it as a double value.

For instance:

Dim StrAmount as String
Dim Amount as double

StrAmount = "2 * Area + 4 * Perimeter"



Now I need a function: ParseFormula


Amount = ParseFormula(StrAmount,Area,Perimeter)

Is there one available, or is there a simpe way to do this ?

Thanks,

Dani

Math Formula Angles Problem?
I need to make a program where are ball moves around a form, and bounces off lines like it would in real life. I have got it so the ball moves according to 2 variables, and xmove, and a ymove and then in a timer its like its like:

Ballx=ballx+ballxmove
Bally=bally+ballymove

easy.

But i have to make it so it bounces off of lines as if the lines on the form were walls. I got collision detection in a function so its like:

if ballhitswall then
...
end if

And I have it so if the wall is vertical then your ballxmove=ballxmove*-1, and for horizontal walls, ballymove=ballymove*-1.


But what would i make the two variables equal if the wall was angled? And these angles could be any angle, not just 45 degrees, and the ball could be aproaching them on any angle?


So I need the code for the ballxmove=... and the ballymove=...




Code:
If BallHitsWall then
If WallIsAngled Then
BallxMove=?
BallyMove=?
End If
End If


Thank you!

Calculate Simple Interest
I have a label and a single textbox and 2 command buttons ie Calculate & exit now i want to calculate simple interest ie Simple Interest=(principal*Time*Rate)/100 can u tell me how can i enter values and show the result only byt clicking 4 times in the one of the command button(ie calculate)
if possible please mail me at uddipto_banerji@indiatimes.com

Simple Math
Hey guys,

i know you can round numbers in vb, but im not sure of a way to round it down.

eg 2.75 would be 2 not 3.

any ideas?

Simple Math?
I'm sure this is going to be another "DOH...BART!!!" moments but here goes:

I have a database with length of cable information stored in feet. I need to trasfer that data to a form where the footages must appear in Kilo-Feet. To accomplish this I simply divide the value from the database by 1000. This works great if the last number in the database is greater than zero. If the last digit is a zero the division by 1000 drops the zero. This is for a state form and there have to be 3 digits to the right of the decimal. I have tried both

Code:
iCableLen=470

text1.text=Int(iCableLen/1000)
'text1.text=0.47

text1.text=Round(ICableLen/1000,3)
'text1.text=0.47

Is there a way I can get the zero to appear without doing some type of validation looking at how many digits appear after the decimal.

Thank you in advance.

Bart

Simple Math
Does anyone know if VB 6 has a floor or ceiling function? I'm assuming it will look like Val() or CInt(). Thanks for your help in advance.

Simple 3D Math
Hi,
Wow, I've not posted on this forum for over a year feels like.

Anyway, I'm developing a dead simple terrain surveying program and part of it involves displaying a square patch of undulating ground.

I have the terrain data in a 2d longs array (longitude, latitude and values are for altitude above sea level in millimetres).

I was wondering if there was a simple algorithm for translating 3d points into 2d ones that I can draw on a picturebox.

The viewpoint can change x,y,z position, pitch up and down and rotate around the Y axiz.

I have currently got as far as calculating the horizontal bearing of a chosen point as measured from the centre of the viewpoint window (instead of North). But my code is a bit convoluted and I'm sure there is a more efficient way of doing it.

Can anyone suggest a nice algorithm that would help me?

Thanks for reading

Adam.

Simple Math.
whenever i try to do anything to an integer variable i.e. some math procedure. MyIntVar + 2 = MyIntVar it tells me: Error: Expression. i am stupid. what do i do?

Simple Math Game
Hey All.. Im new to this and need help with this program. If you can create it for me .. I will be glad

1.The Player must be asked 10 random questions (which is pre stored in the program together with the correct answer) on either addition,subtraction,multiplication or division. The player must be able to input the answer into the program.

2.The program should award 5 points for each correct answer by the player and display a "correct" message

3.The program should award 0 points for an incorrect answer by player and display a "Please try again" message, then the program should display the correct answer for the player.

4.At the end of the game, the program should display the players total marks..IF the total marks is 40 and above the player should display "congratulations" on a pop out box. If its 39 and below it should display "please try again".

5.When the player clicks on a "new game" button the program should refresh the screen and prepare for a new game..

I need help at this.. Anyone willing to help me

Simple Math Problem
Hi guys,

I just need to know how to do this is VB....it's really simple but I don't know how to use absolute value and max. But I think the equation below will work???

1-ABS(B280-B281)/MAX(B280:B281)


basically it translates to:
1 minus the absolute value of (B280 minus B281) divided by the maximum of the two numbers B280 or B281 which ever is larger.

thanks

Simple Adding Math
I need a code that adds +1 for me for example
text1 = 50
i need it to add one to it so it will be 51
or a way for it to add one and make text2 51 and i can just pull the number off of text

Simple Math In Textbox?
I need txtA and txtB to be added together in txtC.

What did I write incorrectly?
Can I not write math this way?
A+B?


Option Explicit
Dim A As String, B As String, C As String

Private Sub cmdcalc_Click()
A = Val(txtA.Value)
B = Val(txtB.Value)
C = A + B

txtC.Value = Format(C, "##.00")

End Sub

Private Sub cmdclear_Click()
A = Empty
B = Empty
C = Empty
txtA.Value = ""
txtB.Value = ""
txtC.Value = ""

End Sub

Private Sub cmdexit_Click()
End
End Sub

Simple Math Error In Vb ?
Private Sub Command1_Click()
Dim price As Single

price = 5.41

Text1.Text = 15 * price


End Sub

Why does the result come out as 81.14999 instead of 81.15 ?

I'm not looking for ways to format the result. The result really should be 81.15. The problem is just those two numbers. Any other number are fine. Just those two values gives the wrong result.

Help - Simple Math Problem
HELP - SIMPLE MATH PROBLEM

Hey people!


Have what should be a simple math problem, but its driving me absolutely buggy!

Something ridiculously obvious is escaping me and I can't for the life of me figure out
what the heck it is.

So, I describe what Im trying to do in this email and have also included what I think are the most
important code snips below, where I think the error is occuring.

So here is the description of the problem.


A series of numbers are provided by the user. The series is a sequence that is variable in
length and variable in size per number. For example

23 1 899 72 11 02

or

1 7 8 19 2

or

233 455 23 24 29 12 14 16 17 91 92 94 98 57 34


so any number can be any size, and there can be any number within the sequence

The numbers are entered by the user into a text box

The user clicks a command button

A routine enumerates the total number of individual numbers in the sequence and
creates an array having the same number of elements that will correspond to the
math we will perform, and that follows the following parameter of;
(Code shown that creates the proper number of array elements)

Where "prefix_number" = the total number of numbers in the sequence, i.e. for the second
example above ( 1 7 8 19 2), prefix_number = 5

'this line determines the total number of array elements required
array_total_elements = (prefix_number + 1) * ((prefix_number + 1) + 1) / 2

'--------------------
'april 19 - 06 - ReDim adding_array(numchars) 'array with the number of elements of the same amount as the number of chars
'this array forms the needed structure of the conic, creating all positions for number placement within the cone

ReDim adding_array(array_total_elements)
'--------------------

So now we have an array with a total number of elements that will accomodate the math we want to perform
on the sequence, and that math operation is this;

Take the given sequence, i.e.

1 7 8 19 2

where each number in the sequence is stored individually in an array element, and subtract it from its neighbor to its immediate
left and starting from the left hand side, take the resultant of that value and place it in the appropriate array element not as yet occupied
and continue the process.

So here we have the following


1 7 8 19 2 is processed as;

where

1 is stored in array element 0
7 is stored in array element 1
8 is stored in array element 2
19 is stored in array element 3
2 is stored in array element 4


2-19 = -17

19-8 = 11

8-7 = 1

7-1 = 6



so now we have ;

1 7 8 19 2
6 1 11 -17

and 6, 1, 11, -17 are stored in array elements

6 is stored in array element 5
1 is stored in array element 6
11 is stored in array element 7
-17 is stored in array element 8

we continue as;


6 1 11 -17


-17-11 = -28

11-1 = 10

1-6 = -5



and -28,10,-5 are stored in array elements

-5 is stored in array element 9
10 is stored in array element 10
-28 is stored in array element 11


And so on, the process continuing until we cant do it any more and we arrive at the last
array element result.

Then, we simply dump all the array values in proper sequence to a text box, perhaps a rich text box
and we place a hard return CHR(13) after each sub sequence so we can view the proper order of
computation.


So the box shows something like;

1 7 8 19 2
6 1 11 -17
-28,10,-5
....and so on.


Seems simple enough to me, but for some reason the whole backwards processing thing has stumped me,
working from left to right, subtractively, especially with properly populating and working with the arrays
that way, sounds silly I know, but I can't get this to work.

My code snippets follow below, can anyone whip this together simply, quickly?

Thanks for any feedback!

Cyndy















'====================================='May 12 - 07
'this line modified to cause backwards subtractive process in line
'LAST CODED
check_what_it_is = Val(adding_array(adding_element))
check_what_it_is2 = Val(adding_array(adding_element - 1))
adding_var = Val(adding_array(adding_element)) - Val(adding_array(adding_element - 1))
'====================================='May 12 - 07
DoEvents


'=======================
' may 12 07
'===================
'value placement
adding_array(adding_element + array_pos_update) = adding_var
adding_element = adding_element - 1
'--------------
'may 29-07

'bug occurs here, adding element gets reduce to zero and it needs to
'go back up to the rung down

Debug.Print "adding_array(6) ;"; adding_array(6)
'here is where it breaks down, at the row switcher
Debug.Print "adding_array(12) ;"; adding_array(12)
'=======================

'======for display to text boxes only, captures data stream for display

string_result = text_trans & " " & string_result
text_trans = CStr(adding_var) & " " & text_trans
'======for display to text boxes only, captures data stream for display

'bug occuring here, may 29-07, its not switching to the next row properly

If row_switch_counter = switch_to_new_row Then

array_pos_update = array_pos_update + times_through_the_loop 'APRIL 18-06, does this var need to be reset to zero
adding_element = times_through_the_loop '- 1 'array_pos_update 'moves array position pointer ahead two, jumping to next line
Debug.Print "adding_element ;"; adding_element
'may 28 - 7 ===============

'may 28 - 7 switch_to_new_row = switch_to_new_row - 1
row_switch_counter = times_through_the_loop
text_trans = text_trans & Chr(13)

times_through_the_loop = 0
End If
End If

Next q 'steps through for loop
'===============================
'===============================
'=== ADDING ARRAY ENDS
'===============================
'==============================
'-----------


ctr_transfer = 0

RichTextBox3.Text = display_first_Line & Chr(13) & text_trans

'-------- send array info to text box

set_carriage_returns = prefix_number + 1
check_for_carriage_returns = 0

feedtextbox_ctr = 0
adding_element = 0
display_result = "" 'var to hold looped array numbers

Do Until feedtextbox_ctr = numchars

DoEvents

display_result = display_result & adding_array(adding_element)
If check_for_carriage_returns = set_carriage_returns Then
display_result = display_result & Chr(13)
set_carriage_returns = set_carriage_returns - 1
check_for_carriage_returns = 0
End If

check_for_carriage_returns = check_for_carriage_returns + 1
feedtextbox_ctr = feedtextbox_ctr + 1
adding_element = adding_element + 1

Loop
'-------- send array info to text box

Text2.Text = display_result
'Text2.Text = text_trans

Simple Math Question
Hi,
I'm useless when I comes to math, but can anyone suggest how I go about finding the highest common factor between two numbers?

Sorry it's such a dull question!

Very Simple Math Code...
This is probably the easyiest thing to do but i cant get it, I want to add "000" and "01" and want it to come out like "001" or i want to add "000" and "31" and get "031" or "091" and "04" and get "095". You cant just use the + because it will remove the zeros. Any help???

Simple? Math Question
What's the formula to make a negative number appear as positive?

i.e. -5 to 5

Help - Simple Math Problem
Hey people!


Have what should be a simple math problem, but its driving me absolutely buggy!

Something ridiculously obvious is escaping me and I can't for the life of me figure out
what the heck it is.

So, I describe what Im trying to do in this email and have also included what I think are the most
important code snips below, where I think the error is occuring.

So here is the description of the problem.


A series of numbers are provided by the user. The series is a sequence that is variable in
length and variable in size per number. For example

23 1 899 72 11 02

or

1 7 8 19 2

or

233 455 23 24 29 12 14 16 17 91 92 94 98 57 34


so any number can be any size, and there can be any number within the sequence

The numbers are entered by the user into a text box

The user clicks a command button

A routine enumerates the total number of individual numbers in the sequence and
creates an array having the same number of elements that will correspond to the
math we will perform, and that follows the following parameter of;
(Code shown that creates the proper number of array elements)

Where "prefix_number" = the total number of numbers in the sequence, i.e. for the second
example above ( 1 7 8 19 2), prefix_number = 5

'this line determines the total number of array elements required
array_total_elements = (prefix_number + 1) * ((prefix_number + 1) + 1) / 2

'--------------------
'april 19 - 06 - ReDim adding_array(numchars) 'array with the number of elements of the same amount as the number of chars
'this array forms the needed structure of the conic, creating all positions for number placement within the cone

ReDim adding_array(array_total_elements)
'--------------------

So now we have an array with a total number of elements that will accomodate the math we want to perform
on the sequence, and that math operation is this;

Take the given sequence, i.e.

1 7 8 19 2

where each number in the sequence is stored individually in an array element, and subtract it from its neighbor to its immediate
left and starting from the left hand side, take the resultant of that value and place it in the appropriate array element not as yet occupied
and continue the process.

So here we have the following


1 7 8 19 2 is processed as;

where

1 is stored in array element 0
7 is stored in array element 1
8 is stored in array element 2
19 is stored in array element 3
2 is stored in array element 4


2-19 = -17

19-8 = 11

8-7 = 1

7-1 = 6



so now we have ;

1 7 8 19 2
6 1 11 -17

and 6, 1, 11, -17 are stored in array elements

6 is stored in array element 5
1 is stored in array element 6
11 is stored in array element 7
-17 is stored in array element 8

we continue as;


6 1 11 -17


-17-11 = -28

11-1 = 10

1-6 = -5



and -28,10,-5 are stored in array elements

-5 is stored in array element 9
10 is stored in array element 10
-28 is stored in array element 11


And so on, the process continuing until we cant do it any more and we arrive at the last
array element result.

Then, we simply dump all the array values in proper sequence to a text box, perhaps a rich text box
and we place a hard return CHR(13) after each sub sequence so we can view the proper order of
computation.


So the box shows something like;

1 7 8 19 2
6 1 11 -17
-28,10,-5
....and so on.


Seems simple enough to me, but for some reason the whole backwards processing thing has stumped me,
working from left to right, subtractively, especially with properly populating and working with the arrays
that way, sounds silly I know, but I can't get this to work.

My code snippets follow below, can anyone whip this together simply, quickly?

Thanks for any feedback!

Cyndy















'====================================='May 12 - 07
'this line modified to cause backwards subtractive process in line
'LAST CODED
check_what_it_is = Val(adding_array(adding_element))
check_what_it_is2 = Val(adding_array(adding_element - 1))
adding_var = Val(adding_array(adding_element)) - Val(adding_array(adding_element - 1))
'====================================='May 12 - 07
DoEvents


'=======================
' may 12 07
'===================
'value placement
adding_array(adding_element + array_pos_update) = adding_var
adding_element = adding_element - 1
'--------------
'may 29-07

'bug occurs here, adding element gets reduce to zero and it needs to
'go back up to the rung down

Debug.Print "adding_array(6) ;"; adding_array(6)
'here is where it breaks down, at the row switcher
Debug.Print "adding_array(12) ;"; adding_array(12)
'=======================

'======for display to text boxes only, captures data stream for display

string_result = text_trans & " " & string_result
text_trans = CStr(adding_var) & " " & text_trans
'======for display to text boxes only, captures data stream for display

'bug occuring here, may 29-07, its not switching to the next row properly

If row_switch_counter = switch_to_new_row Then

array_pos_update = array_pos_update + times_through_the_loop 'APRIL 18-06, does this var need to be reset to zero
adding_element = times_through_the_loop '- 1 'array_pos_update 'moves array position pointer ahead two, jumping to next line
Debug.Print "adding_element ;"; adding_element
'may 28 - 7 ===============

'may 28 - 7 switch_to_new_row = switch_to_new_row - 1
row_switch_counter = times_through_the_loop
text_trans = text_trans & Chr(13)

times_through_the_loop = 0
End If
End If

Next q 'steps through for loop
'===============================
'===============================
'=== ADDING ARRAY ENDS
'===============================
'==============================
'-----------


ctr_transfer = 0

RichTextBox3.Text = display_first_Line & Chr(13) & text_trans

'-------- send array info to text box

set_carriage_returns = prefix_number + 1
check_for_carriage_returns = 0

feedtextbox_ctr = 0
adding_element = 0
display_result = "" 'var to hold looped array numbers

Do Until feedtextbox_ctr = numchars

DoEvents

display_result = display_result & adding_array(adding_element)
If check_for_carriage_returns = set_carriage_returns Then
display_result = display_result & Chr(13)
set_carriage_returns = set_carriage_returns - 1
check_for_carriage_returns = 0
End If

check_for_carriage_returns = check_for_carriage_returns + 1
feedtextbox_ctr = feedtextbox_ctr + 1
adding_element = adding_element + 1

Loop
'-------- send array info to text box

Text2.Text = display_result
'Text2.Text = text_trans

Simple Q: How To Express This Math
I have a value in a variable called TOTALCOST and a user can unput a value into avariable called DISCOUNT.

I wish to take the value in discount off of the Value in TOTALCOST as a percentage

IE

TOTALCOST = TOTALCOST - (DISCOUNT)

But not takeing DISCOUNT as a lereral number but as a percentage so if the user inputed 13 into the Varibale DISCOUNt it would take 13% off the Value in TOTAL COST.

Many thanks in advance

Simple Math, Progressbar...
This is probably something really simple, but my brain's all irished up at the moment.

I'm making a progressbar. How do I figure out how big to draw the progress indicator? Based on the Min,Max,Value, and width of the control.

Simple Math Problem
Hey Everyone. For someone who works with large numbers this shouldn't be that hard.

What I am trying to do take a number. Reduce it to less then 1 Million. And then based on the number of times it took to get it less then 1 Million return the number to it's original state. I need to come back with the exact number, however it is rounding the number off 2... I cant have that happen.


Code:
Private Sub Form_Load()
Dim strNum1 As String
Dim strDivideBy
Dim strCount
Dim strFinal
Dim strShow As String

strNum1 = "1024551063141712"
strDivideBy = 2

Do Until strNum1 < 1000000000
strNum1 = strNum1 / strDivideBy
strCount = strCount + 1
Loop
strFinal = strCount & "." & strNum1

MsgBox strFinal

strCount = 0
Do Until strCount = 20
strNum1 = strNum1 * 2
strCount = strCount + 1
Loop

strShow = strNum1
MsgBox FormatNumber(strShow)

End

End Sub


Thanks,

Help With A Simple Vb Math Problem
it may seem stupid, but ive only been taking VB for about 2 or 3 weeks now so its kind of hard for me.. i need to develop a program that computes the average of three test scores and displays a letter grade. I have everything done and working except the calculation code.. can sum1 help me plz?

Math And Graph (simple One)
HI

Supposing I have a textbox and a picturebox. NOw I want the user to enter a mathematical expresion in terms of a variable X and then draw the graph of that funtion from 1 to 100.

Ex - If the user enters Sin(x) then the program should draw the graph of Sin(x) from x = 1 to x = 100

I can make the graph be drawn on the picturebox but how do I get the mathematical function (Sin(x) in the example) from the user and solve it.

Also what is the fastest way of changing the colours of Points on the picturebox. I am using Picture1.pset. Is there something faster than that

Appi

HELP - SIMPLE MATH PROBLEM
HELP - SIMPLE MATH PROBLEM

Hey people!


Have what should be a simple math problem, but its driving me absolutely buggy!

Something ridiculously obvious is escaping me and I can't for the life of me figure out
what the heck it is.

So, I describe what Im trying to do in this email and have also included what I think are the most
important code snips below, where I think the error is occuring.

So here is the description of the problem.


A series of numbers are provided by the user. The series is a sequence that is variable in
length and variable in size per number. For example

23 1 899 72 11 02

or

1 7 8 19 2

or

233 455 23 24 29 12 14 16 17 91 92 94 98 57 34


so any number can be any size, and there can be any number within the sequence

The numbers are entered by the user into a text box

The user clicks a command button

A routine enumerates the total number of individual numbers in the sequence and
creates an array having the same number of elements that will correspond to the
math we will perform, and that follows the following parameter of;
(Code shown that creates the proper number of array elements)

Where "prefix_number" = the total number of numbers in the sequence, i.e. for the second
example above ( 1 7 8 19 2), prefix_number = 5

'this line determines the total number of array elements required
array_total_elements = (prefix_number + 1) * ((prefix_number + 1) + 1) / 2

'--------------------
'april 19 - 06 - ReDim adding_array(numchars) 'array with the number of elements of the same amount as the number of chars
'this array forms the needed structure of the conic, creating all positions for number placement within the cone

ReDim adding_array(array_total_elements)
'--------------------

So now we have an array with a total number of elements that will accomodate the math we want to perform
on the sequence, and that math operation is this;

Take the given sequence, i.e.

1 7 8 19 2

where each number in the sequence is stored individually in an array element, and subtract it from its neighbor to its immediate
left and starting from the left hand side, take the resultant of that value and place it in the appropriate array element not as yet occupied
and continue the process.

So here we have the following


1 7 8 19 2 is processed as;

where

    1 is stored in array element 0
    7 is stored in array element 1
    8 is stored in array element 2
    19 is stored in array element 3
    2 is stored in array element 4


        2-19 = -17

        19-8 = 11

        8-7 = 1
        
        7-1 = 6



so now we have ;

1 7 8 19 2
6 1 11 -17

and 6, 1, 11, -17 are stored in array elements

    6 is stored in array element 5
    1 is stored in array element 6
    11 is stored in array element 7
    -17 is stored in array element 8

we continue as;


6 1 11 -17


        -17-11 = -28

        11-1 = 10

        1-6 = -5
        


and -28,10,-5 are stored in array elements

    -5 is stored in array element 9
    10 is stored in array element 10
    -28 is stored in array element 11


And so on, the process continuing until we cant do it any more and we arrive at the last
array element result.

Then, we simply dump all the array values in proper sequence to a text box, perhaps a rich text box
and we place a hard return CHR(13) after each sub sequence so we can view the proper order of
computation.


So the box shows something like;

1 7 8 19 2
6 1 11 -17
-28,10,-5
....and so on.


Seems simple enough to me, but for some reason the whole backwards processing thing has stumped me,
working from left to right, subtractively, especially with properly populating and working with the arrays
that way, sounds silly I know, but I can't get this to work.

My code snippets follow below, can anyone whip this together simply, quickly?

Thanks for any feedback!

Cyndy















'====================================='May 12 - 07
'this line modified to cause backwards subtractive process in line
    'LAST CODED
check_what_it_is = Val(adding_array(adding_element))
check_what_it_is2 = Val(adding_array(adding_element - 1))
                        adding_var = Val(adding_array(adding_element)) - Val(adding_array(adding_element - 1))
'====================================='May 12 - 07
DoEvents

                
'=======================
' may 12 07
'===================
'value placement
adding_array(adding_element + array_pos_update) = adding_var
adding_element = adding_element - 1
'--------------
'may 29-07
   
   'bug occurs here, adding element gets reduce to zero and it needs to
   'go back up to the rung down

Debug.Print "adding_array(6) ;"; adding_array(6)
'here is where it breaks down, at the row switcher
Debug.Print "adding_array(12) ;"; adding_array(12)
'=======================
    
'======for display to text boxes only, captures data stream for display

string_result = text_trans & " " & string_result
    text_trans = CStr(adding_var) & " " & text_trans
'======for display to text boxes only, captures data stream for display
                
'bug occuring here, may 29-07, its not switching to the next row properly

                    If row_switch_counter = switch_to_new_row Then
                        
        array_pos_update = array_pos_update + times_through_the_loop 'APRIL 18-06, does this var need to be reset to zero
        adding_element = times_through_the_loop '- 1 'array_pos_update 'moves array position pointer ahead two, jumping to next line
Debug.Print "adding_element ;"; adding_element
'may 28 - 7 ===============

'may 28 - 7 switch_to_new_row = switch_to_new_row - 1
                         row_switch_counter = times_through_the_loop
                    text_trans = text_trans & Chr(13)
                
        times_through_the_loop = 0
                End If
        End If

Next q 'steps through for loop
'===============================
'===============================
'=== ADDING ARRAY ENDS
'===============================
'==============================
'-----------


ctr_transfer = 0

RichTextBox3.Text = display_first_Line & Chr(13) & text_trans

'-------- send array info to text box

set_carriage_returns = prefix_number + 1
check_for_carriage_returns = 0

    feedtextbox_ctr = 0
    adding_element = 0
    display_result = "" 'var to hold looped array numbers
    
Do Until feedtextbox_ctr = numchars

DoEvents

    display_result = display_result & adding_array(adding_element)
        If check_for_carriage_returns = set_carriage_returns Then
            display_result = display_result & Chr(13)
            set_carriage_returns = set_carriage_returns - 1
            check_for_carriage_returns = 0
        End If

check_for_carriage_returns = check_for_carriage_returns + 1
    feedtextbox_ctr = feedtextbox_ctr + 1
    adding_element = adding_element + 1

Loop
'-------- send array info to text box
    
Text2.Text = display_result
'Text2.Text = text_trans
    
    
    
    
    
    

Simple Formula.......
..... that I cant get my head around.

I want the cell I have selected to take the cell which is 8 cells left of the activecell and multiply it by the cell which is 4 cells left of the activecell then minus cell 7 to the left by cell 3 to the left. Put it an easier way in excel i would have typed in if cell L8 was the activecell:

=(D8*H8) - (E8*I8)

I've used the activecell.offset remark but VB does not like it:

ActiveCell.Formula = "=((ActiveCell.Offset(0, -8)*(ActiveCell.Offset(0, -6)) - (ActiveCell.Offset(0, -7)*(ActiveCell.Offset(0, -3)"


I know this maybe be peanuts so sorry for asking such a daft question

As always any help is much appreciated

Thanks

Simple Math Equation Won't Work
I am using a simple addition/subtraction equation in my form, but the addition part won't work properly.

I have a number (100) in a text field (txtNumtoAdd), and another number (0) in a textfield (txtScore). when I click + (cmdAdd) it should add txtNumtoAdd (100) to txtScore (0) and give the result (100) in txtScore.


Code:
Private Sub cmdAdd_Click()
txtScore.Text = txtScore.Text + txtNumtoAdd.Text
End Sub

Private Sub cmdMinus_Click()
txtScore.Text = txtScore.Text - txtNumtoAdd.Text
End Sub

However, when I click +, it puts the answer in, but it puts the NumtoAdd as if I put:


Code:
txtScore.Text = txtScore.Text & txtNumtoAdd.Text
ie/ 100 + 0 = 0100 > 100 + 0100 = 0100100

http://img.photobucket.com/albums/v8...p/Equation.bmp

But when I click - (txtMinus) it subtracts the same equation without a problem.

Can anyone figure this out? It's so stupid it's frustrating me!

Simple Math Calculation *SOLVED*
It's been a long day so please bear with me. I've got 9 text box control arrays Text(0) to Text (8)) and I want to add the numbers I will be entering in them to display in another text box. Below is the code I've got set up but instead of getting the sum of the numbers it simple places them one next to each other.

5 + 5 should display 10 but instead it displays 55

Private Sub Command1_Click()
Dim i As Integer

For i = 0 To 8

tmp = tmp + Text1(i)
Next

txtScoreFr.Text = tmp
End Sub

Thanks,
Lintz

Format Of Simple Math Statement
What am I doing wrong here?


Code:

Dim T as Double

T = ((49.8 / 100) / 182.5)

msgbox T




The answer should be .00272----->

I've tried to Dim as Single, double, long, integer, watermelon.
What am I missing?

Simple Math Prob. How To Colculate?
Sups,
I'm sorry, but i dont know the english word for it, but i'm tryin to write a lil app which will colculate 'functions' like 2x*x + 5x + 3.
which goes like this:
x1,2 = (b*b something (-4)*a*c) /2
I hope u guys knows what i'm talkin about
well, my question is how can i colcuate the 'other' action of b*b?
sorry, bad english. PLZ CHECK attachment for a picture.
tnx!

Overflow Error With Simple Math
VB6 SP6

I have a variable declared as a long. I can assign it a value of 34000 with no problems. However when I try to assign it a sum that equals 34000 I get the overflow error.

For exampleCODEDim MyLng as Long
MyLong = 34000  ' works
MyLong = 32000 + 2000    'error 6, overflow

Simple Formula/formatting
This really is just Excel and not VBA, but here goes:

A lot of people on my team like to use '--- instead of zero in their charts. Then when they go to add them up, they get errors because text and numbers are mixed. I know that one way around this is to use SUMIF instead of SUM as in:

=SUMIF(C3:F3,"<>0")

However, if their zero is a result from summing across sheets (having a formula instead of just a typed i number) then the --- will not show. I was wondering if there is a way to set the cell format to show the number unless it is zero in which case it would show the ---?

Also, if there is a strict Excel forum that would be better for this type of question, let me know and I won't bother everyone with non-VBA questions.

Thanks!

Should Be Simple Variable In Formula
Currently I have a large number of cells that are linked to anoter worksheet, all of the cells have range names. I am trying to take that range name and insert it into a formula and then put the formula into the cell. My thought process was to save the range name as a variable and then insert it into a formula and paste that to the current cell.

Example:

'Range named referenced in cell

=+oth_admin_ne_mtd

I want to take that range name and insert it into a Round function to get the following result and have it inserted into the same cell.

=Round(oth_admin_ne_mtd/1000,0)

Here is my code:

myformula = ActiveCell.FormulaR1C1

ActiveCell.formula = "=Round(myformula/1000,0)"

End Sub

This is the result:

=Round(myformula/1000,0)

I thought this would be simple but it has not gone well, any help would be appreciated.

Thanks,

Kevin

Simple Formula In Crystal
Here is my formula

WhilePrintingRecords;
numberVar x;

if {LOAN.CLOSED} = -1 then
x = x + 1;

"Total loans closed:" & x

The "closed" field in the "loan" table contains 0 or -1, when I refresh my report it returns a 0.00.

On the report it shows about 6 records with a -1.

Anyone know?

Simple Math Equation Wont Work!
I am tryign to get the % of these totals and it wont work, it wont * the number by 100.
It gives me the percentage as a whole number 7.4521574 etc, but now i want to turn it into a percentage .74521574 etc.


VB Code:
Option Explicit Dim num1 As DoubleDim num2 As DoubleDim answer1 As Double ' This calculates the tax credit on partsPrivate Sub Command1_Click()Text3.Text = Text1.Text / Text2.Text * 100 ' this is where it wont do the final part of the calcuationEnd Sub

Overflow Error In Simple Low-value Math. Please Advise.
The software breaks on the following line, reporting error code '6' (overflow).
None of the values in the line ever reach above the capabilities of an integer. (all <5000)
I've attempted casting to double and long.
After the code breaks, if you try running the line again (immediately) it works perfectly.
I've tried breaking up the math into multiple lines using intermediate variables.
The worst part appears to be the inconsistency with which it breaks.
The code also breaks on about 5 other lines that are similar to the one below, yet doesn't break always
the line is hit multiple times but breaks only sometimes...

'CurrentX is a single

Global Const INCHES = 1440

vsp.CurrentX = 6.2 * INCHES + (0.6 * INCHES - vsp.TextWidth("3000")) / 2


Anyone have a good solution? Thanks!

Easy Question..... Simple Date/Time Math In VB.
I know there is a simple answer to this, and i can do it in DCL on a vax easily.... But how would i subtract 7 days from the current system date?

I need my application to 'clean up' old records... We have decided on 7 days being the rollover point, after which records are useless.

Right now, i am doing a lot of string parsing, and such...

Whats the 'simple/quick/easy' way?

Simple Formula In Excel, Visual Basic
Hello,
please help me. I am an amateur regarding VB, but good at excel. I am trying to get this excel formula in VB.
=AVERAGE($AE$43:AE43;AG43:$AG$54)

The problem is that i want to lock the formula, regarding which active cell I choose. It should look something like this, but it does not work!

rad = ActiveCell.row
kolumn = ActiveCell.Column

kstart = kolumn - 3
rslut = rad + 11

ActiveCell.FormulaR1C1 = "=AVERAGE(RC"kstart":RC[-3],RC[-1]:R"rslut"C[-1])"

End Sub

I would be much obliged if someone had an idea.

Thanks
Thomas


Edit by Moderator:
Please post Excel questions, in the Excel forum.

Thank you.
Edit by Moderator: and please do not post duplicate questions, it confuses everyone and generates more work for the Moderators. Thanks

Simple Copy Sheet With No Formula Macro
Trying to copy a worksheet to another workbook (got that far)

However, I only want the values and format of the original worksheet to be copied accross. No formulas.

Is this doable - I have searched for the last 2 hours on it and can not find any reference.

Simple Math Using The Double-precision Floating-point Data Type
I'm just learning how to program using VB 6.0. I've built a calculator. Whenever numbers are entered (using either the keyboard or on-sceen buttons I've created), they appear in a label which serves as the display screen for the calculator. I'd like it to be capabale of dealing with large numbers, so I've declared all of my variables as double-precision floating-point data. The program is near finished and most mathematical functions seem to work quite well (adding, subtracting, dividing, multiplying, exponents, square roots, etc.) But for some strange reason, when I enter "650.2 - 650" (or 650.0), and hit the "=" key, I get 0.200000000000045. It not only appears in my display window, but even when I put a breakpoint next to the line of code that performs the operation and hover over each variable, the function looks like this: "0.200000000000045 = 650.2 - 650". So it doesn't seem to be an error with the manner in which I'm displaying the information, nor the way in which I'm transfering it to the display screen. It seems that the mathematical computation is actually a tiny bit inaccurate. Is that simply a negative characteristic of using double data types or is there something else that explains this occurrence? Should I be using another data type? If you need to, I can certainly include the code, but like I said, I think this has something to do with the way it's storing the variables, not my code. Thanks in advance for your help...

- Matt -

Copyright © 2005-08 www.BigResource.com, All rights reserved