|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Delete labels etc...
If this...
Code:
If lngRecordCount3 <> 0 Then
For Index = 0 To lngRecordCount3
Load lblName(Index)
lblName(Index).Left = vPlace + 100
lblName(Index).Top = vTop + 100
llblName(Index).Visible = True
Next
End If
creates labels how to I delete them later? If I create 10 and next time I only want say 8 then I'd not want then last 2. Tried Kill lblName(0) but this did not work :-( |
|
#2
|
||||
|
||||
|
Quote:
Not so sure, but how about setting the instance of the label to be nothing, much like: lblName(Index) = nothing Give it a try! J.
__________________
Fitness & Diet resources Career Descriptions Boat Cruises All code that is posted by me has not been tested, and it should only be interpreted as a guideline to a solution. There is no guarantee that any of my code samples will work as provided, and should be customized to suite the required need. |
|
#3
|
|||
|
|||
|
Quote:
Fraid not, tried Null as well, 0 just makes it show 0 too. Also tried cancel |
|
#4
|
||||
|
||||
|
lol - this is where i come in...VB is my thing!
Code:
Unload lblName(Index) But remember... you cannot unload objedcts that are created at design time, you can only 'delete' objects that you create yourself using code.
__________________
LozWare Website Directory Whooo! Free submissions, no recip needed. I'm a nice guy
|
|
#5
|
|||
|
|||
|
Perfect thank you..
Load lbl1 lbl1.Caption = "test" lbl1 = vPlace + 10000 lbl1Top = vTop + 1000 lbl1.Visible = True Unload lbl1 |
|
#6
|
||||
|
||||
|
No prob - mind giving us a rep point? I only have 2 :-/
|
|
#7
|
|||
|
|||
|
See if you fancy a big more a of a problem on the same lines. When I try to run the code now with the;
Code:
If lngRecordCount3 > 0 Then
For Index = 0 To lngRecordCount3
Load lblName(Index)
lblName(Index).Caption = "1"
lblName(Index).Left = vPlace + 100
lblName(Index).Top = vTop + 100
lblName(Index).Visible = True
Next
End If
it gives me a "Sub or Function" not defined error. Any ideas? The idea behind this was to create a graph on the fly, this part is the labels then I would repeat but for a line (on it's side) Hope you're as sharp and quick as yesterday! Code:
Private Sub cmdStatistics_Click()
Dim db1 As Database
'
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
'
Dim lngRecordCount1 As Long
Dim lngRecordCount2 As Long
Dim lngRecordCount3 As Long
'
'Dim Percent As Curreny
'
Set db1 = DBEngine.OpenDatabase("\\server2\prog\Christmas Lights\Contacts\DBconsumers.mdb")
'
''Select distint by type and then roll through checking if a person has that type, if so add to lngRecordCount x,y,z
strSQL3 = "SELECT DISTINCT type FROM TBconsumers"
strSQL2 = "select Type FROM TBconsumers"
'
Set rs2 = db1.OpenRecordset(strSQL2)
Set rs3 = db1.OpenRecordset(strSQL3)
'
rs3.MoveLast
lngRecordCount3 = rs3.RecordCount
rs3.MoveFirst
'
For Counter = 1 To lngRecordCount3 'count unique types of customer and set up labels for them with the graph
rs3.Fields("type") = vType
If lngRecordCount3 > 0 Then
For Index = 0 To lngRecordCount3
Load lblName(Index)
lblName(Index).Caption = "1"
lblName(Index).Left = vPlace + 100
lblName(Index).Top = vTop + 100
lblName(Index).Visible = True
Next
End If
strSQL2 = "SELECT * FROM TBconsumers WHERE type = '" & vType & "'"
Set rs2 = db1.OpenRecordset(strSQL2)
If rs2.RecordCount > 0 Then
rs2.MoveLast
lngRecordCount2 = rs2.RecordCount
rs2.MoveFirst
Else
lngRecordCount2 = 0
End If
'
For Index = Counter To Counter
lblName(Index) = lngRecordCount2
End If
rs3.MoveNext
Form1.Caption = lngRecordCount1 - Counter
rs2.Close
Next
'
If lngRecordCount3 > 0 Then
For Index = 0 To lngRecordCount3
lblName(Index).Refresh
Next
End If
rs3.Close
db1.Close
'
MsgBox "Done"
End Sub
|
|
#8
|
||||
|
||||
|
At what exact line does the error display on? VB6 will show you (it high-lights it in yellow).
EDIT: I take it that vTop and vPlace are global variables, right? |
|
#9
|
|||
|
|||
|
Found the problem..
You must have the first instance already in existance from what I can tell. e.g. Command7 already existed as Command7(0) Here is the code so far - you will note at the bottom the way to add graphics, not stunning but works. Next stage to push to a html file when I get sometime! Code:
Private Sub cmdStatistics_Click()
Dim db1 As Database
'
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
'
Dim lngRecordCount1 As Long
Dim lngRecordCount2 As Long
Dim lngRecordCount3 As Long
'
Dim Index As Long
'Dim Percent As Curreny
'
vUnload = 0
Set db1 = DBEngine.OpenDatabase("\\server2\prog\Christmas Lights\Contacts\DBconsumers.mdb")
'
''Select distint by type and then roll through checking if a person has that type, if so add to lngRecordCount x,y,z
strSQL3 = "SELECT DISTINCT type FROM TBconsumers"
'strSQL2 = "select Type FROM TBconsumers"
Set rs3 = db1.OpenRecordset(strSQL3)
'
rs3.MoveLast
lngRecordCount3 = rs3.RecordCount
rs3.MoveFirst
'
For Counter = 1 To lngRecordCount3 'count unique types of customer and set up labels for them with the graph
On Error GoTo ErrorHandler340
If vUnload = 0 Then
For Index = 1 To 99 ' cmdlabels
Unload Command7(Index)
Next
Else
End If
vUnload = 1
vType = rs3.Fields("type")
strSQL2 = "SELECT Type FROM TBconsumers WHERE type = '" & vType & "'"
Set rs2 = db1.OpenRecordset(strSQL2)
If rs2.RecordCount > 0 Then
rs2.MoveLast
lngRecordCount2 = rs2.RecordCount
rs2.MoveFirst
Else
lngRecordCount2 = 0
End If
If lngRecordCount3 = lngRecordCount3 Then
If lngRecordCount3 > 0 Then
For Index = Counter To Counter
vTop = vTop + 200
Load Command7(Index)
Command7(Index).Caption = Index
Command7(Index).Caption = rs3.Fields("type")
Command7(Index).Left = vPlace + 575
Command7(Index).Top = vTop
Command7(Index).Width = 2000
Command7(Index).Height = 100
Command7(Index).Visible = True
Next
Else
End If
End If
rs3.MoveNext
Form1.Caption = lngRecordCount1 - Counter
rs2.Close
Next
'
If lngRecordCount3 > 0 Then
For Index = 0 To lngRecordCount3
Command7(Index).Refresh
Next
End If
rs3.Close
db1.Close
'
MsgBox "Done"
ErrorHandler340:
If Err.Number = 340 Then
Resume Next
Else
Refresh
End If
End Sub
'Need to add in percents as well in a line system
'Percent = lngRecordCount1 / lngRecordCount2
'Percent = Percent * 100
'Line1.BorderWidth = Percent
'Line1.BorderColor = 16711680
'Label1.Caption = Format(Percent, "### 0.00")
'Label2.Caption = lngRecordCount1
'Line1.Refresh
|
|
#10
|
|||
|
|||
|
Good reply
first all keepnin mind contrl created design time canotbe
unload creat label at run time then you can unload them |
|
#11
|
|||
|
|||
|
One working model...
Code:
Private Sub cmdStatistics_Click()
'
Dim db1 As Database
'
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim rs3 As Recordset
'
Dim lngRecordCount1 As Long
Dim lngRecordCount2 As Long
Dim lngRecordCount3 As Long
'
Dim Index As Long
'
vTop = vTop + 600
vUnload = 0
Set db1 = DBEngine.OpenDatabase("DBconsumers.mdb")
'
Form1.Caption = "Processing"
'
'Select distint by type and then roll through checking if a person has that type, if so add to lngRecordCount x,y,z
strSQL3 = "SELECT DISTINCT type FROM TBconsumers"
'
Set rs3 = db1.OpenRecordset(strSQL3)
'
rs3.MoveLast
lngRecordCount3 = rs3.RecordCount
rs3.MoveFirst
'
strSQL1 = "SELECT Orderid FROM TBconsumers"
'
Set rs1 = db1.OpenRecordset(strSQL1)
'
rs1.MoveLast
lngRecordCount1 = rs1.RecordCount
rs1.MoveFirst
'
For Counter = 1 To lngRecordCount3 'count unique types of customer and set up labels for them with the graph
'
On Error GoTo ErrorHandler340
''''''''''''''''''''''''''''''''''''
If vUnload = 0 Then
For Index = 1 To 99
Unload Command7(Index)
Unload Line1(Index)
Unload Command8(Index)
Next
Else
End If
vUnload = 1
''''''''''''''''''''''''''''''''''''
strSQL2 = "SELECT Type FROM TBconsumers WHERE type = '" & rs3.Fields("type") & "'"
Set rs2 = db1.OpenRecordset(strSQL2)
If rs2.RecordCount > 0 Then
rs2.MoveLast
lngRecordCount2 = rs2.RecordCount
rs2.MoveFirst
Else
lngRecordCount2 = 0
End If
''''''''''''''''''''''''''''''''''''
If lngRecordCount3 = lngRecordCount3 Then
If lngRecordCount3 > 0 Then
For Index = Counter To Counter ' creates a loop
vTop = vTop + 300
vPlace1 = 4750
Load Command7(Index)
Command7(Index).Caption = Index
Command7(Index).Caption = rs3.Fields("type")
Command7(Index).Left = vPlace + 500
Command7(Index).Top = vTop
Command7(Index).Width = 2000
Command7(Index).Height = 100
Command7(Index).Visible = True
''''''''''''''''''''''''''''''''''''
'Need to add in percents as well in a line system
Percent = lngRecordCount2 / lngRecordCount1
Percent = Percent * 100
'Line1(Index).Refresh
''''''''''''''''''''''''''''''''''''
Load Line1(Index)
'Line1(Index) = Index
Line1(Index).Y1 = vTop + 100
Line1(Index).Y2 = vTop + 100
Line1(Index).X1 = vPlace1
Line1(Index).X2 = vPlace1 + (Percent * 100)
Line1(Index).Visible = True
'
Load Command8(Index)
Command8(Index).Caption = Index
Command8(Index).Left = vPlace + 2650
Command8(Index).Top = vTop
Command8(Index).Width = 2000
Command8(Index).Height = 100
Command8(Index).Visible = True
Command8(Index).Caption = Format(Percent, "### 0.00")
''''''''''''''''''''''''''''''''''''
Next
Else
End If
End If
'
rs3.MoveNext
Form1.Caption = lngRecordCount1 - Counter
rs2.Close
Next
If Form1.BackColor = &HFFC0C0 Then
MsgBox "Statistics redone"
Else
Form1.BackColor = &HFFC0C0
End If
Form1.Height = 1000 + vTop
'reset all the values and refresh
If lngRecordCount3 > 0 Then
For Index = 0 To lngRecordCount3
Command7(Index).Refresh
Next
End If
Form1.Caption = "Statistics V1.0 - Statistics run"
cmdStatistics.BackColor = &HFF8080
Exit Sub
ErrorHandler340:
If Err.Number = 340 Then
Resume Next
Else
Refresh
End If
'
End Sub
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Delete labels etc... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|