Appendix V – Visual Basic Source Code

This appendix contains the code for the Visual Basic 6 subroutines in GRSI and Combine. The full code, including initialisation settings, is in the project files GRSI.frm and Combine.frm.

Here is the code for GRSI, which illustrates the implementation of fuzzy traffic lights with pie charts and stacked bars:

Private Sub Form_Load()
ValueSlider.Value = 0
WeightSlider.Value = 5
 
Chart.ChartType = VtChChartType2dBar
Chart.Width = 2400
Chart.Row = 1
Chart.Data = 0
Chart.Row = 2
Chart.Data = 0
Chart.Row = 3
Chart.Data = 100
Fuzzy.Value = 1
Bar.Value = True
Pie.Value = False
End Sub
Private Sub Fuzzy_Click()
Call ValueSlider_Change
End Sub
Private Sub Pie_Click()
Bar.Value = False
Chart.ChartType = VtChChartType2dPie
End Sub
Private Sub ValueSlider_Change()
Red = 0
Yellow = 0
Green = 0
 
v = 0.1 * ValueSlider.Value
 
If Fuzzy.Value = 1 Then
If v < 0.5 Then
Yellow = 200 * v
Red = 100 - Yellow
Else
Yellow = 200 - 200 * v
Green = 100 - Yellow
End If
Else 'crisp traffic lights
If v < 0.35 Then
Red = 1
ElseIf v < 0.65 Then
Yellow = 1
Else
Green = 1
End If
End If
 
Chart.Row = 1
Chart.Data = Green
Chart.Row = 2
Chart.Data = Yellow
Chart.Row = 3
Chart.Data = Red
End Sub
Private Sub WeightSlider_Change()
Chart.Width = 300 * (3 + WeightSlider.Value)
End Sub

 

Here is the code for Combine, which shows how two fuzzy indicators are integrated by taking the weighted combination of their values. This code also calculates the Score and Discord values.

Private Sub Form_Load()
For i = 0 To 1
ValueSlider(i).Value = 0
WeightSlider(i).Value = 5
 
Chart(i).Width = 2000
Chart(i).Row = 1
Chart(i).Data = 0
Chart(i).Row = 2
Chart(i).Data = 0
Chart(i).Row = 3
Chart(i).Data = 100
Next i
Total.Width = 3000
Total.Row = 1
Total.Data = 0
Total.Row = 2
Total.Data = 0
Total.Row = 3
Total.Data = 100
End Sub
Public Sub ValueSlider_Change(i As Integer)
Dim v(0 To 1) As Single
Weight = 0
For j = 0 To 1
v(j) = 0.1 * ValueSlider(j).Value
Weight = Weight + WeightSlider(j).Value
Next j
If v(i) < 0.5 Then
Yellow = 200 * v(i)
Red = 100 - Yellow
Green = 0
Else
Yellow = 200 - 200 * v(i)
Green = 100 - Yellow
Red = 0
End If
Chart(i).Row = 1
Chart(i).Data = Green
Chart(i).Row = 2
Chart(i).Data = Yellow
Chart(i).Row = 3
Chart(i).Data = Red
Call combine
End Sub
Private Sub combine()
Dim v(0 To 1) As Single
Dim w(0 To 1) As Single
Dim r(0 To 1) As Single
Dim y(0 To 1) As Single
Dim g(0 To 1) As Single
 
score = 0
Weight = 0 ' total of all weights
For j = 0 To 1
v(j) = 0.1 * ValueSlider(j).Value
w(j) = WeightSlider(j).Value
Weight = Weight + w(j)
If v(j) < 0.5 Then
y(j) = 200 * v(j)
r(j) = 100 - y(j)
g(j) = 0
Else
y(j) = 200 - 200 * v(j)
g(j) = 100 - y(j)
r(j) = 0
End If
score = score + v(j) * w(j)
Next j
 
Red = 0
Yellow = 0
Green = 0
 
For j = 0 To 1
Red = Red + w(j) * r(j)
Yellow = Yellow + w(j) * y(j)
Green = Green + w(j) * g(j)
Next j
If Weight < 0.001 Then Weight = 0.001
Total.Row = 1
Total.Data = Green / Weight
Total.Row = 2
Total.Data = Yellow / Weight
Total.Row = 3
Total.Data = Red / Weight
score = score / Weight
discord = 0.0004 * Green * Red / (Weight * Weight)
txtScore.Caption = "Score = " & Format(score, "0%") & ",
Discord = " & Format(discord, "0%")
End Sub
Public Sub WeightSlider_Change(i As Integer)
Chart(i).Width = 200 * (3 + WeightSlider(i).Value)
Call combine
End Sub
 

All material on this site copyright 2002-2005 by William Silvert unless otherwise indicated. This page was last updated on 10 November 2005 .