首先,您必须初始化所有变量和数组。对于你想做的事情,单独的 FOR 循环是不合适的 复制这个源代码并编译它以了解如何工作
如果您不明白某些想法,请随时提问
' Declare it is not indispensable but useful if you want to know how many and which SUB and FUNCTION are inside the program when the code is long.
Declare SUB Salary()
Sub Salary()
' We make a multi dimensional array is more usefull
Dim as String Identity(10,5)
' We initialize the variables by giving a value that we will use as an index
Dim as Integer Teachernum = 1, NameTeacher = 2, YearOfServe = 3, CurrentSalary = 4, FutureSalary = 5
' We initialize a string variable to use as a prompt
Dim As String PromptWord
Dim As integer InsValue = 0 ' Initialize a var to use inside FOR Loop
Dim As Integer TheExit = 0 ' Initialize a TheExit Var to use for the loop
Dim As Integer InsData = 1 ' You need for control the inser data
Dim As String TeacherFound = "" ' You Need this var for print message status during search
PRINT " Congrats! 10 of you have been chosen to receive a raise in your salary :D. Please follow instructions below :)."
Do Until (TheExit = 1) 'make a loop while the variable TheExit is not equal to 1
If InsData = 1 Then 'This start the data insert if = 1
For InsValue = 1 To 10 Step 1
Identity(InsValue, Teachernum) = str(InsValue) ' Put in the array the number of teacher where the Index is same of loop step
Print "Your number is:" & Identity(InsValue, Teachernum) 'We use the & symbol to join strings without spaces
Line Input " Nice to meet you! What's your name? :D "; Identity(InsValue, NameTeacher) 'Put the name of teacher
Line Input " How many years have you serve here :O ?"; Identity(InsValue, YearOfServe) 'punt the year o service
Line Input " What is your current Salary?"; Identity(InsValue, CurrentSalary) 'put current salary
IF Val(Identity(InsValue, CurrentSalary)) > 1 then 'VAL converts a string into an integer value that can be calculated
' With STR and VAL can calculate the value inside String array
' STR Convert a Integer to String
' VAL Conver a string to Integer
' I use this method to not initialize too many different types of variables
Identity(InsValue, FutureSalary) = Str( ((Val(Identity(InsValue, YearOfServe)) * 2) +100) * Val(Identity(InsValue, CurrentSalary)) / 100)
' FutureSalary = ( (YearOfService * 2 ) +100 ) * CurrentSalary / 100 (If is this you want calculate
' Rate(10)= (Yos(10) * 2) +100
' Nsal(10) = Rate(10) * (Sal(10))/100
Print " Your name is: " & Identity(InsValue,NameTeacher)
Print " Your Previous Salary was: " & Identity(InsValue, CurrentSalary)
Print " Your New Salary is: " & Identity(InsValue,FutureSalary)
Print " Thank you for your time :D, Please allow the next user to begin. (*Dear new user, Please press enter to begin*)"
End If
Line Input " Press Enter for continue... "; PromptWord 'Ask for enter for jump to the next
Next InsValue
InsData = 0 ' When loop this dont stat the Insert data
End if
'Finish Loop now the check ask if you want check the data inserted
Line Input "Would you like to see a specific name and current salary of a teacher or yourself ? Yes / No "; PromptWord
TeacherFound = "" 'Reset the var
If UCASE(PromptWord) = "YES" Then ' UCASE UCASE It transforms the string into capital letters so if you write with upper and lower case letters it does not differ
Line Input "Please input the Teacher's Number or Name"; PromptWord
For InsValue = 1 To 10 Step 1
If ( Val(PromptWord) = Val(Identity(InsValue, Teachernum))) Or ( UCASE(PromptWord) = UCASE(Identity(InsValue,NameTeacher)) )Then
Print "Teacher Found num:" & Identity(InsValue, Teachernum)
Print "Teacher Name:" & Identity(InsValue,NameTeacher)
Print "Previous Salary was: " & Identity(InsValue, CurrentSalary)
Print "New Salary is: " & Identity(InsValue,FutureSalary)
TeacherFound = "Found"
Else
TeacherFound = TeacherFound & "" 'Add a empty value each round
End If
Next InsValue
If TeacherFound = "" Then Print "No Teacher Found !"
Else
Print "The Program is Done Press Enter for exit"
Line Input PromptWord
TheExit = 1 ' Make end to the loop Do until
End If
Loop
End Sub
' Call the Sub Salary like a command
Salary()