Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

caculation sum 1

Status
Not open for further replies.

thomasII

Technical User
Jan 30, 2001
4
SG
hi,this is a simple question,i hope u people can help me
ok here go,
below are 9 numbers

2 4 5 6 7 8 5 4 6

can u people give me the solution on how to pick up the smallest number.
i have been using if else but can't work
thank
 
Hi Thomas,
try this logic..
dim n(9)
dim smalln
dim i
n(1)=2
n(2)=4
n(3)=5
n(4)=6
n(5)=1
n(6)=8
n(7)=5
n(8)=6
n(9)=4
smalln=n(1)
for i=2 to ubound(n)
if n(i) < smalln then
smalln=n(i)
end if
next
msgbox cstr(smalln)
logic is
assign first nbr as smallest and loop thru all nbrs and if any nbs is less then smalln then assign that nbr to smalln.

Anil.
 
hi,thank for the solution,i hope it work!
anyway,what if the number if given by the the users itself.
i mean the users key the number in instead of we putting it in.
If possible,please ans as soon as possible.
thank you very much.
 
hi,
u can take input from user by input box like this..

Dim n, temp, i, totaln
totaln = InputBox(&quot;Enter how many nbrs are there &quot;)
ReDim n(totaln - 1)
For i = 0 To totaln - 1
n(i) = CInt(InputBox(&quot;Enter nbr :&quot; + CStr(i + 1)))
Next

dim smalln
smalln=n(1)
for i=2 to ubound(n)
if n(i) < smalln then
smalln=n(i)
end if
next

msgbox cstr(smalln)
anil.
 
To Mr AnilKumar
let say if there is two tables.
one is input table while the other is output table.
The user is to key in the 9 numbers in the input table in a 3 by 3 form.
I had already name the input table which a box is given a name each.
This is the same for the output table.
However,i was unable to call out the answer in the output table.
Also,i have a submit button given to it.This is for the users to press after he/she had key in the number.

Pls reply as soon as possible.
Thank you very much
 
This is my script.
can u tell me where is the error,except that this time the table is 2 by 2.And that the output table consist of only 1 output.
************************************************************

<script language=&quot;VBScript&quot;>

dim n(4)
dim smalln
dim i
dim mean(1)

sub ShowButton_OnClick
Next
For a=1 to 4
If no(a)=&quot;&quot; Then
no(a)=&quot;&quot;
Else
no(a)=CLng(no(a))
End If
Next

n(1)=txtno1.value
n(2)=txtno2.value
n(3)=txtno3.value
n(4)=txtno4.value


smalln=n(1)
for i=2 to 4
if n(i) < smalln then
smalln=n(i)
end if
next

mean1.value=smalln
</script>
<script For=&quot;showbutton&quot;event=&quot;onclick&quot;language=VBScript>
mean1.value=smalln
</script>

************************************************************

The problem is that i can't display the output.
Thank you.Please reply as soon as possible.
or u can e-mail me at king_thomas@lovemail.com
 
Hi ,
I could see only problem will be in this para..
sub ShowButton_OnClick
Next
For a=1 to 4
If no(a)=&quot;&quot; Then
no(a)=&quot;&quot;
Else
no(a)=CLng(no(a))
End If
Next

n(1)=txtno1.value
n(2)=txtno2.value
n(3)=txtno3.value
n(4)=txtno4.value

why u r using 2 arrays no and n , u can validate input like..
sub ShowButton_OnClick
if txtno1.value = &quot;&quot; then
n(0)=0
else
n(0)=clng(txtno1.value)
end if

if txtno2.value = &quot;&quot; then
n(1)=0
else
n(1)=clng(txtno2.value)
end if

if txtno3.value = &quot;&quot; then
n(2)=0
else
n(2)=clng(txtno3.value)
end if

if txtno4.value = &quot;&quot; then
n(3)=0
else
n(3)=clng(txtno4.value)
end if

I think < and > function don't works in case of string.

I hope this will solve ur problem.

Thx,
Anil.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top