|
-
Jun 2nd, 2000, 10:13 AM
#1
Thread Starter
Junior Member
Is it posiable to do a For.. Next statement for more then 2 labels.. ex: I want to beable to get each label caption.
Ex code: [this is what i was trying to use]
For X = 1 To 8
text1 = text1 + Label & X.Caption
Next
Label & X.Caption <~ this is where i get my problem, I've tried many things, such as, Label[X].Caption
Can this be done?
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 2nd, 2000, 10:23 AM
#2
You just about had it on the last one, but VB uses regular parentheses, not square brackets to reference arrays.
Try the following code (it is assumed that "MyLabel" is a control array):
Code:
For X = 1 To 8
text1 = text1 & MyLabel(X).Caption
Next
P.S.: Caption is the default property of a label, so the ".Caption" can be omitted:
Code:
For X = 1 To 8
text1 = text1 & MyLabel(X)
Next
Let me know how you make out.
"It's cold gin time again ..."
Check out my website here.
-
Jun 2nd, 2000, 10:30 AM
#3
Thread Starter
Junior Member
I get an 'Type mismatch' error on that.. I'm using a good something ike that, but i'm trying to write the capions to an ini file.
my real code:
For X = 1 To 8
Call WriteINI("Mouse", "Option[" & X & "]", Label(X), "C:\windows\desktop\vault.ini")
Next
^--- this gives me the error
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 2nd, 2000, 11:35 AM
#4
Thread Starter
Junior Member
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 2nd, 2000, 01:45 PM
#5
Fanatic Member
For X = 1 To 8
Call WriteINI("Mouse", "Option[" & trim(str(X)) & "]", Label(X), "C:\windows\desktop\vault.ini")
Next
-
Jun 2nd, 2000, 03:45 PM
#6
Thread Starter
Junior Member
Still, it doesnt work.. Label(X) <-- this is the only part that dont work, I'm tring to do a For.. Next statement instead of writing an WriteINI line for each label.
For X = 1 To 8
Call WriteINI("Mouse", "Option[" & X & "]", Label(X), "C:\windows\desktop\vault.ini")
Next
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 2nd, 2000, 04:12 PM
#7
PowerPoster
Declare Variable X
Hi nopd-officer, I think you may forgot to declare the variable x.
Code:
Option Explicit
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
Dim x%
For x = 1 To 8
Call WriteINI("Mouse", "Option[" & x & "]", Label(x), "C:\windows\desktop\vault.ini")
Next
End Sub
Private Sub WriteINI(MyAppName As String, MyKeyName As String, MyValue As String, myFileName As String)
WritePrivateProfileString MyAppName, MyKeyName, MyValue, myFileName
End Sub
-
Jun 3rd, 2000, 02:25 AM
#8
Thread Starter
Junior Member
This still doesn't work, I get an error saying "Compile error: Sub or Function not defined" and it highlights the word Label from Label(x)
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 3rd, 2000, 07:00 AM
#9
If you are using Label(x), that means that you are using an Index property. Check and see if you have all of the Index's from 0 to X. (make sure they exsist)
-
Jun 3rd, 2000, 08:38 AM
#10
Thread Starter
Junior Member
Can Anyone?? For.. Next with Labels
I've tried all of that, still nothing. Can this be done?
not all police eat doughnut's and drink coffee.. some of us like milk instead.
-
Jun 3rd, 2000, 10:13 AM
#11
Junior Member
Perhaps....
I think that Label is a keyword in visual basic and therefore cannot be used. Try naming in lblLabel or lbl only. Perhaps it would work! Be sure that it is an array of either controls or string.
Kazim Zaidi (the cracker)
-
Jun 3rd, 2000, 11:44 AM
#12
PowerPoster
Check...
Does you really have some Label control will a proper index assigned in you Form?
[Edited by Chris on 06-04-2000 at 09:12 AM]
-
Jun 3rd, 2000, 12:07 PM
#13
For Each ... Next
Try this:
Code:
Private Sub Command1_Click()
Dim oCTRL As Control
For Each oCTRL In Me
If TypeOf oCTRL Is Label Then
Text1.SelText = oCTRL.Caption & vbCrLf
End If
Next
End Sub
- Aaron.
-
Jun 3rd, 2000, 01:13 PM
#14
Thread Starter
Junior Member
YAY.. I got this thing working.. What I did was changed all
the names of the labels from [Label1, Label2, ect] to
Label, which also changed each index of each label from 0 to
7 so now the name of each label is [Label(0), Label(1),
ect].. Now in the For..Next section the Label(x) now works..
Thanks everyone who help.. more !thanks! to Chris :P
not all police eat doughnut's and drink coffee.. some of us like milk instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|