IF Statment Issue
-
Monday, July 02, 2012 1:44 AM
Hi Everyone,
You may have noticed I have a slightly new username due to having a new email address now, so I created a new account.
I am having some trouble with a program I have been creating to make my job at work alittle easier.
Now this program I am creating is to read and write data to a spreadsheet(CSV), this data is in the form of "tickets". My program will record what team members completed certain tickets, this is read from a file.
Sub SynapseChecker For i = 1 To Array.GetItemCount(TicketDetails) If Text.IsSubText(TicketDetails[i], "Synapse") Then TeamChecker() Else FailedTickets[i] = TicketDetails[i] EndIf EndFor EndSub
Each ticket is stored within the TicketDetails array then passed the this subroutine - SynapseChecker, which checks for the keyword within each ticket data and if not its added to the FailedTickets array.
Sub TeamChecker For j = 1 To Array.GetItemCount(TeamMember) If Text.IsSubText(TicketDetails[i], TeamMember[j]) Then 'TypeChecker TextWindow.WriteLine(i) Else If j = Array.GetItemCount(TeamMember) Then TextWindow.WriteLine(i) FailedTickets[Array.GetItemCount(FailedTickets) + 1] = TicketDetails[i] EndIf EndIf EndFor EndSub
The tickets that do not fail are then passed to this TeamChecker subroutine and this is where my problem is occuring. I have a array of 60 team members which it should then check the ticket data for their name. When their name is fount it then runs the TypeChecker subroutine but when the name is not fount it should add to the FailedTickets array.
Now my problem is even though it will find their name it will also act asif it hasn't, hence where I have wrote the lines TextWindow.WriteLine(i) to check what ticket has passed or not it will print the line twice indicating it was the IF and ELSE was called for that ticket.
Please help me fix this problem or point out if anything is obviously causing it.
Also let me know if you have any questions.
Thanks.
- Edited by kirk_kaf Monday, July 02, 2012 1:46 AM
All Replies
-
Monday, July 02, 2012 5:54 PMModerator
I put a simple test and some more debugging output:
You can see that it is not the same If that is outputting the value i twice, they are called for different j.
TicketDetails[1] = "Synapse Fred" TicketDetails[2] = "Synapse Mary" TeamMember[1] = "Fred" TeamMember[2] = "Mary" SynapseChecker() Sub SynapseChecker For i = 1 To Array.GetItemCount(TicketDetails) If Text.IsSubText(TicketDetails[i], "Synapse") Then TextWindow.WriteLine("TicketDetails["+i+"] "+TicketDetails[i]) TeamChecker() Else FailedTickets[i] = TicketDetails[i] EndIf EndFor EndSub Sub TeamChecker For j = 1 To Array.GetItemCount(TeamMember) If Text.IsSubText(TicketDetails[i], TeamMember[j]) Then 'TypeChecker TextWindow.WriteLine("IF i="+i+" j="+j) Else If j = Array.GetItemCount(TeamMember) Then TextWindow.WriteLine("ELSE i="+i+" j="+j) FailedTickets[Array.GetItemCount(FailedTickets) + 1] = TicketDetails[i] EndIf EndIf EndFor EndSub
-
Monday, July 02, 2012 7:26 PM
Litdev,
Thank you for taking the time to look into this problem. I am not quite sure what the issue is still I understand its two different IF statments but the IF statment that is nested with the ELSE should not run unless J is equal to the last team member.
If a team members name is fount within the ticket it would then goto the TypeChecker subrountine (not provided here) but if the first team members name is not fount it will then check the next name until its the last name, if the last name isn't fount it then adds the ticket to the FailedTickets array. (Well this is what it should do)
Thanks.
-
Monday, July 02, 2012 7:38 PMModerator
I'm not quite sure I understand, can you provide a full sample (as simple as possible) that can be run and shows the issue, stating what the output should be for the input given.
Perhaps you can consider writing a flow diagram for yourself of the logic to help clarify what it should do.
-
Monday, July 02, 2012 10:29 PMAnswerer
Hi there kirk_kaf!
The same way as litdev, I can't figure out exactly what you want either.
Nevertheless, I did a remix of your code.
Hope it can help you out somehow. @_@
' Program -> Synapse Work Done Members
' Version -> 1.1
' For -> kirk_kaf
' Thread -> http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/8074a14d-d065-41d5-b3e8-030500e1d180
LF = Text.GetCharacter(10)
TAB = Text.GetCharacter(9)
teamMembers = "0=Unknown;1=Dyke;2=Beth;3=Nash;4=Kate;"
ticketDetails[1] = "Beth expects to complete her schedule in time"
ticketDetails[2] = "Kate has sent her synapse already!"
ticketDetails[3] = "Task for Nash? I swear he'll finish it tomorrow"
ticketDetails[4] = "Me Dyke am trying to have the synapse work done."
ticketDetails[5] = "What is the task's name?"
ticketDetails[6] = "Kate accomplished her 2nd synapse! @_@"
ticketDetails[7] = "Dunno who is that Joe guy, but there's a synapse from him right there!!!"
numMembers = Array.GetItemCount(teamMembers) - 1
numTickets = Array.GetItemCount(ticketDetails)
triggerWord = "synapse"
SynapseChecker()
ShowReport()
'____________________________________________________________________________________________'
Sub SynapseChecker
For i = 1 To numTickets
If Text.IsSubText( Text.ConvertToLowerCase(ticketDetails[i]) triggerWord ) Then
failedTickets[i] = "False" ' Found 'synapse' word within ticketDetails[]
teamChecker()
Else
failedTickets[i] = "True" ' triggerWord not found. Task not completed here!
EndIf
EndFor
EndSub
'____________________________________________________________________________________________'
Sub TeamChecker
For j = 1 To numMembers
If Text.IsSubText( ticketDetails[i] teamMembers[j] ) Then
numAccomplish[ teamMembers[j] ] = numAccomplish[ teamMembers[j] ] + 1
j = numMembers + 1 ' Break free from loop for it's already found a member within ticketDetails[].
EndIf ' Also make j iterator > numMembers to flag its abnormal interruption!
EndFor
If j = numMembers + 1 Then ' If loop finished normally up to its end, it means no known members have accomplished this task!
numAccomplish["Unknown"] = numAccomplish["Unknown"] + 1
EndIf
EndSub
'____________________________________________________________________________________________'
Sub ShowReport
Success = 0
Failed = 0
For i = 1 To numTickets
If failedTickets[i] Then
Failed = Failed + 1
Else
Success = Success + 1
EndIf
EndFor
TextWindow.WriteLine("Tickets Total = " + numTickets)
TextWindow.WriteLine("Accomplished = " + Success)
TextWindow.WriteLine("Failed = " + Failed + LF)
TextWindow.WriteLine("Member List of Accomplishments:" + LF)
For i = 0 To numMembers
TextWindow.WriteLine(teamMembers[i] + TAB + TAB + " -> " + TAB + numAccomplish[ teamMembers[i] ] * 1)
EndFor
TextWindow.WriteLine("")
EndSub
'____________________________________________________________________________________________'
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Tuesday, July 03, 2012 1:53 AM New version 1.1
-
Tuesday, July 03, 2012 10:20 AM
Apologies for not explaining things to help you understand what I am trying to accomplish. I don't really have a huge about of time to examine GoToLoop's code at the moment but from the comments written it appears to do what I could not.
The data that is passed to my program in the TicketDetails array then gets passed to both subroutines I provided - SynapseChecker and TeamChecker. If Synapse is not listed within the data then it will be added to the FailedTickets array, same goes for TeamChecker if gone of the team members names are placed within the data, it's a failed ticket.
My original code I posted appeared to have not worked as expected on the TeamChecker subroutine. If I was to write out all of the FailedTickets afterwards I could see their was tickets that should not of been placed into the array.
I will put some more time into GoToLoop's example later and will let you know if all works as required, then I can see where I went wrong.
Thank you for putting the time and effort into this post.
-
Tuesday, July 03, 2012 1:47 PMAnswerer
Hi again!
In the meantime, got remix example expanded!
Check it out:
' Program -> Synapse Work Done Members
' Version -> 1.35
' For -> kirk_kaf
' Thread -> http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/8074a14d-d065-41d5-b3e8-030500e1d180
LF = Text.GetCharacter(10)
TAB = Text.GetCharacter(9)
teamMembers = "0=Unknown;1=Dyke;2=Beth;3=Nash;4=Kate;"
ticketDetails[1] = "Beth expects to complete her schedule in time"
ticketDetails[2] = "Kate has sent her synapse already!"
ticketDetails[3] = "Task for Nash? I swear he'll finish it tomorrow"
ticketDetails[4] = "Me Dyke am trying to have the synapse work done."
ticketDetails[5] = "What is the task's name?"
ticketDetails[6] = "Kate accomplished her 2nd synapse! @_@"
ticketDetails[7] = "There's a synapse from some Joe guy right there!!!"
numMembers = Array.GetItemCount(teamMembers) - 1
numTickets = Array.GetItemCount(ticketDetails)
triggerWord = "synapse"
failForUnknown = "True" ' Unkown individuals mean auto-fail if flagged "True"
SynapseChecker()
ShowTeamReport()
ShowTotalReport()
ListSuccessTickets()
ListFailTickets()
'______________________________________________________________________________________________'
Sub SynapseChecker
numAccomplish = ""
For i = 1 To numTickets
If Text.IsSubText( Text.ConvertToLowerCase(ticketDetails[i]) triggerWord ) Then
teamChecker() ' Spotted triggerWord within ticketDetails[]. Let's find out who did it :-D
Else
failedTickets[i] = "True" ' triggerWord not found. Flag failing as "True"
EndIf
EndFor
EndSub
'______________________________________________________________________________________________'
Sub TeamChecker
For j = 1 To numMembers
If Text.IsSubText( ticketDetails[i] teamMembers[j] ) Then
numAccomplish[ teamMembers[j] ] = numAccomplish[ teamMembers[j] ] + 1
failedTickets[i] = teamMembers[j] ' Record member's name as responsible for complete task
j = numMembers + 1 ' Break free from loop for it's already found a member within ticketDetails[].
EndIf ' Also make j iterator > numMembers to flag its abnormal loop termination!
EndFor
If j = numMembers + 1 Then ' If loop finished up fully, it means no known members have accomplished this particular task here!
numAccomplish[ teamMembers[0] ] = numAccomplish[ teamMembers[0] ] + 1
failedTickets[i] = teamMembers[0]
EndIf
EndSub
'______________________________________________________________________________________________'
Sub ShowTeamReport
TextWindow.WriteLine("Member List of Accomplishments:" + LF)
For i = 0 To numMembers
TextWindow.WriteLine(teamMembers[i] + TAB + TAB + " -> " + numAccomplish[ teamMembers[i] ] * 1)
EndFor
TextWindow.WriteLine("")
EndSub
'______________________________________________________________________________________________'
Sub ShowTotalReport
Success = 0
Failed = 0
For i = 1 To numTickets
If failedTickets[i] Then ' "True" means no triggerWord found; thus a failed task!
Failed = Failed + 1
ElseIf failForUnknown And failedTickets[i] = teamMembers[0] Then ' Consider a task by an unknown as fail if flag is set
Failed = Failed + 1
Else
Success = Success + 1 ' Anything ≠ "True" means a task was succesfully completed by someone
EndIf
EndFor
TextWindow.WriteLine("Tickets Total" + TAB + " = " + numTickets)
TextWindow.WriteLine("Accomplished" + TAB + " = " + Success)
TextWindow.WriteLine("Failed" + TAB + TAB + " = " + Failed + LF)
EndSub
'______________________________________________________________________________________________'
Sub ListSuccessTickets
TextWindow.WriteLine("Successful Ticket List:" + LF)
For i = 1 To numTickets
If failedTickets[i] <> "True" Then
If failForUnknown <> "True" Or failForUnknown And failedTickets[i] <> teamMembers[0] Then
TextWindow.WriteLine(i + TAB + ticketDetails[i] + " -> " + failedTickets[i])
EndIf
EndIf
EndFor
TextWindow.WriteLine("")
EndSub
'______________________________________________________________________________________________'
Sub ListFailTickets
TextWindow.WriteLine("Failed Ticket List:" + LF)
For i = 1 To numTickets
If failedTickets[i] Or failForUnknown And failedTickets[i] = teamMembers[0] Then
TextWindow.WriteLine(i + TAB + ticketDetails[i] )
EndIf
EndFor
TextWindow.WriteLine("")
EndSub
'______________________________________________________________________________________________'
Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)
- Edited by GoToLoopEditor Wednesday, July 04, 2012 1:49 AM Minor If condition mod v3.5
- Proposed As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, October 11, 2012 5:49 AM
- Marked As Answer by Ed Price - MSFTMicrosoft Employee, Owner Thursday, October 18, 2012 7:32 AM

