|
-
Dec 2nd, 2006, 12:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] command button click ?
Hi Everyone , have a nice day
VB Code:
Private Sub Command1_Click()
Dim txt As String
Dim strline() As String
Dim word As String
Dim mean As String
Dim strvalues() As String
FF = FreeFile
Open App.Path & "\words.txt" For Input As FF
txt = Input(LOF(FF), FF) 'Read the whole file
Close FF
strline = Split(txt, vbNewLine)
For z = 0 To 3203
strvalues = Split((strline(z)), "|")
word = strvalues(0)
mean = strvalues(1)
Label1.Caption = word
Label2.Caption = mean
Next z
End Sub
Private Sub Command4_Click()
Unload Form1
End Sub
The code given above is what i have done till now . words.txt is basically a file having vocabulary in which one word is on each line and its meaning is separated by "|".
now what i want to do is that i have couple of more cummand buttons on my form like "next word" , "show meaning" , which should have capability of moving to next word without meanings display ... or show meanings .. and then proceed to next word .. but i donno how should i put that feasibility here ..
like i had in my mind if i could give something like .. within z loop
if commandbutton2_click = true
then label1.caption=word
but this doesnt work ..
i hope i making myself clear enuff
Regards and waiting for responce
-
Dec 2nd, 2006, 01:20 AM
#2
Re: command button click ?
Try this....
VB Code:
Private Sub CommandButton2_Click()
Lable1.Caption = "Word"
End Sub
Also, if you double click the command button, it will have that format already written.
My usual boring signature: Something
-
Dec 2nd, 2006, 01:23 AM
#3
Re: command button click ?
Load the Array, and display the first elements data.
Re-do the 'For (z) Next' as a function of the new "Next" CommandButton.
Using the "Next" CommandButton, have it index the next element of the Array. Each press will increment the index value.
-
Dec 2nd, 2006, 06:38 AM
#4
Re: command button click ?
as bruce said, but best if you declare (Dim) your array at form level (in the general section at the top) so that it keeps it's value for the whole time the form is open, then you only have to load it once when you open the form.
if you declare i as a static then it will also keep its value within that sub
and
VB Code:
txt = Input(LOF(FF), #FF)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 2nd, 2006, 08:11 AM
#5
Re: command button click ?
Here is how you would do it. However there is no error handling. You will need to add error handling codes e.g. check for bounds etc
VB Code:
Dim strline() As String '<-- Declare it at form level
' so that you donot need to open again and again
Dim cur As Long
Private Sub Command1_Click()
Dim txt As String
FF = FreeFile
Open App.Path & "\words.txt" For Input As FF
txt = Input(LOF(FF), #FF) 'Read the whole file
Close FF
strline = Split(txt, vbNewLine)
ShowWordMeaning
End Sub
Private Sub Command4_Click()
Unload Form1
End Sub
Private Sub Command5_Click() 'Previous word/menaing
cur = cur - 1
ShowWordMeaning
End Sub
Private Sub Command6_Click() 'Next word/meaning
cur = cur + 1
ShowWordMeaning
End Sub
Private Sub ShowWordMeaning()
'This sub shows word/meaning pair
'Modify as per your needs
Dim strvalues() As String
strvalues = Split((strline(cur)), "|")
Label1.Caption = strvalues(0) 'word
Label2.Caption = strvalues(1) 'meaning
End Sub
Pradeep
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
|