פתרון לתרגילים - IF - ELSE - THEN :
תרגיל - 1
option explicit

dim a,reminder
num = cint(input("Enter Number"))


if num mod 10 = 5 or num mod 10 = 0  then
   msgbox "divided by 5" 

else
   msgbox "Not divided by 5"
end if

תרגיל - 2

option explicit

dim name,salary,button

name = inputbox("Enter Name")

button = msgbox(name & " ,do you agree to enter your salary?",vbyesno)

if button = vbyes then
salary=cint(inputbux(name & ", please enter your salary"))
if salary < 5000 then
msgbox "You Deserve A Raise"
else
msgbox "You Don't Deserve A Raise"
end if
else
msgbox "Go Home"
end if

תרגיל - 3
option explicit

dim name,salary,raise

name = inputbox("Enter Name")

salary = cint(intputbox(name & ", please enter your salary))

raise = cint(inputbox(name & ", please enter a raise percent))

if salary + (salary*raise/100) <= 10000 then
salary = salary + (salary*raise/100)
end if

msgbox "Your new salary is " & salary

תרגיל -4
דרך פתרון ראשונה :
Calculator  
option explicit
dim num1,num2,action


num1=cint(inputbox("Enter First Number"))
num2=cint(inputbox("Enter Second Number"))

operat=inputbox("Select an option calculation" & vbcr & "(+, -, /, * )")

if
action = "+" then
msgbox "The Option was '+' " & vbcr & "The Result Is " & num1+num2
end if

if
action = "-" then
msgbox "The Option was '-' " & vbcr & "The Result Is " & num1-num2
end if

if
action = "*" then
msgbox "The Option was '*' " & vbcr & "The Result Is " & num1*num2
end if

if
action = "/" then
msgbox "The Option was '-' " & vbcr & "The Result Is " & num1/num2
end if


דרך פתרון שניה :
option explicit
dim num1,num2,action

if action = "+" then
   msgbox "The Option was '+' " & vbcr & "The Result Is " & num1+num2
elseif  
action = "-" then
   msgbox "The Option was '-' " & vbcr & "The Result Is " & num1-num2
elseif
action = "*" then
   msgbox "The Option was '*' " & vbcr & "The Result Is " & num1*num2
elseif
action = "/" then
   msgbox "The Option was '-' " & vbcr & "The Result Is " & num1/num2
end if


תרגיל - 5
rem Personal Info
option explicit

dim name,age,button,phone

name=inputbox("Enter Your Name","Personal Information")

button = msgbox("" &name &" Will You Enter Your Age?",vbyesno+vbinformation,"Personal Information")

if button = vbyes then
age=inputbox("Enter Your Age","Personal Information")
end if

if age < 1 or age >120 then
age = 0
end if

phone=inputbox("Type in Your Phone Number","Personal Information")

msgbox "Your Personal Information :" & vbcr & "Your Name - " &name & vbcr & "Your Age - " &age & vbcr & "Your Phone - " &phone,vbinformation,"Personal Information"

,תרגיל - 6

rem USER/PASS
option explicit

dim user,pass
dim vpass,button

user=inputbox("Enter User Name")
pass=inputbox("Enter Your Password")

vpass=inputbox("Enter your Password For Validation")

if pass=vpass then
msgbox "Valid Closing Up",vbinformation,"Validation Check"
else if pass<>vpass then
button=msgbox("Select Cancel To Close Or Try Again",vbretrycancel+vbinformation,"Validation Check")
end if
end if

if button = vbcancel then
msgbox "Closing Up",vbinformation,"Validation Check"
else if button = vbretry then
vpass=inputbox("Enter your Password Again")
end if
end if

if pass=vpass then
msgbox "Valid Closing Up",vbinformation,"Validation Check"
else if pass<>vpass then
msgbox "Closing Up",vbinformation,"Validation Check"
end if
end if


תרגיל - 7

rem USER/PASS
option explicit

dim user,pass
dim vpass,button

user=inputbox("Enter User Name")
pass=inputbox("Enter Your Password")

vpass=inputbox("Enter your Password For Validation")

if pass=vpass then
msgbox "Valid Closing Up",vbinformation,"Validation Check"
else if pass<>vpass then
button=msgbox("Select Cancel To Close Or Try Again",vbretrycancel+vbinformation,"Validation Check")
end if
end if

if button = vbcancel then
msgbox "Closing Up",vbinformation,"Validation Check"
else if button = vbretry then
vpass=inputbox("Enter your Password Again")
end if
end if

if pass=vpass then
msgbox "Valid Closing Up",vbinformation,"Validation Check"
else if pass<>vpass then
msgbox "Closing Up",vbinformation,"Validation Check"
end if
end if




IF-THEN-ELSE

VBS – תרגילים תנאים

1) יש לקלוט מספר ולבדוק על פי ספרת האחדות אם הוא מתחלק ב-5 או לא.
    (אם הסיפרה היא 0 או 5 אז מתחלק)

2) יש לקלוט שם. להציג הודעה עם השם ולשאול האם אתה מוכן להקיש את שכרך?
(למשל: "שלום דויד, האם אתה מוכן להקיש את שכרך?")
אם כן – יש לקלוט שכר. אם השכר נמוך מ- 5000 ₪ יש להדפיס: "מגיע לך העלאה"
אחרת – להדפיס: "אין צורך בהעלאה"

3) יש לקלוט שם ומשכורת ואחוז העלאה.
יש להעלות את המשכורת על פי האחוז בתנאי שלאחר ההעלאה,
השכר אינו עולה על 10,000 ₪. אם כן – יש להשאיר את המשכורת כפי שהיא.
בסיום יש להדפיס הודעה עם השם והמשכורת המעודכנת.

4) כתבו תסריט שמבצע פעולות מחשבון. יש לקלוט ערכים ל-2 משתנים, למשל: a, b
    לאחר מכן יש לקלוט פעולה רצויה (+, -, /, * )
    על פי הפעולה שנבחרה יש לבצע פעולה חשבונית ולהדפיס חלון עם התוצאה המתאימה.
    (אין צורך לבצע בדיקות תקינות לפעולה שהוקשה)

5) יש לקלוט שם משתמש וסיסמא. לאחר מכן יש לקלוט שוב סיסמא לאימות.
    אם הסיסמא לא תקינה, יש להודיע שגיאה ולאפשר למשתמש לסיים או לנסות שנית
    (כפתורים: RETRY  ו- CANCEL)
    אם המשתמש בחר לנסות שנית, יש לקלוט שוב סיסמת אימות. אם תקין – להודיע הודעה מתאימה. אם לא –    יש להודיע שגיאה ולסיים.

6) יש לקלוט שם, להציג הודעה שפונה למשתמש בשמו ושואלת אם הוא מסכים להזין גיל
    אם הוא לוחץ "כן" – יש לבקש גיל ולבדוק תקינות של הגיל (גיל תקין הוא בין 1-120).
    לאחר מכן, ללא קשר להזנת הגיל, יש לבקש להזין מס' טלפון.
    לבסוף יש להציג הודעת סיכום עם הנתונים שהוזנו.
    (אם הגיל לא הוזן – אפשר להציג 0 בתור הגיל או להציג הודעה נפרדת
                                                             במקרה שהוזן הגיל ובמקרה שלא הוזן הגיל)

7) כתבו תסריט לניהול מכירת משקאות.
    בכל חלון שיציג התסריט – יש להדפיס כותרת: "welcome to our Bar!"
    התסריט ישאל את המשתמש לגילו. במידה וגילו קטן מ 18- ,  יש להודיע לו 
    שאינו יכול לקנות משקה אלכוהולי ולשאול אותו אם הוא מעוניין במשקה קל
    (עם אפשרות ללחוץ YES   או NO).
    אם לחץ YES    - יש להציע לו להקיש 1 עבור סודה או 2 עבור לימונדה.
    בהתאם לבחירה שיעשה – יש להודיע הודעה מתאימה.
    במידה והמשתמש מעל גיל 18, תציע המערכת למשתמש לבחור בין בירה לכוס יין
    (בירה = 1, יין = 2), ותדפיס   הודעה מתאימה.
    (אין צורך לבצע בדיקות תקינות לערכים שהוקשו)
  

תיקון לפתרון תרגילים :


תרגיל - 1


option explicit

  dim diameter,radius,pi

  diameter = inputbox("ENTER DIAMETER")

  pi=3.14
  radius=diameter/2


msgbox "area is " & pi*radius*radius & vbcr & "perimeter is " & 2*pi*radius,vbokcancel+vbinformation,"DIAMETER"


_________________________________________________________

תרגיל - 2
option explicit


  dim length,width
  dim area,title
  title = "*** Rectangle Calculator ***"

  msgbox "This Script Will Calculate Your Rectangle " & vbcr & "LENGTH & 

  WIDTH",vbinformation,title

  length=inputbox("Please Enter Rectangle Length", title ,"Enter Length")

  width=inputbox("Please Enter Rectangle Width", title ,"Enter Width")

  msgbox "Rectangle Length Is " & length & vbcr & "Rectangle Width Is " & width & vbcr&"Your Rectangle Area IS " &length*width & vbcr & "Rectangle Scope is " & 
(2*length)+(2*width),vbinformation,title
להלן פתרונות לתרגילים:

 תרגיל 1
option explicit
dim Fname,Lname,age,city
Fname=inputbox("Please enter your First Name","Personal Information")
Lname=inputbox("Please enter your First Name","Personal Information")
age=inputbox ("Please enter your age","Personal Information")
city=inputbox("Please Enter Your City","Personal Information")
msgbox "YOUR NAME IS " &Fname+" "&Lname,,"Personal Information"
msgbox "YOUR AGE IS " &age,,"Personal Information"
msgbox "YOUR CITY IS " &city,,"Personal Information"

תרגיל 2

option explicit
dim scale,area
dim pi,radius
pi=3.14
msgbox "Welcome to Diameter" & vbcr & "This will calculate your Circle :-)",vbokcancel+vbinformation,"DIAMETER"
radius = inputbox("Enter Radius","DIAMETER")
scale = 2*pi*radius
msgbox "The Scale circuit is " &scale ,vbinformation,"DIAMETER"
area = pi*radius*radius
msgbox "The circle area is " &area ,vbinformation,"DIAMETER"

תרגיל 3

option explicit
dim length,width
dim area
msgbox "This Script Will Calculate Your Rectangle " & vbcr & "LENGTH & WIDTH",vbinformation,"*** Rectangle Calculator ***"
length=inputbox("Please Enter Rectangle Length","*** Rectangle Calculator ***","Enter Length")
width=inputbox("Please Enter Rectangle Width","*** Rectangle Calculator ***","Enter Width")
msgbox "Rectangle Length Is " &length & vbcr & "Rectangle Width Is "&width & vbcr & "Your Rectangle Area IS " &length*width ,vbinformation,"*** Rectangle Calculator ***"