Question Beginner needs help about boolean and other stuff

weird_iris

New member
Joined
Oct 24, 2012
Messages
2
Programming Experience
Beginner
Hi guys im new to VB.net
and i am stucking in one of my assignment question.
DisplayOutput()
Method Type Sub Procedure
Parameters One String, one Boolean
Description Displays the content of the String in the Statistics Output Label (SOL)
· Appends the String to the existing content of the SOL if Boolean is
TRUE otherwise the existing content is overwritten.
Return Type None

ShowStats()
Method Type Sub Procedure
Parameters None
Description · Calls CountScores(), then displays the return value using
DisplayOutput().
· Calls SumScores(), then displays the return value using
DisplayOutput().


those are the two sub procedures requirement.
i try to do it but the code just can't be overwritten and also the as many times as i press the button the sum function will keep adding but not reset and count the sum again.

for example i have 1,2 in listbox i press once the sum will be 3 then when i press again it should be 3 as well but it shows 6......

pls help.....

here is my code im struggling with it.......
VB.NET:
[FONT=Verdana]Private Sub DisplayOutput(ByVal Stat As String, ByVal append As Boolean) Dim vCtxt As String[/FONT]
[FONT=Verdana]vSta = Sta_Label.Text & Stat & ControlChars.NewLine[/FONT]
[FONT=Verdana]If append = True Then[/FONT]
[FONT=Verdana]Sta_Label.Text = vSta[/FONT]
[FONT=Verdana]Exit Sub[/FONT]
[FONT=Verdana]Else[/FONT]
[FONT=Verdana]vCtxt = Sta_Label.Text & Stat & ControlChars.NewLine[/FONT]
[FONT=Verdana]Sta_Label.Text = vCtxt[/FONT]
[FONT=Verdana]End If[/FONT]
[FONT=Verdana]Exit Sub[/FONT]
[FONT=Verdana]End Sub[/FONT]
[FONT=Verdana]Private Sub showstats()[/FONT]


[FONT=Verdana]Call CountScores()[/FONT]
[FONT=Verdana]vCountN = vCount[/FONT]
[FONT=Verdana]If vCountN <> vCount Then[/FONT]
[FONT=Verdana]Status = False[/FONT]
[FONT=Verdana]Call DisplayOutput(vCountT, Status)[/FONT]
[FONT=Verdana]Else[/FONT]
[FONT=Verdana]Status = True[/FONT]
[FONT=Verdana]Call DisplayOutput(vCountN, Status)[/FONT]
[FONT=Verdana]End If[/FONT]
[FONT=Verdana]vCountT = "Count Scores: " + Convert.ToString(vCount)[/FONT]
[FONT=Verdana]Call SumScores()[/FONT]
[FONT=Verdana]vCountW = vTotal[/FONT]
[FONT=Verdana]If vCountW <> vTotal Then[/FONT]
[FONT=Verdana]Status = False[/FONT]
[FONT=Verdana]Call DisplayOutput(vCountW, Status)[/FONT]
[FONT=Verdana]Else[/FONT]
[FONT=Verdana]Status = True[/FONT]
[FONT=Verdana]Call DisplayOutput(vCountS, Status)[/FONT]
[FONT=Verdana]End If[/FONT]
[FONT=Verdana]vCountS = "Sum Scores: " + Convert.ToString(vTotal)[/FONT]
[FONT=Verdana]End Sub[/FONT]
i am really confusing right now......:eek:ffended::eek:ffended:
 
Hi,

No wonder your confused? I am sorry, but your code could not be more confusing if you tried. I cannot really help you here but some initial comments are:-

1) You only have 1 variable declaration in your whole code but you are using a multitude of variables. Where are these definitions?

2) You use vCount, vCountN, vCountT, vCountS, vCountW, vSta, vCtxt but there is no way we can work out what these mean. When you declare variables you must use qualifying names which then describes the usage of each variable. This is crucial in reading your own code to work out what each variable is supposed to be doing.

3) You call CountScores and SumScores procedures but you have not shown them so we cannot qualify their accuracy.

4) If you need to get further help then please address the above points and then repost describing your form layout as well as posting your reworked code.

Cheers,

Ian
 
Exactly as IanRyder says - if your description of your assignment is exactly as it was given to you, then you're tutor should be hung out to dry!

One obvious error is the unnecessary 'Exit Sub' before the End Sub in DisplayOutput
 
Hi Ian thanks for your reply. i have tried so many times so i made the code this difficult to look.
here is the code i was worked on.
VB.NET:
Private Sub DisplayOutput(ByVal Stat As String, ByVal append As Boolean) 
label.text &= Stat & ControlChars.NewLine
[LEFT][FONT=Courier New]LblCount.[/FONT][FONT=Courier New]Text[/FONT][FONT=Courier New]=[/FONT][FONT=Courier New]If[/FONT][FONT=Courier New]([/FONT][FONT=Courier New]append, LblCount.[/FONT][FONT=Courier New]Text[/FONT][FONT=Courier New]& stat, stat[/FONT][FONT=Courier New])[/FONT][/LEFT]
End Sub

Sub showstats()
Dim vCountT As String
Dim vCountS As String
Dim Status As Boolean
Call CountScores()
vCountT = "Count Scores: " + Convert.ToString(vCount)
Status = True
Call DisplayOutput(vCountT, Status)
Call SumScores()
vCountS = "Sum Scores: " + Convert.ToString(vTotal)
Status = True
Call DisplayOutput(vCountS, Status)

Private Function CountScores() As Integer
vCount = Score_box.Items.Count
Return vCount
End Function

Private Function SumScores() As Integer
Dim vIndex As Integer
For vIndex = 0 To Score_box.Items.Count - 1 Step 1
vTotal = vTotal + Score_box.Items(vIndex)
Next
Return vTotal
End Function
so my problem is how to let the whole thing working.
if nothing in the label then display the result, otherwise overwritten with the new result.
and how to make sure the sum function wont just add on ever time ,(suppose to be get a sum value every time depends on the value in the listbox)

thanks
 
Last edited:
Hi,

I can see plenty of issues here already with just a casual glance but, not meaning to be rude, I am not going to even try and attempt to address this until you have addressed the points I raised in my first post.

Please re-read my first post, update your code, and I will try and help you.

Cheers,

Ian
 
Back
Top