PDA

View Full Version : مبتدی: بیرون پریدن از برنامه



peehaa
شنبه 18 مرداد 1393, 15:45 عصر
سلام خدمت اساتید بزرگوار
من گشتم تو انجمن بخش اکسل رو ندیدم البته مشکل من اکسل نیست
من یک برنامه با vba نوشتم توی اکسل که برای محاسبه ی حجم و مساحت جانبیه هرم و مخروط و استوانه هست
که باید اولش نام شکل رو از کاربر بپرسه
ولی وقتی که نام رو وارد میکنم فقط روی اولی که هرم هست محاسبه میکنه
و بعد میاد بیرون
این هم کدهای برنامه
ممنون میشم بگید مشکلش کجاست
این پروژه هم3 نمره ی امتحان من رو داره لطفا کمک کنید:)


Sub masahat()
'barnameye mohasebe hajm va masahate janebye heram va makhroot va ostavane
Sheets("masahat").Select


Const pi As Single = 3.142


a = Val(InputBox("shekle shoma chist?heram?ostovane?makhroot?", "name sehkl", heram, ostovane, makhroot))








If a = heram Then


h = Val(InputBox("lotfan ertefae amood bar heram ra vared konid"))
Range("g12").Select
ActiveCell.Value = h


b = Val(InputBox("lotfan toole ghaede ra vared koid"))
Range("g9").Select
ActiveCell.Value = b




c = Val(InputBox("lotfan arze ghaede ra vared konid"))
Range("g10").Select
ActiveCell.Value = c


sh = Val(InputBox("lotfan ertefae mosalas haye janebi ra benevisid"))
Range("g11").Select
ActiveCell.Value = sh




'mohsebe hajm
v = (1 / 3) * (h) * (b * c)


Range("g13").Select
ActiveCell.Value = v


'mohasebe masahate janebi
sj = (((b * sh) + (c * sh)) * 2) + (b * c)


Range("g14").Select
ActiveCell.Value = sj






MsgBox "hajme heram" & v & "masahate janebi" & sj


ElseIf a = ostovane Then
'daryafte shoa
r = Val(InputBox("lotfan shoae ghede ostovane ra vared konid"))
Range("j9").Select
ActiveCell.Value = r


'daryafte ertefa
b = Val(InputBox("lotfan ertefa ra vared konid"))
Range("j10").Select
ActiveCell.Value = b


'hajme ostovane
v = (pi) * (r * r) * (b)
Range("j11").Select
ActiveCell.Value = v




'masahate janebi
sj = 2 * pi * r * b
Range("j12").Select
ActiveCell.Value = sj


'masahate kol
st = (2 * pi * r) * (r + b)
Range("j13").Select
ActiveCell.Value = st




MsgBox "hajme ostovane " & v & "masahate janebi" & sj & "masahate kol" & st




ElseIf a = makhroot Then
'daryafte shoa
r = Val(InputBox("lotfan shoa ra vared konid"))
Range("m9").Select
ActiveCell.Value = r


'daryafte ertefa
h = Val(InputBox("lotfan ertefa e makhroot ra vared konid"))
Range("m10").Select
ActiveCell.Value = h




'mohasebe hajm
v = (1 / 3) * pi * (r ^ 2) * h
Range("m11").Select
ActiveCell.Value = v


'masahte janebi
sj = pi * r * h
Range("m12").Select
ActiveCell.Value = sj


'masahate kol
st = (pi * r) * (r + h)
Range("m13").Select
ActiveCell.Value = st




MsgBox "hajme makhroot" & v & "masahte janebi makhroot" & sj & "masahte kol" & st




End If





End Sub

amirzazadeh
چهارشنبه 22 مرداد 1393, 20:16 عصر
كد ها رو به اين شكل اصلاح كنيد:

Sub masahat()

'barnameye mohasebe hajm va masahate janebye heram va makhroot va ostavane

Sheets("masahat").Select

Const pi As Single = 3.142


a = InputBox("shekle shoma chist?heram?ostovane?makhroot?", "name sehkl", heram, ostovane, makhroot)

If a = "heram" Then

h = Val(InputBox("lotfan ertefae amood bar heram ra vared konid"))

Range("g12").Select

ActiveCell.Value = h

b = Val(InputBox("lotfan toole ghaede ra vared koid"))

Range("g9").Select

ActiveCell.Value = b

c = Val(InputBox("lotfan arze ghaede ra vared konid"))

Range("g10").Select

ActiveCell.Value = c

sh = Val(InputBox("lotfan ertefae mosalas haye janebi ra benevisid"))

Range("g11").Select

ActiveCell.Value = sh

'mohsebe hajm

v = (1 / 3) * (h) * (b * c)

Range("g13").Select

ActiveCell.Value = v

'mohasebe masahate janebi

sj = (((b * sh) + (c * sh)) * 2) + (b * c)
Range("g14").Select

ActiveCell.Value = sj
MsgBox "hajme heram" & v & "masahate janebi" & sj
ElseIf a = "ostovane" Then

'daryafte shoa

r = Val(InputBox("lotfan shoae ghede ostovane ra vared konid"))

Range("j9").Select

ActiveCell.Value = r
'daryafte ertefa

b = Val(InputBox("lotfan ertefa ra vared konid"))

Range("j10").Select

ActiveCell.Value = b
'hajme ostovane

v = (pi) * (r * r) * (b)

Range("j11").Select

ActiveCell.Value = v
'masahate janebi

sj = 2 * pi * r * b

Range("j12").Select

ActiveCell.Value = sj
'masahate kol

st = (2 * pi * r) * (r + b)

Range("j13").Select

ActiveCell.Value = st

MsgBox "hajme ostovane " & v & "masahate janebi" & sj & "masahate kol" & st

ElseIf a = "makhroot" Then

'daryafte shoa

r = Val(InputBox("lotfan shoa ra vared konid"))

Range("m9").Select

ActiveCell.Value = r

'daryafte ertefa

h = Val(InputBox("lotfan ertefa e makhroot ra vared konid"))

Range("m10").Select

ActiveCell.Value = h
'mohasebe hajm

v = (1 / 3) * pi * (r ^ 2) * h

Range("m11").Select

ActiveCell.Value = v
'masahte janebi

sj = pi * r * h

Range("m12").Select

ActiveCell.Value = sj
'masahate kol

st = (pi * r) * (r + h)

Range("m13").Select

ActiveCell.Value = st
MsgBox "hajme makhroot" & v & "masahte janebi makhroot" & sj & "masahte kol" & st
End If
End Sub