Confessions of a terrible programmer
Am trying to transfer selections from List1 to List2. Why won't this work:
Private Sub Form_Load()
With Form1.List1
.AddItem "One"
.AddItem "Two"
.AddItem "Three"
End With
End Sub
Private Sub List2_Click()
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected = True Then
List2.AddItem List1.List
End If
Next
End Sub
[471 byte] By [
wisgro] at [2007-11-11 8:15:54]

# 6 Re: Confessions of a terrible programmer
Phil... here's the module code that I hoped would initiate the carriage return in the text box.
Walt
Option Explicit
'***************************************************************
'ModProcessRequest.Bas March 5, 2006
'***************************************************************
'
'
'Function receives choice from lstAppliance_Click event then
'returns average monthly operating cost for selected appliance
'and displays it in the txtAvgMoCost Text Box.
'
'Initialize newLine variable that will use the
'ASCII value or vbCrLf for carriage return and line feed
Public Function GetInfo(Choice As Long) As String
Dim newLine As String
newLine = Chr(13) + Chr(10) 'or vbCrLf (doesn't work with either)
Select Case Choice
'Ran debug. After 1st selection runs succesfully
'program skips remaining cases and stops at lstAppliance_Click()
Case 0
GetInfo = Format$(2.1, "currency") & newLine
Case 1
GetInfo = Format$(3.25, "currency") & newLine
Case 2
GetInfo = Format$(5.98, "currency") & newLine
End Select
End Function
wisgro at 2007-11-11 17:30:50 >

# 8 Re: Confessions of a terrible programmer
Here's the rest of the code:
Option Explicit
'****************************************************************************
'Walt Isgro, wisgro@me.acadia.net
'Purpose:
'1. A user selects items from a list of appliances then uses a button to
' transfers the items to a second list.
'2. When the appliances are transfered an average monthly cost appears in a
' text box.
'3. Eventually a running total of appliance costs will accumulate in a second
' text box located below the first.
'
'Variable names:
'txtAvgMoCost is the average monthly operating cost of an appliance
'selected by a user.
'lstAppliance is the list of appliance selections
'lstSelectedAppliances displays appliances selected by a user
'
'PROBLEM: Module modProcess Request doesn't execute a carriage return after
' each selection is made.
'Ran debug, step into. After making 1st selection the program runs succesfully
' but program skips the remaining cases and stops at lstAppliance_
' Click()
'****************************************************************************
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdMovetoLeft_Click()
Dim i As Integer
If lstSelectedAppliances.ListIndex = -1 Then Exit Sub
For i = lstSelectedAppliances.ListCount - 1 To 0 Step -1
If lstSelectedAppliances.Selected(i) = True Then
lstAppliance.AddItem lstSelectedAppliances.List(i)
lstSelectedAppliances.RemoveItem i
End If
Next i
End Sub
Private Sub cmdMovetoRight_Click()
Dim i As Integer
If lstAppliance.ListIndex = -1 Then Exit Sub
For i = lstAppliance.ListCount - 1 To 0 Step -1
If lstAppliance.Selected(i) = True Then
lstSelectedAppliances.AddItem lstAppliance.List(i)
lstAppliance.RemoveItem i
End If
Next i
End Sub
Private Sub Form_Load()
With frmMultiSelectListBoxes.lstAppliance
'abbreviated list for test
.AddItem "100 Watt Bulb"
.AddItem "60 Watt Bulb"
.AddItem "Fan"
End With
End Sub
Private Sub lstAppliance_Click()
'txtAvgMoCost.Text = ""
'txtAvgMoCost.SetFocus
'Select Case for list test
Select Case lstAppliance.ListIndex
Case 0
txtAvgMoCost.Text = GetInfo(0)
Case 1
txtAvgMoCost.Text = GetInfo(1)
Case 2
txtAvgMoCost.Text = GetInfo(2)
'Case...
End Select
End Sub
Private Sub lstSelectedAppliances_Click()
'intCounter is usually named i
Dim i As Integer
If lstAppliance.ListIndex = -1 Then Exit Sub
For i = lstAppliance.ListCount - 1 To 0 Step -1
If lstAppliance.Selected(i) = True Then
lstSelectedAppliances.AddItem lstAppliance.List(i)
'lstAppliance.RemoveItem i
End If
Next i
End Sub
Private Sub txtAvgMoCost_Change()
Dim rs
Dim Choice As Long
'Identify item chosen in lstAppliance
Choice = frmMultiSelectListBoxes.lstAppliance.ListIndex
'Call the function GetInfo and get the average monthly cost
'that corresponds to the selected item
rs = GetInfo(Choice)
'Display average cost in txtAvgMoCost text box.
frmMultiSelectListBoxes.txtAvgMoCost.Text = rs
End Sub
Private Sub txtTotalAvg_Change()
End Sub
wisgro at 2007-11-11 17:32:48 >
